How can i change the values to BarChart dynamically in Core-Plot iphone?

社会主义新天地 提交于 2019-12-13 12:42:02

问题


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:

  1. Call -reloadData on the graph to reload all plots.
  2. Call -reloadData on the plot to reload all of the data for only that plot.
  3. Call -reloadDataInIndexRange: on the plot to reload a range of data indices without changing the total number of data points.
  4. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!