Range Padding By Percentage


#1

Is there a way for me to set the range padding on a chart by percentage?  I want the high padding to be 20% of the data span and the low padding to be 10% of the data span.  I have tried getting the axis data range, calculating the value and setting that as the padding, but then I have to call reloadData and redrawChart to get the padding to take effect.  I would like to just set the percentages and let the chart take care of the rest.


#2

Hey,

Currently, the only way you can set an axis’ range padding is by specifying a padding size. Like you said, you can calculate the percentage of the data range and set the range padding manually youself, which is what I would recommend. As for getting the change in properties to take effect, you should only need to do [myChart redrawChart] to see the changes in padding take effect (unless you are also changing your data ofcourse!). A chart redraw is extremely quick, infact, the chart redraws multiple times every time you pan or zoom.

I have forwarded your suggestion of being able to set the padding by a percentage to our development team. They will review it and make decision as to whether it will be included in any future releases.

Thanks,
Jan


#3

I have tried setting the padding and calling redrawChart, but it does not redraw with the range padding.


#4

Apologies jmonroe, you need to call [chart reloadData] too!


#5

Jan,

Thanks for the help.  We were attempting to set the padding in sChartDidFinishLoadingData (so that we could get the data range span easily).  We ultimately found refreshDataRange which recalculates the ranges. 

- (void)sChartDidFinishLoadingData:(ShinobiChart *)chart {
    NSNumber * padding = @(chart.yAxis.dataRange.span.doubleValue * 0.05);
    chart.yAxis.rangePaddingHigh = padding;
    chart.yAxis.rangePaddingLow = padding;
    [chart.yAxis refreshDataRange];
}