ShinobiChart: limit axis max range


#1

Hi, 

i have a chart that, for example, has data on xAxis going from 7pm to 8pm.

i want to keep the minimum zoom level fitted to my plot, but i would like to pan my chart to some min/max limits (i.e: if dataRange, as in this case, is 1 hour, i want to pan one hour before the datarange and one hour after the datarange)

i tried to change the defaultRange with  [[SChartData Range alloc]initWithDateMinimum:startWithtOneHourLess andDateMaximum:startWithOneHourMore] , but if i use this, my zoom level is not fitted to my dataRange.

Any help?

Thanks all.


#2

Hi isis,

Rather than setting a new range, have you tried setting your axis’ “allowPanningOutOfDefaultRange” and “allowPanningOutOfMaxRange” properties to YES?

Let me know how you get on.

Kind regards,
Andrew Polkinghorn


#3

Hi Andrew,

yes i did it. But if i set allowPanningOutOfMaxRange, i would pan forever… Instead, i would like to pan to some limits without changing the defaulRange property.

Is this possible? 

Thanks.

Cesare


#4

Hello Isis,

Try setting the default range to pad your dataset by an hour each way and then set your axis range to fit your data snugly. If you this before your initial render, the chart should load with your ranges fitting your data, but the user should be able to pan to their default range.

Thanks,
Jan


#5

Hi Jan,

do you mean something like this?

        NSTimeInterval secondsBetween = [self.endDate timeIntervalSinceDate:self.startDate];
        NSDate *start = [[NSDate alloc]initWithTimeInterval:-secondsBetween sinceDate:self.startDate];
        NSDate *end = [[NSDate alloc]initWithTimeInterval:secondsBetween sinceDate:self.endDate];
        xAxis.defaultRange = [[SChartDateRange alloc]initWithDateMinimum:start andDateMaximum:end];
 
        [xAxis setRangeWithMinimum:self.startDate andMaximum:self.endDate withAnimation:YES];
 
Thanks,
Cesare

#6

Yeah - that looks fine to me. You’re setting your default range to span your whole pannable area, and then setting the range of your axis to span your data set.  :laughing:

Jan


#7

Mmm… i did it but this is what i log for xAxis:

SChartDateTimeAxis at 0x135640560, axisRange = { 1969-12-31 23:59:59 +0000, 1970-01-01 00:00:01 +0000 }, defaultRange = { 2015-01-28 04:57:43 +0000, 2015-01-28 15:58:37 +0000 }, maxRange = { 1970-01-01 00:00:00 +0000, 1970-01-01 00:00:01 +0000 }
 
The default range is correct but the axisRange isn't.
Do you have any suggestion?
 
Thanks,
Cesare.

#8

Hi Isis,

When you say the range isn’t correct, do you mean the visible range, or the range show in the log? As the range in the logs will be different to the visible range, since we perform transformations on the data internally, which is what you’re seeing there.

Best regards,

Rob


#9

Hi,

i’m not able to solve this problem. In the code posted above seems that the axis range is not correct.

My defaultRange is correct. I can see all series in my whole pannable area but i don’t know how i can fit the chart to my plot area.

Probably this line of code is not doing what i except:

[xAxis setRangeWithMinimum:self.startDate andMaximum:self.endDate withAnimation:YES];

Thanks all.


#10

Hi Isis,

If you set your default range as you have done, but then use the chart’s delegate method as below:

- (void)sChartRenderFinished:(ShinobiChart *)chart {
    
    if (firstRender) {
        [chart.xAxis setRangeWithMinimum:self.startDate andMaximum:self.endDate];
        [chart redrawChart];
        
        firstRender = NO;
    }
    
}

Obviously you’ll need to declare a BOOL instance variable and set the chart’s delegate that ensures we only redraw the axis once.

I hope that’s of some help!

Sam