【问题标题】:how to change the barchart values using slider in ios如何使用 ios 中的滑块更改条形图值
【发布时间】:2012-11-20 05:10:08
【问题描述】:

我在 iOS 中的条形图应用程序出现问题。我使用DSBarChart 和滑块控件创建了一个条形图。我希望图表在更改滑块时动态更改。我怎么做?这是我到目前为止所做的示例代码。

- (void)sliderValueDidChange:(UISlider *)sender {
    if((int)slider.value % 10 == 0) {
        positionLabel.text = [NSString stringWithFormat:@"%d",(int)slider.value];
        myValue =  (int)slider.value;
    }

    NSDictionary *dict =[NSDictionary dictionaryWithObjectsAndKeys:
                         [NSNumber numberWithInt:10], @"0",
                         [NSNumber numberWithInt:20], @"1",
                         [NSNumber numberWithInt:15], @"2",
                         [NSNumber numberWithInt:25], @"3",
                         [NSNumber numberWithInt:30], @"4",
                         [NSNumber numberWithInt:20], @"5",
                         [NSNumber numberWithInt:15], @"6",
                         nil];

    DSBarChart *chrt = [[DSBarChart alloc] initWithFrame:ChartView.bounds
                        color:[UIColor greenColor]
                        andDictionary:dict];
    chrt.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
    chrt.bounds = ChartView.bounds;
    [ChartView addSubview:chrt];
}

【问题讨论】:

  • 我不知道你犯了什么错误,你应该让我们知道是什么问题。
  • 嗨,我创建了 DSBarChart。你到底想在这里做什么?您是否尝试让多个滑块映射到图表?我不清楚你的问题。如果您可以更清楚地编辑/评论,我会帮助您。
  • 嗨,DhilipSiva 先生,我想创建带有滑块控件的条形图。当我的滑块改变或移动时,我的条形图值也会改变,我的图表也会改变。不知道怎么办?

标签: ios slider uislider bar-chart


【解决方案1】:

您可以做的一件事是在 barChart 上创建自定义视图。

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event

{

if (lineView) {
    [lineView removeFromSuperview];

    NSSet *allTouchesSet = [event allTouches]; 
    NSArray *allTouches = [NSArray arrayWithArray:[allTouchesSet allObjects]];   
    int count = [allTouches count];

    if (count  == 1) {

        UITouch *touch = [[event allTouches] anyObject];
        tapPoint = [touch locationInView:self];
        NSLog(@"tapPoint: %@",NSStringFromCGPoint(tapPoint));

        UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(tapPoint.x, 0.0, 1, 320.0)];
        lineView.backgroundColor = [UIColor whiteColor];
        [parentView addSubview:lineView];


    }
}

}

【讨论】:

    【解决方案2】:

    DSBarChart 还没有动态绑定到控件!但是有一个解决方法。当滑块的值更改被触发时,您可以从视图中删除现有的 DSBarchart 实例,使用更改的值创建一个新图表并将其再次添加到视图中。目前,DSBarChart 处于 pre-alpha 状态。它没有多大作用。有时间我会扩展功能的。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-07-22
      • 2020-07-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多