CareKit
CareKit copied to clipboard
bar chart fails to display when only one entry is there in dataSeries
self.chartView.graphView.dataSeries = [
OCKDataSeries(values: [132], title: "Steps", gradientStartColor: ColorUtility.chartBottomColor(), gradientEndColor: ColorUtility.chartTopColor())
]
when we have two entries in values bar seems to work fine. it doesn't show anything when only one entry is there
Thanks for opening an issue!
Are you seeing this bug on the stable
branch or the main
branch?
I believe the reason this is happening is because CareKit is trying to fit the data you provided neatly into the frame. It sets the minimum Y value to the smallest value you've given and the maximum Y value to the largest value you've given.
Since you've only provided one value, it may be doing something unexpected.
A simple fix would be to manually set the minimum Y value to 0, if that's what you expect it to be. Try setting it like this
self.chartView.graphView.dataSeries = [/* data series */]
self.chartView.graphView.yMinimum = 0
Based on your code snippet, it looks like you are setting the data manually instead of using an OCKDataSeriesConfiguration
to dynamically fetch from the store. As long as that's true, modifications you make to the graph view should work as you expect. If you ever switch to using data series configurations, you'll find that your changes to the graph view may get lost each time data in the store changes.
Thanks for replying. I tried setting minimum Y to 0 but no luck. when it has two values in array, that time two bars are shown but not for one data. And just for reference I hardcoded data in dataSeries to make it more understandable. I have dynamic function to get data and binding it to dataSeries. Will check on OCKDataSeriesConfiguration also like you suggested. But chart seems to be having issue when only 1 entry is there. I tried this on this repo as well. I put a hack in my code to add 2nd dummy 0 value when one entry is there. this will work for me because this is edge case. But I would like to know if this gets fixed from your end. I would love to update care kit.
Can you try explicitly settings all four of these values?
// You can make these values whatever you'd like. I'm not sure what the scale of your data is.
self.chartView.graphView.yMinimum = 0
self.chartView.graphView.yMaximum = 100
self.chartView.graphView.xMinimum = 0
self.chartView.graphView.xMaximum = 10
Since you only have one data point, it's probably struggling to guess the right min and max on the X axis as well.
You can also inspect the graphBounds()
property to see what range is being displayed. I suspect it may be showing a range that you don't expect.
We can begin looking into a fix inside of CareKit, but in the meantime, please see if this workaround does the trick.
That one works. thanks for that. yMinimun and xMinimum is fine. but I would like to setup dynamic max value for both yMaximum and xMaximum.
xMaxmim in my case is string (dynamic) like weekdays sometimes and month names sometimes. how to address this?
Will also check on graphBounds