1

我正在使用 AChart Engine 显示条形图,并希望显示如下条形图:

在此处输入图像描述

但它最终是这样的: 在此处输入图像描述

这是非常令人沮丧的,我在过去的 4 个小时里都在尝试给它一个正确的格式,但失败了。我在互联网上搜索了一个合适的教程,但无法管理。你能告诉我我应该包括什么片段吗?

这是我的尝试代码:

public class BarGraph{

    public GraphicalView getView(Context context) 
    {   
        // Bar 1

        XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset();

        CategorySeries ac = new CategorySeries("AC");
        CategorySeries pe = new CategorySeries("PE");
        CategorySeries wa = new CategorySeries("WA");
        CategorySeries tl = new CategorySeries("TL");
        CategorySeries ml = new CategorySeries("ML");
        CategorySeries ce = new CategorySeries("CE");
        CategorySeries re = new CategorySeries("RE");
        CategorySeries ot = new CategorySeries("OT");
        ac.add(291);
        dataset.addSeries(ac.toXYSeries());
        pe.add(11);
        dataset.addSeries(pe.toXYSeries());
        wa.add(204);
        dataset.addSeries(ac.toXYSeries());
        tl.add(28);
        dataset.addSeries(pe.toXYSeries());
        ml.add(0);
        dataset.addSeries(ac.toXYSeries());
        ce.add(21);
        dataset.addSeries(pe.toXYSeries());
        re.add(51);
        dataset.addSeries(ac.toXYSeries());
        ot.add(4);
        dataset.addSeries(pe.toXYSeries());


        XYMultipleSeriesRenderer mRenderer = new XYMultipleSeriesRenderer();
        mRenderer.setChartTitle("Submission Statistics");
        mRenderer.setXTitle("Verdict Code");
        mRenderer.setYTitle("No. of Submissions");
        mRenderer.setAxesColor(Color.BLACK);
        mRenderer.setLabelsColor(Color.BLACK);
        mRenderer.setApplyBackgroundColor(true);
        mRenderer.setBackgroundColor(Color.WHITE);
        mRenderer.setMarginsColor(Color.WHITE);
        mRenderer.setZoomEnabled(true);
        mRenderer.setZoomButtonsVisible(true);

        XYSeriesRenderer renderer = new XYSeriesRenderer();
        renderer.setColor(Color.parseColor("#00AA00"));
        renderer.setDisplayChartValues(true);
        renderer.setChartValuesSpacing((float) 0.5);

        XYSeriesRenderer renderer2 = new XYSeriesRenderer();
        renderer2.setColor(Color.parseColor("#666600"));
        renderer2.setDisplayChartValues(true);
        renderer2.setChartValuesSpacing((float) 0.5);

        XYSeriesRenderer renderer3 = new XYSeriesRenderer();
        renderer3.setColor(Color.parseColor("#FF0000"));
        renderer3.setDisplayChartValues(true);
        renderer3.setChartValuesSpacing((float) 0.5);

        XYSeriesRenderer renderer4 = new XYSeriesRenderer();
        renderer4.setColor(Color.parseColor("#0000FF"));
        renderer4.setDisplayChartValues(true);
        renderer4.setChartValuesSpacing((float) 0.5);

        XYSeriesRenderer renderer5 = new XYSeriesRenderer();
        renderer5.setColor(Color.parseColor("#6767D0"));
        renderer5.setDisplayChartValues(true);
        renderer5.setChartValuesSpacing((float) 0.5);

        XYSeriesRenderer renderer6 = new XYSeriesRenderer();
        renderer6.setColor(Color.parseColor("#AAAA00"));
        renderer6.setDisplayChartValues(true);
        renderer6.setChartValuesSpacing((float) 0.5);

        XYSeriesRenderer renderer7 = new XYSeriesRenderer();
        renderer7.setColor(Color.parseColor("#00AAAA"));
        renderer7.setDisplayChartValues(true);
        renderer7.setChartValuesSpacing((float) 0.5);

        XYSeriesRenderer renderer8 = new XYSeriesRenderer();
        renderer8.setColor(Color.parseColor("#000000"));
        renderer8.setDisplayChartValues(true);
        renderer8.setChartValuesSpacing((float) 0.5);


        mRenderer.addSeriesRenderer(renderer);
        mRenderer.addSeriesRenderer(renderer2);
        mRenderer.addSeriesRenderer(renderer3);
        mRenderer.addSeriesRenderer(renderer4);
        mRenderer.addSeriesRenderer(renderer5);
        mRenderer.addSeriesRenderer(renderer6);
        mRenderer.addSeriesRenderer(renderer7);
        mRenderer.addSeriesRenderer(renderer8);

        return ChartFactory.getBarChartView(context, dataset,mRenderer, Type.DEFAULT);
    }

}
4

1 回答 1

1

我建议不要建造CategorySeries,而是建造XYSeries。然后,在第一个系列中做:series.add(1, 291);第二个将是series.add(2, 11);依此类推。

于 2013-07-16T13:25:21.153 回答