2014-06-09 2 views
1

iOS 앱에 막 대형 차트를 구현하려고합니다. 나는 JBChartView를 사용하고있다. 모든 것이 잘 작동하지만 touchEvent를 사용하여 바를 제외하고는 막대에 색상이 없습니다.막대 차트의 색이 JBChartView에 표시되지 않습니다.

누구나 올바르게 작동하도록이 특정 플러그인에 대한 경험이 있습니까?

감사

- (void)viewDidLoad 
    { 


     _barChartView = [[JBBarChartView alloc] init]; 
     _barChartView.delegate = self; 
     _barChartView.dataSource = self; 


    _tableView.backgroundColor =[UIColor clearColor]; 
     _barChartView.frame = CGRectMake(0,0,200,200); 
     _barChartView.backgroundColor = [UIColor clearColor]; 
     [_barChartView reloadData]; 
     [_barChart addSubview: _barChartView]; 

    } 


    - (UIColor *)barSelectionColorForBarChartView:(JBBarChartView *)barChartView 
    { 
     return [UIColor greenColor]; // color of selection view 
    } 
    - (BOOL)slideNavigationControllerShouldDisplayLeftMenu 
    { 
     return YES; 
    } 
    - (UIColor *)barChartView:(JBBarChartView *)barChartView colorForBarViewAtIndex:(NSUInteger)index 
    { 
     return [UIColor greenColor]; 
    } 

    - (NSUInteger)numberOfBarsInBarChartView:(JBBarChartView *)barChartView 
    { 
     return 4; 
    } 
    - (CGFloat)barChartView:(JBBarChartView *)barChartView heightForBarViewAtAtIndex:(NSUInteger)index 
    { 
     return 100.0; 
    } 

답변

2

문제는 JBBarChartView이 값을 "정상화"어떻게 함께 할 것으로 보인다. 이 때문에 "정상화"당신의 모든 값이 동일한 (100.0f)에있는이 0으로 그들 모두를 정규화, 그래서 표시 할 바가 없다의

/** 
* Height for a bar at a given index (left to right). There is no ceiling on the the height; 
* the chart will automatically normalize all values between the overal min and max heights. 
* 
* @param barChartView  The bar chart object requesting this information. 
* @param index   The 0-based index of a given bar (left to right, x-axis). 
* 
* @return The y-axis height of the supplied bar index (x-axis) 
*/ 

: JBBarChartView.h에 대한 헤더 파일 당.

- (CGFloat)normalizedHeightForRawHeight:(NSNumber*)rawHeight 
{ 
    CGFloat minHeight = [self minimumValue]; 
    CGFloat maxHeight = [self maximumValue]; 
    CGFloat value = [rawHeight floatValue]; 

    if ((maxHeight - minHeight) <= 0) 
    { 
     return self.availableHeight; // change this line to return the max height instead of 0 
    } 

    return ((value - minHeight)/(maxHeight - minHeight)) * [self availableHeight]; 
} 
+0

'min = max' (일명 모두 높이가 같음) 때마다 "0으로 나누기"오류가 발생해야하기 때문에이 실행도 놀랍습니다. – Stonz2

+0

설명해 주셔서 감사합니다. 작동하지만 이상한 문제는 표시되지 않습니다. 그래서 0 값을 설정해야하는 추가 막대를 하나 더 추가해야합니다 ... –

0

문제에 대한 올바른 해결책은 차트에서 최소 값을 제공하는 것입니다 : 당신은 그냥 구현 파일을 열고 조금 수정해야하므로 다행히, 그것은 오픈 소스이다.

JBChartView에 대한 설명서 @를보고하십시오 :

/** 
* The minimum and maxmimum values of the chart. 
* If no value(s) are supplied: 
* 
* minimumValue = chart's data source min value. 
* maxmimumValue = chart's data source max value. 
* 
* If value(s) are supplied, they must be >= 0, otherwise an assertion will be thrown. 
* The min/max values are clamped to the ceiling and floor of the actual min/max values of the chart's data source; 
* for example, if a maximumValue of 20 is supplied & the chart's actual max is 100, then 100 will be used. 
* 
* For min/max modifications to take effect, reloadData must be called. 
*/ 
@property (nonatomic, assign) CGFloat minimumValue; 
@property (nonatomic, assign) CGFloat maximumValue; 

를 모든 데이터는 단일 값 (. 즉, 100)과 같은 경우, 모든 막대를 보장합니다 0의 최소 값을 제공 동일에서 그려 (보이는) 높이 (0에 대해).

희망이 도움이됩니다.