1

我在 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];
}
4

2 回答 2

0

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

于 2012-12-03T06:27:01.277 回答
0

您可以做的一件事是在 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];


    }
}

}
于 2012-12-03T06:56:54.287 回答