Reputation: 45
I have a CPTXYGraph with a CPTScatterPlot, which I update with new data using [graph reloadData]. I also set the ranges based on the data. My problem is that though the axes update fine when the range changes, the gridlines do not, so I end up with this http://inky.ws/g/hw (no grid lines at the end of the x-axis).
I set axis.gridLinesRange = nil, and I tried re-setting all the gridline properties when updating ranges, to no avail.
To clarify, the original plot looks fine, but when I update with a bigger data set, the grid lines are missing in the added range.
Upvotes: 1
Views: 1120
Reputation: 56
I've had the same issue and used the following workaround: calculate new bounds of your values and replace the default plot space range with a new one using the plotRangeWithLocation:length: convenience method.
Not very satisfying performance-wise and conceptually (feels a bit like doing the job of the framework) but it worked for me.
CPTXYPlotSpace *plotSpace = (CPTXYPlotSpace *)graph.defaultPlotSpace;
plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat([valuesMin floatValue]) length:CPTDecimalFromFloat([valuesMax floatValue]-[valuesMin floatValue])];
CPTXYAxisSet *axisSet = (CPTXYAxisSet *)graph.axisSet;
CPTXYAxis *y = axisSet.yAxis;
float amplitude = ([valuesMax floatValue]-[valuesMin floatValue]);
NSDecimal intervalLength = CPTDecimalFromFloat(100);
y.majorIntervalLength = intervalLength;
Upvotes: 3