问题
I am using Core-Plot library to draw bar chart in iPhone. I am using CPTTestApp-iPhone
to my training. In my project the bar appear very good thats looks like from the sample project. But, i dont where i need to give the values to draw the bars. Then, in my actual project i need to change the bar values dynamically. How can i do this? Please help me to find out the solution. Thanks in advance. Below the sample datasource code,
#pragma mark -
#pragma mark Plot Data Source Methods
-(NSUInteger)numberOfRecordsForPlot:(CPTPlot *)plot
{
return 10;
}
-(NSNumber *)numberForPlot:(CPTPlot *)plot field:(NSUInteger)fieldEnum recordIndex:(NSUInteger)index
{
NSDecimalNumber *num = nil;
if ( [plot isKindOfClass:[CPTBarPlot class]] )
{
switch ( fieldEnum )
{
case CPTBarPlotFieldBarLocation:
num = (NSDecimalNumber *)[NSDecimalNumber numberWithUnsignedInteger:index];
break;
case CPTBarPlotFieldBarTip:
num = (NSDecimalNumber *)[NSDecimalNumber numberWithUnsignedInteger:(index+1)*(index+1)];
if ( [plot.identifier isEqual:@"Bar Plot 2"] )
num = [num decimalNumberBySubtracting:[NSDecimalNumber decimalNumberWithString:@"10"]];//10
break;
}
}
return num;
}
-(CPTFill *) barFillForBarPlot:(CPTBarPlot *)barPlot recordIndex:(NSNumber *)index;
{
return nil;
}
How to increment the bar length in coreplot iPhone? Thanks.
回答1:
A Core Plot plot will request its data from the datasource when it is first displayed. You can force it to load new data in several ways:
- Call
-reloadData
on the graph to reload all plots. - Call
-reloadData
on the plot to reload all of the data for only that plot. - Call
-reloadDataInIndexRange:
on the plot to reload a range of data indices without changing the total number of data points. - Call
-insertDataAtIndex:numberOfRecords:
to insert new data at the given index. Any data at higher indices will be moved to make room. Only the new data will be requested from the datasource.
You can also remove data from the plot without reloading anything by using the -deleteDataInIndexRange:
method.
As the name implies, the -numberOfRecordsForPlot:
method tells the plot how many data points will be plotted. The -numberForPlot:field:recordIndex:
method will be called to load the actual data values. It gets called for each combination of field (location and tip) and data index.
来源:https://stackoverflow.com/questions/8633519/how-can-i-change-the-values-to-barchart-dynamically-in-core-plot-iphone