Reputation: 1
I am new to objective-c and xcode. It would be very thankful if someone can point how to set new plot data for bar chart using core-plot. I need to set data like : y-axis and x-axis : as (10,1), (5,2), (20,3), (15,4) and the output should come as :
--------------------- 30 25 20 # 15 # # 10 # # # 5 # # # # 1 2 3 4 ---------------------
It would be great if someone can provide me the .m and .h file Thanks in advance
Joshua
Upvotes: 0
Views: 820
Reputation: 355
The function numberForPlot is where you define your datas you want to plot:
-(NSNumber *)numberForPlot:(CPPlot *)plot field:(NSUInteger)fieldEnum recordIndex:(NSUInteger)index
{
NSNumber *num = nil;
if ( [plot isKindOfClass:[CPBarPlot class]] ) {
switch ( fieldEnum ) {
case CPBarPlotFieldBarLocation:
num = (NSNumber *)[NSNumber numberWithFloat:[[*yourArray* objectAtIndex:index] floatValue]];
break;
case CPBarPlotFieldBarLength:
num = (NSNumber *)[NSNumber numberWithFloat:[[*yourOtherArray* objectAtIndex:index] floatValue]];
break;
}
}
return num;
}
You just have to insert datas in your arrays.
Upvotes: 0
Reputation: 27381
Look at the programs in the examples folder in your Core Plot directory. All three CPTestApp programs (Mac, iPhone, and iPad) have bar plots.
Upvotes: 1