I have a graph that keeps getting dynamically changing data from our server based on player statistics. The problem that I am having is that I am having trouble figuring out how to center the graph based on the data received. I thought I had it configured properly, but upon further testing we found the graph be completely off center. Below is the snippet of code located in my reloadData.
- (void)reloadData
{
CPTXYPlotSpace *plotSpace = (CPTXYPlotSpace *)Chart.defaultPlotSpace;
if (maxY < valueMaxY || minY > valueMinY)
{
// Reload the plot graph
maxY = valueMaxY + (valueMaxY / 2);
// Properly align the Y-Axis
int tickCount = maxY / 5;
if(tickCount <= 1)
{
tickCount = 1;
}
plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(tickCount * -1) length:CPTDecimalFromInt(maxY - (tickCount * -1))];
CPTXYAxisSet *axisSet = (CPTXYAxisSet *)Chart.axisSet;
CPTXYAxis *y = axisSet.yAxis;
y.majorIntervalLength = CPTDecimalFromInt(tickCount);
y.minorTicksPerInterval = 1;
NSArray *exclusionRanges = [NSArray arrayWithObjects:
[CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(-2.0) length:CPTDecimalFromFloat(2.0)],
nil];
y.labelExclusionRanges = exclusionRanges;
}
[Chart reloadData];
}
Brief description is that I would like the chart centered according to the view that sotres it. If possible I would like no more than 5 ticks visible on both the y and x axis. What I am trying to do, from the snippet above is just the y-axis, is to get the data from the server and check if value is greater and less than the previous value. Then I call reloadData and check if the values received are greater than either the min or the max values from the previous message. If either then I readjust the graph and the plots.
Any advice would be greatly appreciated.
I figured it out. I had to get the total distance from my min to my max values then find the center of that. Once I got that I set the y-axis orthogonal point to be the center added to my minimum value.