我想使用MPAndroidChart制作像这样的Barchart Barchart

时间:2018-06-27 05:06:40

标签: bar-chart mpandroidchart

enter image description here

这是我实施Barchart的方法: 公共无效setpiechart(条形图){         列表条目= new ArrayList();

    entries.add(new BarEntry(Float.parseFloat("2012"), 10f));
    entries.add(new BarEntry(Float.parseFloat("2013"), 20f));
    entries.add(new BarEntry(Float.parseFloat("2014"), 30f));
    entries.add(new BarEntry(Float.parseFloat("2015"), 40f));
    entries.add(new BarEntry(Float.parseFloat("2016"), 50f));
    entries.add(new BarEntry(Float.parseFloat("2017"), 60f));


    BarDataSet dataset = new BarDataSet(entries, "Entry");
    dataset.setColors(getResources().getColor(R.color.colorAccent));

    BarData data = new BarData(dataset);
    dataset.setValueTextSize(14f);
    dataset.setValueFormatter(new IValueFormatter() {
        @Override
        public String getFormattedValue(float value, Entry entry, int dataSetIndex, ViewPortHandler viewPortHandler) {
            return String.valueOf(value).replace(".0", "");
        }
    });
    data.setBarWidth(0.7f);
    XAxis xAxis = chart.getXAxis();
    YAxis left = chart.getAxisLeft();
    YAxis right = chart.getAxisRight();
    left.setDrawAxisLine(false);
    right.setDrawAxisLine(false);
    left.setDrawLabels(false);
    right.setDrawLabels(false);
    xAxis.setDrawAxisLine(true);
    xAxis.setAxisLineWidth(ViewGroup.LayoutParams.WRAP_CONTENT);
    xAxis.setAxisLineColor(getResources().getColor(R.color.lightbackground));
    xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
    xAxis.setTextSize(10f);
    xAxis.setValueFormatter(new IAxisValueFormatter() {
        @Override
        public String getFormattedValue(float value, AxisBase axis) {
            return String.valueOf(value).replace(".0", "");
        }
    });

我要使其与我上传的图片中显示的相同。

0 个答案:

没有答案