【问题标题】:how to integrate slider control in bar chart application in ios如何在 ios 的条形图应用程序中集成滑块控件
【发布时间】:2012-11-12 07:07:27
【问题描述】:

嗨朋友们,我正在使用核心绘图标题创建条形图应用程序,我希望条形图使用滑块控件更改其值。所以我创建了滑块。滑块值已更改,但我的条形图未更改。我不知道如何在条形图中整合滑块值。如果有人知道请分享我。我对此更新鲜。我的代码如下所示: 我的滑块代码:

-(void)updateSliderValueTo:(CGFloat)_value {

[sliderValue setText:[NSString stringWithFormat:@"%f", _value]];  }

我的条形图代码是:

 - (id)init
{

self = [super init];

if(sliderValue == 0)
{

if (self) 
{
     //NSLog(@"sliderval :%d", sliderValue);
    // Setting up sample data here.
    sampleData = [[NSArray alloc] initWithObjects:[NSNumber numberWithInt:0],
                                                  [NSNumber numberWithInt:500], 
                                                  [NSNumber numberWithInt:1500], 
                                                  [NSNumber numberWithInt:2500], 
                                                  [NSNumber numberWithInt:3500], 
                                                  [NSNumber numberWithInt:4500], 
                                                  [NSNumber numberWithInt:5500],
                                                  [NSNumber numberWithInt:6500],
                                                  nil];

    sampleProduct = [[NSArray alloc] initWithObjects:@"", @"A", @"B", @"C", @"D", @"E",@"F",@"G",nil];

    // Initialize the currency formatter to support negative with the default currency style.
    currencyFormatter = [[NSNumberFormatter alloc] init];
    [currencyFormatter setNumberStyle:NSNumberFormatterCurrencyStyle];
    [currencyFormatter setNegativePrefix:@"-"];
    [currencyFormatter setNegativeSuffix:@""];
}
}

else if(sliderValue != 0)
 {
   if(self)
   {
 sampleData = sliderValue; 
sampleProduct = [[NSArray alloc] initWithObjects:@"", @"A", @"B", @"C", @"D", @"E",@"F",@"G",nil];

    // Initialize the currency formatter to support negative with the default currency style.
    currencyFormatter = [[NSNumberFormatter alloc] init];
    [currencyFormatter setNumberStyle:NSNumberFormatterCurrencyStyle];
    [currencyFormatter setNegativePrefix:@"-"];
    [currencyFormatter setNegativeSuffix:@""];
}
}

【问题讨论】:

    标签: ios charts slider bar-chart


    【解决方案1】:

    将该初始化代码移动到 buildGraph 方法中,然后您可以从 iinit 和您需要的新 IBAction(连接到 Slider 的 IBAction)调用该方法

    所以

    - (IBAction)onSliderChange {
         [self buildGraphData:self.slider.doubleValue]; //make the array with the new values
         [self.graph reloadData]; //you need this so CorePlot updates the specified graph view];
    }
    

    【讨论】:

    • 线索是你没有在 init 中这样做而是重新加载图表
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多