用`MPAndroidChart`绘制水平条形图

时间:2017-10-28 08:29:05

标签: android mpandroidchart

有没有人知道如何做到这一点:my app image看起来像这样:how it should be

我的问题是:如何让水平条形图的每一行填充在两行之间?

for (Iterator<Map.Entry<String, Float>> iterator = structuredData.entrySet().iterator(); iterator.hasNext();) {
                Map.Entry<String, Float> entry = iterator.next();
                //i*10 => starting position of the bar
                horizontalBarChartArr.add(new BarEntry((i*10), entry.getValue()));
                names.add(entry.getKey());
                i++;
            }

            XAxis xAxis = horizontalBarChart.getXAxis();
            xAxis.setValueFormatter(new IAxisValueFormatter() {
                @Override
                public String getFormattedValue(float value, AxisBase axis) {
                    return names.get((int)value % names.size());
                }
            });

            xAxis.setDrawGridLines(true);
            xAxis.setDrawAxisLine(true);
            BarDataSet barDataSet = new BarDataSet(horizontalBarChartArr, "Day Expenses");
            barDataSet.setColors(Color.RED);
            BarData data = new BarData(barDataSet);
            data.setBarWidth(9f);
            horizontalBarChart.setDoubleTapToZoomEnabled(false);
            Description a = new Description();
            a.setText("");
            horizontalBarChart.setDescription(a);
            horizontalBarChart.invalidate();
            horizontalBarChart.animateY(1200);
            horizontalBarChart.setData(data);

1 个答案:

答案 0 :(得分:0)

根据您的情况检查此示例:

https://github.com/ddanny/achartengine

自动从code.google.com/p/achartengine

导出

enter image description here