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'm using the technique described here: #1496 to provide custom xAxis data.
In my case, I'm showing a fixed "weekly" view so always want the axis values to be the last seven days, e.g. ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'] but I don't always have data for every day.
Previously this worked ok, since the xAxis and ChartDataEntrys were divorced, but I'm having trouble doing this now.
One technique which comes close is to add ChartDataEntry's with a nan y value, like this contrived example:
varxAxisValues:[String]=["Mon","Tue","Wed","Thu","Fri","Sat","Sun"]func stringForValue(_ value:Double, axis:AxisBase?)->String{leti=Int(value)returnxAxisValues[i]}func fillChart(data:[Double?]){
//data is a length-7 array, entry 0 is Monday, 1 Tuesday, etc. nils mean no data for that day
varvalues=[ChartDataEntry]()
for (x, y) in data.enumerated(){
if let y = y {
values.append(ChartDataEntry(x:Double(i), y: y))}else{
// set y to nan
values.append(ChartDataEntry(x:Double(i), y:Double.nan))}}letdataSet=LineChartDataSet(values: values, label:"Data")
//... etc
}
This appears to work ok, but gives a lot of runtime errors in CoreGraphics, because the nan values aren't filtered out in, for example, LineChartRenderer.drawHorizontalBezier(context:dataSet).
So, my question is, is this a viable route to go down, in which case the nan values need to be filtered somewhere (e.g. in ChartDataSet.entryForIndex()), or is there a better way?
If you think using nan like this is the correct approach, I can help with the code updates to remove the CoreGraphics runtime warnings, but didn't want to go down that route if there's a better way.
I feel like chasing down the corner cases with nan values might be a rabbit-hole though. I think at a minimum, all the functions in ChartDataSet that reference _values would need to change in some way.
I can probably set up an example project to demonstrate what I'm doing if that'll help.
The text was updated successfully, but these errors were encountered:
I'm using the technique described here: #1496 to provide custom xAxis data.
In my case, I'm showing a fixed "weekly" view so always want the axis values to be the last seven days, e.g.
['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
but I don't always have data for every day.Previously this worked ok, since the xAxis and ChartDataEntrys were divorced, but I'm having trouble doing this now.
One technique which comes close is to add ChartDataEntry's with a
nan
y value, like this contrived example:This appears to work ok, but gives a lot of runtime errors in CoreGraphics, because the nan values aren't filtered out in, for example,
LineChartRenderer.drawHorizontalBezier(context:dataSet)
.So, my question is, is this a viable route to go down, in which case the
nan
values need to be filtered somewhere (e.g. inChartDataSet.entryForIndex()
), or is there a better way?If you think using
nan
like this is the correct approach, I can help with the code updates to remove the CoreGraphics runtime warnings, but didn't want to go down that route if there's a better way.I feel like chasing down the corner cases with
nan
values might be a rabbit-hole though. I think at a minimum, all the functions inChartDataSet
that reference_values
would need to change in some way.I can probably set up an example project to demonstrate what I'm doing if that'll help.
The text was updated successfully, but these errors were encountered: