2

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

Nekto
  • 17,837
  • 1
  • 55
  • 65
user851369
  • 21
  • 3

1 Answers1

4

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:

  1. CPTBarPlotFieldBarLocation : Bar location on independent coordinate axis.
  2. CPTBarPlotFieldBarTip : Bar tip value.
  3. 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....).

Nekto
  • 17,837
  • 1
  • 55
  • 65