iOS图表中的组合图表 - 不显示折线图的负值

时间:2016-10-13 23:02:03

标签: ios-charts

我正在使用io-Charts(https://github.com/danielgindi/Charts/)。 我必须在组合图表中显示条形图和折线图。 xAxis将反映-12到12之间的值,y值范围介于-3000到3000之间。虽然条形图适用于负y轴和x轴,但是对于小于0的值,未显示折线图。以下链接,

Negative values not displayed in line charts using ios-charts using Swift

我已设置_chartView.xAxis.axisMinimum = -12; //从-12而不是0开始。

请在下面找到当前图表, enter image description here

图表视图的设置和折线图的数据集

    - (LineChartData *)generateLineData

{     LineChartData * d = [[LineChartData alloc] init];

NSMutableArray *entries = [[NSMutableArray alloc] init];

[entries addObject:[[ChartDataEntry alloc] initWithX:0 y:-3000]];
[entries addObject:[[ChartDataEntry alloc] initWithX:0.5 y:-999]];
[entries addObject:[[ChartDataEntry alloc] initWithX:1 y:-1000]];
[entries addObject:[[ChartDataEntry alloc] initWithX:2 y:-1000]];
[entries addObject:[[ChartDataEntry alloc] initWithX:3.5 y:-1300]];
[entries addObject:[[ChartDataEntry alloc] initWithX:4 y:-900]];
[entries addObject:[[ChartDataEntry alloc] initWithX:5 y:-1200]];
[entries addObject:[[ChartDataEntry alloc] initWithX:6 y:-2500]];
[entries addObject:[[ChartDataEntry alloc] initWithX:8 y:-1300]];
[entries addObject:[[ChartDataEntry alloc] initWithX:9 y:1400]];
[entries addObject:[[ChartDataEntry alloc] initWithX:11 y:-900]];
[entries addObject:[[ChartDataEntry alloc] initWithX:12 y:-3000]];
[entries addObject:[[ChartDataEntry alloc] initWithX:-1 y:-1000]];
[entries addObject:[[ChartDataEntry alloc] initWithX:-2 y:-1300]];
[entries addObject:[[ChartDataEntry alloc] initWithX:-4 y:-1100]];
[entries addObject:[[ChartDataEntry alloc] initWithX:-5 y:-1500]];
[entries addObject:[[ChartDataEntry alloc] initWithX:-6 y:-1500]];
[entries addObject:[[ChartDataEntry alloc] initWithX:-8 y:-1100]];
[entries addObject:[[ChartDataEntry alloc] initWithX:-9 y:-1000]];
[entries addObject:[[ChartDataEntry alloc] initWithX:-11 y:-1500]];

LineChartDataSet *set = [[LineChartDataSet alloc] initWithValues:entries label:@"Line DataSet"];
[set setColor:[UIColor colorWithRed:240/255.f green:238/255.f blue:70/255.f alpha:1.f]];
set.lineWidth = 2.5;
set.fillColor = [UIColor colorWithRed:240/255.f green:238/255.f blue:70/255.f alpha:1.f];
set.mode = LineChartModeHorizontalBezier;
set.drawValuesEnabled = NO;
set.drawCirclesEnabled = NO;
set.axisDependency = AxisDependencyLeft;

[d addDataSet:set];

return d;

}

我不确定我是否错过了一些chartview的设置。

1 个答案:

答案 0 :(得分:0)

通过重新排序x值从-12到12的折线图数据集来解决这个问题,在我的原始问题中,数据集是混合的,而不是折线图的正确顺序。