繁体   English   中英

MPChart BarChart X轴标签问题

[英]MPChart BarChart X-Axis label issue

我已经实现了MPChart库的BarChart。

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

屏幕截图: 在此处输入图片说明 在此处输入图片说明

我的代码:

            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);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM