Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chart customAxisMax and customAxisMin doesn't update correctly #864

Closed
DarkInsight opened this issue Mar 21, 2016 · 3 comments
Closed

Chart customAxisMax and customAxisMin doesn't update correctly #864

DarkInsight opened this issue Mar 21, 2016 · 3 comments

Comments

@DarkInsight
Copy link

In my UI, I have a segmented control and a chart. I also have 31 days of data. Based on the selected segment of segmented control, I will respectively show 1 day, 7 days and 1 month of data. The segmented control also starts at "1 day" segment.

When user taps on a new segment, I will filter the original datas:
self.filteredChartDatas = [self.chartDatas filteredArrayUsingPredicate:predicate];

And then I will construct the data sets for the chart again and then determine the customAxisMax and customAxisMin values for the chart
id <IChartDataSet> set = self.vwChart.data.dataSets[0];
CGFloat maximumValue = set.yMax;
CGFloat minimumValue = set.yMin;

ChartYAxis *leftAxis = self.vwChart.leftAxis;
leftAxis.customAxisMax = maximumValue;
leftAxis.customAxisMin = minimumValue;

And then I will redraw the chart
[self.vwChart animateWithXAxisDuration:2.5 easingOption:ChartEasingOptionEaseInOutQuart];

Let's say for 1 day, the maximum value and minimum value are 1254.45 and 1252.25
for 7 days, the maximum value and minimum value are 1269.95 and 1227.40
for 1 month, the maximum value and minimum value are 1280.80 and 1203.45

The issue is: the chart starts out displaying correctly:
simulator screen shot 21 mar 2016 10 57 40 am

However when I taps on 7 days, the new chart still used the previous maximum and minimum value for 1 day:
simulator screen shot 21 mar 2016 10 59 02 am

And when I taps on 1 month, the chart used the previous maximum and minimum value for 7 days:
simulator screen shot 21 mar 2016 10 58 43 am

It seems whenever I recalculate the maximum and minimum values and redraw the chart, the chart doesn't update properly and still use the previous maximum and minimum values.

I also don't want to set a universal maximum and minimum values, as it might make 1 day chart meaningless:
simulator screen shot 21 mar 2016 11 13 40 am

May I know how should I change my implementation?

@danielgindi
Copy link
Collaborator

notifyDataSetChanged()

@DarkInsight
Copy link
Author

Thank you very much, the issue is fixed!

@danielgindi
Copy link
Collaborator

Note that setting data property - calls notifyDataSetChanged(), so if you set other properties before that, it will avoid extra calculations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants