Difference on core plot CPTBarPlotFieldBarLocation and CPTBarPlotFieldBarTip?
I'm new to core plot and wondering what the difference is on CPTBarPlotFieldBarLocation
and CPTBarPlotFieldBarTip
. I have been looking at the core plot example CPTTestApp_ipadViewController
and I have seen that both of these field enum are called during filling the ploy with the numberForPlot
-method but I don't understand the difference.
Thanks for any help
The difference is very huge. If we look at definition of type CPTBarPlotField
in CPTBarPlot
we will see that there are three values in that enum:
CPTBarPlotFieldBarLocation
: Bar location on independent coordinate axis.CPTBarPlotFieldBarTip
: Bar tip value.CPTBarPlotFieldBarBase
: Bar base (used only if barBasesVary is YES).
You can ask - where can I use that values? Ok, you should use this constants in method -(NSNumber *)numberForPlot:(CPTPlot *)plot field:(NSUInteger)fieldEnum recordIndex:(NSUInteger)index
. In that method you should return values of that properties for each individual bar. For example,
-(NSNumber *)numberForPlot:(CPTPlot *)plot field:(NSUInteger)fieldEnum recordIndex:(NSUInteger)index
{
int plotIndex = [(NSNumber *)plot.identifier intValue];
return [[[datas objectAtIndex:plotIndex] objectAtIndex:index] valueForKey:(fieldEnum == CPTBarPlotFieldBarLocation ? @"x" : @"y")];
}
In my example I have dictionary which contains values for x axis (locations of bars) and y (values of bars).
I want to mention, that you should not set property plotRange
of your CPTBarPlot *plot
or CorePlot
will set locations of your bars automatically (at position 0,1,2,3,4....).
精彩评论