gpt4 book ai didi

ios - JBChartView 中未显示条形图的颜色

转载 作者:行者123 更新时间:2023-11-29 10:41:55 25 4
gpt4 key购买 nike

我正在尝试在我的 iOS 应用中实现条形图。我正在使用 JBChartView。一切正常,但条形图没有颜色,除非我使用 touchEvent 按下它们。

有没有人有使用这个特定插件的经验来帮助我让它正常工作?

谢谢

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

最佳答案

问题似乎在于 JBBarChartView 如何“规范化”这些值。根据 JBBarChartView.h 的头文件:

/**
* 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)
*/

由于这种“规范化”,当您的所有值都相同时 (100.0f),它会将它们全部规范化为 0,因此没有要显示的栏。幸运的是,它是开源的,所以你只需要打开实现文件并做一点修改:

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

关于ios - JBChartView 中未显示条形图的颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24123794/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com