Dynamic date range (iOS)


#1

I’ve been struggling to understand the range types in both bar and line charts. My bar chart has a y Axis of date type, and my line chart has a x Axis of date type.

On creating the charts, on both of them I’m setting an initial range that will allow the chart to initially display 7 days, if there is more than 7 days to be shown (and the other data will be visible by panning/zooming):

yRange = [[SChartDateRange alloc] initWithDateMinimum:firstDayToShow andDateMaximum:self.allDaysSorted[6]];
self.chart.yAxis = [[SChartDateTimeAxis alloc] initWithRange:yRange];

or, in case there is less than 7 days to be shown, I create the axis without setting a range, so that way all my data will be displayed

self.chart.yAxis = [SChartDateTimeAxis new];
self.chart.yAxis.rangePaddingHigh = [SChartDateFrequency dateFrequencyWithDay:1];
self.chart.yAxis.rangePaddingLow = [SChartDateFrequency dateFrequencyWithDay:1];

This way my data always fit well on the chart.

My problem is when I reload my data and redraw the bar chart. Sometimes, I need to reload from a 15-date chart to a 4-date chart, for example. When I do that, I still have the same range, and when I redraw the chart, it seems that there is nothing there, but it is because the data is outside the visible initial range. I’m trying to re-set the range before redrawing it, but I’m confused on how to do that.

Oddly enough, the line chart seems to adjust itself just fine.

Could I get some help on that? Thanks!


#2

Hi Tati,

Have you tried setting the “defaultRange” property on your axis?

As when you initialise an axis with a range, it sets that range as its defaultRange.

The “defaultRange” property is what range the axis will fall back to when the chart redraws.

Let me know if you have any questions.

Kind regards,
Andrew Polkinghorn.