我在图表中使用的BalloonMarker出现问题,因为它不会显示所有图表元素的标记,而只会显示其中一个。
我将ChartsDemo项目中的BalloonMarker用于条形图。标记将显示,但仅用于图表中的一个条形图。我不知道这是否是巧合,但它从中间开始显示在酒吧上。
我看不到我在这里想念的东西。我可以添加任何错误或任何其他设置以使标记正确显示吗?
这是我用来为图表创建BallonMarker的代码:
BalloonMarker *balloonMarker = [[BalloonMarker alloc]
initWithColor: [UIColor colorWithWhite:180/255. alpha:0.9]
font: [UIFont systemFontOfSize:10.0]
textColor: UIColor.whiteColor
insets: UIEdgeInsetsMake(8.0, 8.0, 20.0, 8.0)];
balloonMarker.chartView = barChartOrdersView;
balloonMarker.minimumSize = CGSizeMake(40.f, 20.f);
我使用以下代码将标记添加到了图表:
barChartOrdersView.drawMarkers = YES;
barChartOrdersView.marker = balloonMarker;
条形图的属性为:
barChartOrdersView.gridBackgroundColor = [UIColor whiteColor];
barChartOrdersView.backgroundColor = [UIColor whiteColor];
barChartOrdersView.drawBarShadowEnabled = NO;
barChartOrdersView.drawValueAboveBarEnabled = YES;
barChartOrdersView.chartDescription.enabled = NO;
barChartOrdersView.dragEnabled = NO;
[barChartOrdersView setScaleEnabled:NO];
barChartOrdersView.pinchZoomEnabled = NO;
barChartOrdersView.rightAxis.enabled = NO;
barChartOrdersView.leftAxis.drawGridLinesEnabled = YES;
barChartOrdersView.leftAxis.drawLabelsEnabled = YES;
barChartOrdersView.leftAxis.labelFont = [UIFont systemFontOfSize:10.f];
barChartOrdersView.leftAxis.labelPosition = YAxisLabelPositionOutsideChart;
barChartOrdersView.leftAxis.spaceTop = 0.15;
barChartOrdersView.leftAxis.axisMinimum = 0.0;
barChartOrdersView.xAxis.labelPosition = XAxisLabelPositionBottom;
barChartOrdersView.xAxis.drawGridLinesEnabled = NO;
barChartOrdersView.xAxis.axisMinimum = 0.0;
barChartOrdersView.xAxis.granularity = 1.0;
barChartOrdersView.xAxis.labelFont = [UIFont systemFontOfSize:10.f];
barChartOrdersView.xAxis.drawGridLinesEnabled = NO;
barChartOrdersView.xAxis.granularity = 1.0;
barChartOrdersView.xAxis.labelCount = 7;
barChartOrdersView.xAxis.valueFormatter = [DayAxisValueFormatter new];
barChartOrdersView.legend.enabled = YES;
barChartOrdersView.legend.horizontalAlignment = ChartLegendHorizontalAlignmentLeft;
barChartOrdersView.legend.verticalAlignment = ChartLegendVerticalAlignmentBottom;
barChartOrdersView.legend.orientation = ChartLegendOrientationHorizontal;
barChartOrdersView.legend.drawInside = NO;
barChartOrdersView.legend.form = ChartLegendFormSquare;
barChartOrdersView.legend.formSize = 9.0;
barChartOrdersView.legend.font = [UIFont fontWithName:@"HelveticaNeue-Light" size:11.f];
barChartOrdersView.legend.xEntrySpace = 4.0;
最佳答案
确保您传入的条目按x值的升序排序。
如前所述,无序条目可能会导致意外行为,例如数据集闪烁或标记不可轻按。
关于ios - iOS图表标记未针对所有图表元素显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46037602/