You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a chart that should display on the x axis the number of days of a cycle, and the temperatures that the user filled in, the problem is that the user is not required to add a temperature every day if he doesn't want to, and I have to ignore values that are equal to 0. I looked on stack-overflow and here to properly set x-axis labels, but for some reason my plots are not properly aligned with my labels. I also noticed that in my XAxisFormatter the value returned by the stringForValue is not like I expected meaning [1, 2, 3, 4] but more like [0.5, 0.9, 1.6, 2.4] meaning that I cannot use the value convert it as Int and pull the data from my array.
Any idea what could be the problem below part of the code I wrote
ChartDataSetEntries
private func prepareDataEntries(with data: [DailyData]) -> [ChartDataEntry] {
var dataEntries = [ChartDataEntry]()
for (index, dailyData) in data.enumerated() {
if dailyData.temperature > 0 {
let temperature = String(format:"%.2f", Double(dailyData.temperature)/10)
if let formattedTemp = Double(temperature) {
let chartDataEntry = ChartDataEntry(x: Double(index), y: formattedTemp)
dataEntries.append(chartDataEntry)
if ovulationDetector.hasOvulationForDay(at: index){
ovulation = Highlight(x: chartDataEntry.x, y: chartDataEntry.y, dataSetIndex: 0)
}
}
}
}
return dataEntries
}
private class XAxisValueFormatter: NSObject, IAxisValueFormatter {
private var values: [String]
init(with values: [String]) {
self.values = values
super.init()
}
func stringForValue(_ value: Double, axis: AxisBase?) -> String {
//value cannot be used like values[Int(value)] because I get 0.4 then 0.9 etc... and I will get duplicates since both will be equal to 1
if let index = axis?.entries.index(where: { (current) -> Bool in
return current == value
}) {
return "\(index+1)"
}else {
return "0"
}
}
}
Any idea what could be the issue ?
The text was updated successfully, but these errors were encountered:
Hi to everyone,
I have a chart that should display on the x axis the number of days of a cycle, and the temperatures that the user filled in, the problem is that the user is not required to add a temperature every day if he doesn't want to, and I have to ignore values that are equal to 0. I looked on stack-overflow and here to properly set x-axis labels, but for some reason my plots are not properly aligned with my labels. I also noticed that in my XAxisFormatter the value returned by the stringForValue is not like I expected meaning [1, 2, 3, 4] but more like [0.5, 0.9, 1.6, 2.4] meaning that I cannot use the value convert it as Int and pull the data from my array.
Any idea what could be the problem below part of the code I wrote
ChartDataSetEntries
Setup of the XAxis
XAxisValueFormatter
Any idea what could be the issue ?
The text was updated successfully, but these errors were encountered: