gpt4 book ai didi

android - MPChart BarChart X 轴标签问题

转载 作者:行者123 更新时间:2023-12-05 00:06:28 25 4
gpt4 key购买 nike

我已经实现了 MPChart 库的 BarChart。

当条形图中的条形数量低于 9 时,标签与条形对齐,但一旦计数增加到 9 以上,标签就会被跳过,而不是 x 轴上的 9 个标签,它只显示 4- 5.截断标签字符串大小没有帮助。

截图: enter image description here enter image description here

我的代码:

            float index = 0;
ArrayList<String> xAxisLabel = new ArrayList<>();

for (Map.Entry<String, Integer> callMapVal : callMap.entrySet()) {
if (index < 8) {
barChartEntries.add(new BarEntry(index, callMapVal.getValue()));
if (callMapVal.getKey().length() > 10) {
xAxisLabel.add(getTruncated(callMapVal.getKey(), 9));
} else {
xAxisLabel.add(callMapVal.getKey());
}

}
index++;
}

BarDataSet dataSet = new BarDataSet(barChartEntries, selectedCallType.toString() + " CALLS");
dataSet.setValueTextSize(8f);
BarData chartData = new BarData(dataSet);
dataSet.setColors(ColorTemplate.COLORFUL_COLORS);
barChart.setData(chartData);
barChart.getXAxis().setValueFormatter(new IndexAxisValueFormatter(xAxisLabel));
//barChart.getXAxis().setLabelRotationAngle(20f);
barChart.getXAxis().setPosition(XAxis.XAxisPosition.BOTTOM);
barChart.getXAxis().setTextSize(8f);
//barChart.getXAxis().setAvoidFirstLastClipping(true);
barChart.getXAxis().setGranularityEnabled(true);
barChart.getXAxis().setCenterAxisLabels(false);
barChart.getDescription().setEnabled(false);
barChart.setFitBars(true); // make the x-axis fit exactly all bars
barChart.invalidate(); // refresh
barChart.setScaleEnabled(false);
barChart.setDoubleTapToZoomEnabled(false);
barChart.setBackgroundColor(Color.rgb(255, 255, 255));
barChart.setDrawBorders(false);
barChart.setDrawValueAboveBar(true);

最佳答案

您可以将标签计数设置为图表中的条数:

barChart.getXAxis().setLabelCount(9, true);

关于android - MPChart BarChart X 轴标签问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52685201/

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