bmr calculator: use values from one class/scrren - kivy

I'm trying to use values from one class/scrren to multiply with another class screen but keep getting 0.
I know i probably do not carry the variable properly from one class to another but seem to have tried almost everything so if I dont get nontype error I just get 0 value when multiplying anything, like I would carry 0 from my second screen in the values which i have to input in the second screen. Any ideas? as Im brand new on kivy
.py
class SecondWindow(Screen):
ageInput = NumericProperty()
weightInput = NumericProperty()
heightInput = NumericProperty()
def info(self):
age = self.ids.ageInput.text
ageVal = int(age)
height = self.ids.heightInput.text
heightVal = int(height)
weight = self.ids.weightInput.text
weightVal = int(weight)
add = int(age) + int(height) - int(weight)
self.ids.label.text = str(add)
addVal = self.ids.label.text
print (addVal)
return ageVal, heightVal, weightVal
class ThirdWindow(Screen):
male = ObjectProperty()
female = ObjectProperty()
second = ObjectProperty()
def bmrCalc(self, button, weight):
choice = self.ids.lbl.text
if choice == "":
self.ids.lbl.text = button
self.weight = self.second.weightInput
if self.ids.lbl.text == "male":
m = 66.5
mw = 13.75 * int(self.second.weightInput)
mh = 5.003 * int(self.second.heightInput)
ma = 6.75 * int(self.second.ageInput)
print(mw)
.kv file
<SecondWindow>:
id: second
name: "second"
age: ageInput
hheight: heightInput
weight: weightInput
lbl1: label
FloatLayout:
canvas.before:
Color:
rgba: 255, 0, 0, 1
Rectangle:
# self here refers to the widget i.e FloatLay
pos: self.pos
size: self.size
Label:
text: "Calorie Intake Calculator"
font_size: 35
pos_hint: {"x": 0.3, "top": 1}
size_hint: 0.35, 0.1
Label:
text: "Enter your age"
font_size: 30
pos_hint: {"x": 0.1, "y": 0.8}
size_hint: 0.3, 0.1
TextInput:
id: ageInput
font_size: 15
multiline: False
pos_hint: {"x": 0.5 , "y":0.82}
size_hint:0.3, 0.05
Label:
text: "Enter your height(cm)"
font_size: 30
pos_hint: {"x": 0.1, "y": 0.6}
size_hint: 0.3, 0.1
TextInput:
id: heightInput
font_size: 15
multiline: False
pos_hint: {"x": 0.5 , "y":0.62}
size_hint:0.3, 0.05
Label:
text: "Enter your weight(kg)"
font_size: 30
pos_hint: {"x": 0.1, "y": 0.4}
size_hint: 0.3, 0.1
TextInput:
id: weightInput
font_size: 15
multiline: False
pos_hint: {"x": 0.5 , "y":0.42}
size_hint:0.3, 0.05
Button:
pos_hint: {"x":0.35, "y": 0.3}
size_hint: 0.3, 0.05
text: "Submit"
on_press:
root.info()
app.root.current = "third"
root.manager.transition.direction = "left"
Label:
id: label
text: "text"
font_size: 15
pos_hint: {"x": 0.7, "y": 0.1}
size_hint: 0.3, 0.2
Button:
pos_hint: {"x":0.35, "y": 0.15}
size_hint: 0.3, 0.05
text: "Back"
on_release:
app.root.current = "first"
root.manager.transition.direction = "right"
<ThirdWindow>:
id: third
name: "third"
lbl: lbl
male: male
female: female
FloatLayout:
canvas.before:
Color:
rgba: 153, 0, 0, 1
Rectangle:
# self here refers to the widget i.e FloatLayout
pos: self.pos
size: self.size
Label:
text: "Calorie Intake Calculator"
font_size: 35
pos_hint: {"x": 0.3, "top": 1}
size_hint: 0.35, 0.1
Label:
text: "Choose Your gender"
font_size: 30
pos_hint: {"x": 0.32, "top": 0.85}
size_hint: 0.35, 0.1
Button:
id: male
pos_hint: {"x":0.35, "y": 0.6}
size_hint: 0.3, 0.1
text: "Male"
on_press:
root.bmrCalc("male", "weight")
Button:
id: female
pos_hint: {"x":0.35, "y": 0.5}
size_hint: 0.3, 0.1
text: "Female"
on_press:
root.bmrCalc("female")
Label:
id: lbl
text: ""
font_size: 15
pos_hint: {"x": 0.35, "top": 0.3}
size_hint: 0.35, 0.1
Button:
pos_hint: {"x":0.35, "y": 0.1}
size_hint: 0.3, 0.05
text: "Back"
on_press:
app.root.current = "second"
root.manager.transition.direction = "right"

Related

MDBoxLayout -> Widget width and height doesn't work ! kivy/kivymd

MDBoxLayout:
orientation: "vertical"
Widget:
size_hint_y: 5
height: 100
width: 100
canvas:
Color:
rgb: 1, 1, 1
Ellipse:
size: self.width / 3 , self.width / 3
pos: ( self.width - ( self.width / 3 ) ) / 2 , self.height - 100
source: 'cat-1.jpg'
angle_start: 0
angle_end: 360
ScrollView:
MDList:
id: scroll
OneLineAvatarIconListItem:
id: profile
text: "Profile"
elevation: 10
IconLeftWidget:
icon: "account-card-details-outline"

SwiftUI Chart: how can I overlay multiple graph datas?

here are two charts.
and I would like to show the data of object and object2 together in one chart.
Would it be possible?
Chart(db.objects, id: \.self) { object in
LineMark(
x: .value("name", object.name),
y: .value("value", Int(object.value) ?? 0)
)
}
Chart(db.objects2, id: \.self) { object2 in
LineMark(
x: .value("name", object2.name),
y: .value("value", Int(object2.value) ?? 0)
)
}
I just found the way from apple developer website
https://developer.apple.com/documentation/charts/chart/
struct ProfitOverTime {
var date: Date
var profit: Double
}
let departmentAProfit: [ProfitOverTime] = [] // ...
let departmentBProfit: [ProfitOverTime] = [] // ...
var body: some View {
Chart {
ForEach(departmentAProfit) {
LineMark(
x: .value("Date", $0.date),
y: .value("Profit A", $0.profit)
)
.foregroundStyle(.blue)
}
ForEach(departmentBProfit) {
LineMark(
x: .value("Date", $0.date),
y: .value("Profit B", $0.profit)
)
.foregroundStyle(.green)
}
RuleMark(
y: .value("Threshold", 500.0)
)
.foregroundStyle(.red)
}
}
This is an alternative solution. Since the data structure is the same, the data could be one source and displayed using one LineMark.
As an example, dept was added to the model to identify each group of data that represents a single line in the chart:
struct ProfitOverTime {
var dept: String
var date: Date
var profit: Double
}
The data combined into one array:
let data: [ProfitOverTime] = [] // ...
The foreground style is based on the department, that is, each line in the chart.
struct DepartmentChart: View {
var body: some View {
Chart(data) {
LineMark(
x: .value("Date", $0.date),
y: .value("Profit", $0.profit)
series: .value("Department", $0.dept)
)
.foregroundStyle(by: .value("Department", $0.dept))
RuleMark(
y: .value("Threshold", 500.0)
)
.foregroundStyle(.red)
}
.chartForegroundStyleScale(["Profit A": .green, "Profit B": .blue])
}
}
Series was added to identify each line by its color:
The chartForegroundStyleScale is optional since each line will automatically be colored differently. But chartForegroundStyleScale can be used to customize the line colors.
Here I am showing the data for a week. So if you want to show more than data then you can increase the number of entries. So that’s it from my side hope you understand.
Now use MultiLineChartView like this.
Complete Code:
import SwiftUI
import Charts
struct ContentView: View {
let days = ["S", "M", "T", "W", "T", "F", "S"]
let entries1 = [
ChartDataEntry(x: 1, y: 1),
ChartDataEntry(x: 2, y: 2),
ChartDataEntry(x: 3, y: 0),
ChartDataEntry(x: 4, y: 0),
ChartDataEntry(x: 5, y: 0),
ChartDataEntry(x: 6, y: 0),
ChartDataEntry(x: 7, y: 1),
]
let entries2 = [
ChartDataEntry(x: 1, y: 2),
ChartDataEntry(x: 2, y: 3),
ChartDataEntry(x: 3, y: 0),
ChartDataEntry(x: 4, y: 0),
ChartDataEntry(x: 5, y: 0),
ChartDataEntry(x: 6, y: 0),
ChartDataEntry(x: 7, y: 2)
]
var body: some View {
VStack{
Spacer()
MultiLineChartView(entries1: entries1, entries2: entries2, days: days)
.frame(height: 220)
Spacer()
}
}
}
struct MultiLineChartView : UIViewRepresentable {
var entries1 : [ChartDataEntry]
var entries2 : [ChartDataEntry]
var days: [String]
func makeUIView(context: Context) -> LineChartView {
let chart = LineChartView()
return createChart(chart: chart)
}
func updateUIView(_ uiView: LineChartView, context: Context) {
uiView.data = addData()
}
func createChart(chart: LineChartView) -> LineChartView{
chart.chartDescription?.enabled = false
chart.xAxis.drawGridLinesEnabled = false
chart.xAxis.drawLabelsEnabled = true
chart.xAxis.drawAxisLineEnabled = false
chart.xAxis.labelPosition = .bottom
chart.rightAxis.enabled = false
chart.leftAxis.enabled = false
chart.drawBordersEnabled = false
chart.legend.form = .none
chart.xAxis.labelCount = 7
chart.xAxis.forceLabelsEnabled = true
chart.xAxis.granularityEnabled = true
chart.xAxis.granularity = 1
chart.xAxis.valueFormatter = CustomChartFormatter(days: days)
chart.data = addData()
return chart
}
func addData() -> LineChartData{
let data = LineChartData(dataSets: [
//Schedule Trips Line
generateLineChartDataSet(dataSetEntries: entries1, color: UIColor(Color(#colorLiteral(red: 0.6235294118, green: 0.7333333333, blue: 0.3568627451, alpha: 1))), fillColor: UIColor(Color(#colorLiteral(red: 0, green: 0.8134518862, blue: 0.9959517121, alpha: 1)))),
//Unloadings Line
generateLineChartDataSet(dataSetEntries: entries2, color: UIColor(Color(#colorLiteral(red: 0.003921568627, green: 0.231372549, blue: 0.431372549, alpha: 1))), fillColor: UIColor(Color(#colorLiteral(red: 0.4745098054, green: 0.8392156959, blue: 0.9764705896, alpha: 1))))
])
return data
}
func generateLineChartDataSet(dataSetEntries: [ChartDataEntry], color: UIColor, fillColor: UIColor) -> LineChartDataSet{
let dataSet = LineChartDataSet(entries: dataSetEntries, label: "")
dataSet.colors = [color]
dataSet.mode = .cubicBezier
dataSet.circleRadius = 5
dataSet.circleHoleColor = UIColor(Color(#colorLiteral(red: 0.003921568627, green: 0.231372549, blue: 0.431372549, alpha: 1)))
dataSet.fill = Fill.fillWithColor(fillColor)
dataSet.drawFilledEnabled = true
dataSet.setCircleColor(UIColor.clear)
dataSet.lineWidth = 2
dataSet.valueTextColor = color
dataSet.valueFont = UIFont(name: "Avenir", size: 12)!
return dataSet
}
}
class CustomChartFormatter: NSObject, IAxisValueFormatter {
var days: [String]
init(days: [String]) {
self.days = days
}
public func stringForValue(_ value: Double, axis: AxisBase?) -> String {
return days[Int(value-1)]
}
}

Highcharts gauge not showing colour as expected

I have 3 stops at 0.4, 0.6 and 0.8 (red, green, blue). The maximum is 100 (for percent)
If I set the data as 50, I expect it to be green but it seems to be a mix of the green and red. It's only when I get to 60 that it's bright green that I expect.
Anyway to remove the gradient?
https://jsfiddle.net/sy3r2hj7/1/
var gaugeOptions = {
chart: {
type: 'solidgauge'
},
title: null,
pane: {
center: ['50%', '85%'],
size: '140%',
startAngle: -90,
endAngle: 90,
background: {
backgroundColor: (Highcharts.theme && Highcharts.theme.background2) || '#EEE',
innerRadius: '60%',
outerRadius: '100%',
shape: 'arc'
}
},
tooltip: {
enabled: false
},
// the value axis
yAxis: {
stops: [
[0.40, '#ff0000'],
[0.60, '#00ff00'], // yellow
[0.80, '#0000ff'] // red
],
lineWidth: 0,
minorTickInterval: null,
tickAmount: 2,
title: {
y: -70
},
labels: {
y: 16
}
},
plotOptions: {
solidgauge: {
dataLabels: {
y: 5,
borderWidth: 0,
useHTML: true
}
}
}
};
// The speed gauge
var chartSpeed = Highcharts.chart('container-speed', Highcharts.merge(gaugeOptions, {
yAxis: {
min: 0,
max: 100,
title: {
text: 'Speed'
}
},
credits: {
enabled: false
},
series: [{
name: 'Speed',
data: [60],
dataLabels: {
format: '<div style="text-align:center"><span style="font-size:25px;color:' +
((Highcharts.theme && Highcharts.theme.contrastTextColor) || 'black') + '">{y}</span><br/>' +
'<span style="font-size:12px;color:silver">km/h</span></div>'
},
tooltip: {
valueSuffix: ' km/h'
}
}]
}));
Instead of using stops property, you can change the color of the point programmatically, based on some condition:
events: {
render: function() {
var point = this.series[0].points[0];
if (point.y < 40) {
point.graphic.attr({
fill: '#ff0000'
})
} else if (point.y < 60) {
point.graphic.attr({
fill: '#00ff00'
})
} else {
point.graphic.attr({
fill: '#0000ff'
})
}
}
}
Live demo: https://jsfiddle.net/BlackLabel/fw594Lmg/

Values are not showing on chart graph swift

I am using chart library to plot graph in swift. I want to show below values on LineChartView.
My values are as follows.
1) x: 0.0 y: 0.62020133693747
2) x: 0.0 y: 0.62020133693747
3) x: 0.0 y: 0.62020133693747
4) x: 8500.0 y: 0.62020133693747
5) x: 8500.0 y: 0.925703706122449
6) x: 9000.0 y: 0.925703706122449
7) x: 9000.0 y: 1.43307403327373
8) x: 9500.0 y: 1.43307403327373
9) x: 9500.0 y: 0.37799568
10) x: 9500.0 y: 0.37799568
11) x: 9500.0 y: 0.37799568
12) x: 9000.0 y: 0.37799568
13) x: 9000.0 y: 0.269996914285714
14) x: 8500.0 y: 0.269996914285714
15) x: 8500.0 y: 0.239997257142857
16) x: 6000.0 y: 0.239997257142857
17) x: 6000.0 y: 0.219552079597251
18) x: 0.0 y: 0.219552079597251
19) x: 0.0 y: 0.453594816
20) x: 0.0 y: 0.453594816
From these values the expected graph is:
But when I am using chart library I am getting the following graph:
It seems that the library is not able to plot the last values.
I have tried various setting but it didn't solve my issue.
My Code:
`func updateChartValues(arrLineCDE: Array<ChartDataEntry>) -> (LineChartDataSet) {
let Xvalues: [Double] = [/*All My X values are here*/]
let Yvalues: [Double] = [/*All My Y values are here*/]
var entries: [ChartDataEntry] = Array()
for (i, x) in Xvalues.enumerated() {
entries.append(ChartDataEntry(x: Xvalues[i], y: Yvalues[i], data: UIImage(named: "icon", in: Bundle(for: self.classForCoder), compatibleWith: nil)))
}
self.dataSet = LineChartDataSet(values: entries, label: "Depth vs. FV")
self.dataSet.mode = LineChartDataSet.Mode.cubicBezier
return dataSet
}`
Line Chart Sttings
`func setLineChartProperty(lineChartView lcv: LineChartView) {
//Line Chart Setting:
// lcv.delegate = self
lcv.setViewPortOffsets(left: 44.0, top: 30.0, right: 44.0, bottom: 44.0)
lcv.backgroundColor = darkBlueColor
lcv.chartDescription?.enabled = false
lcv.dragEnabled = false
lcv.setScaleEnabled(false)
lcv.pinchZoomEnabled = false
lcv.drawGridBackgroundEnabled = false
lcv.xAxis.labelFont = UIFont(name: "HelveticaNeue-Light", size: CGFloat(12.0))!
lcv.xAxis.setLabelCount(6, force: false)
lcv.xAxis.labelTextColor = UIColor.white
lcv.xAxis.labelPosition = .bottom
lcv.xAxis.axisLineColor = UIColor.white
lcv.xAxis.gridColor = UIColor.white
lcv.xAxis.drawGridLinesEnabled = true
lcv.xAxis.axisMaximum = 10000
lcv.xAxis.axisMinimum = 0
lcv.leftAxis.labelFont = UIFont(name: "HelveticaNeue-Light", size: CGFloat(12.0))!
lcv.leftAxis.setLabelCount(6, force: false)
lcv.leftAxis.labelTextColor = UIColor.white
lcv.leftAxis.labelPosition = .outsideChart
lcv.leftAxis.axisLineColor = UIColor.white
lcv.leftAxis.gridColor = UIColor.white
lcv.leftAxis.drawGridLinesEnabled = true
lcv.legend.horizontalAlignment = .right
lcv.legend.verticalAlignment = .bottom
lcv.legend.orientation = .horizontal
lcv.legend.drawInside = true
lcv.legend.form = .square
lcv.legend.formSize = 8.0
lcv.legend.formToTextSpace = 4.0
lcv.legend.xEntrySpace = 6.0
lcv.xAxis.enabled = true
lcv.rightAxis.enabled = false
lcv.leftAxis.enabled = true
lcv.legend.enabled = true
lcv.legend.textColor = UIColor.white
lcv.animate(xAxisDuration: 1.0, yAxisDuration: 1.0)
}`

Use gradient color in Highchart solidgauge

$(function () {
var gaugeOptions = {
chart: {
type: 'solidgauge'
},
title: null,
pane: {
center: ['50%', '85%'],
size: '140%',
startAngle: -90,
endAngle: 90,
background: {
backgroundColor: (Highcharts.theme && Highcharts.theme.background2) || '#EEE',
innerRadius: '60%',
outerRadius: '100%',
shape: 'arc'
}
},
tooltip: {
enabled: false
},
// the value axis
yAxis: {
lineWidth: 0,
minorTickInterval: null,
tickPixelInterval: 400,
tickWidth: 0,
title: {
y: -70
},
labels: {
y: 16
}
},
plotOptions: {
solidgauge: {
dataLabels: {
y: 5,
borderWidth: 0,
useHTML: true
}
}
}
};
// The speed gauge
$('#container-speed').highcharts(Highcharts.merge(gaugeOptions, {
yAxis: {
min: 0,
max: 100,
title: {
text: 'Speed'
}
},
series: [{
name: 'Speed',
data: [75]
}]
}));
});
Using the Highchart's solidgauge. Is there a way to have a gradient color up to the value showing on the gauge?
For example if my gauge is from 0 to 100, and at a specific time the value we are showing is 75, I want to show it as a gradient color transitioning from a green left section to small red right section. Of course the remaining 25% of the gauge in this example should not have any color just showing the background color of the gauge.
Is there a way to do that?

Resources