如何在Core-Plot iphone中动态更改BarChart的值? [英] How can i change the values to BarChart dynamically in Core-Plot iphone?

查看:158
本文介绍了如何在Core-Plot iphone中动态更改BarChart的值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Core-Plot库在iPhone中绘制条形图。我正在使用 CPTTestApp-iPhone 进行培训。在我的项目中,酒吧看起来非常好,看起来像样品项目。但是,我不需要给出值来绘制酒吧。然后,在我的实际项目中,我需要动态地改变条形值。我该怎么办?请帮我找出解决方案。提前致谢。下面的示例数据源代码

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;
}

如何在coreplot iPhone中增加条长度?谢谢。

How to increment the bar length in coreplot iPhone? Thanks.

推荐答案

核心绘图将在首次显示时从数据源请求其数据。您可以强制以多种方式加载新数据:

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. 调用 -reloadData 在图表上重新加载所有的图。

  2. 在图上调用 -reloadData ,以重新加载所有图形的所有数据。 / li>
  3. 在图上调用 -reloadDataInIndexRange:,以重新加载一系列数据索引,而不更改数据点的总数。

  4. 调用 -insertDataAtIndex:numberOfRecords:在给定的索引中插入新数据。更高指数的任何数据将被移动以腾出空间。

  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.

您还可以从图形中删除数据,而无需使用 -deleteDataInIndexRange:方法。

You can also remove data from the plot without reloading anything by using the -deleteDataInIndexRange: method.

顾名思义, -numberOfRecordsForPlot:方法告诉绘图将绘制多少数据点。将调用 -numberForPlot:field:recordIndex:方法来加载实际的数据值。它被称为字段(位置和提示)和数据索引的每个组合。

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.

这篇关于如何在Core-Plot iphone中动态更改BarChart的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆