Bar chart not working in AchartEngine

我怕爱的太早我们不能终老 提交于 2019-12-12 12:23:05

问题


I am trying to create Bar Chart using AchartEngine but various things doesn't work for me..

1) Unable to show Grid.

2) Unable to remove category series title i.e "Bar Graph".

3) It's not showing bars as it should show.

4) By Default white color background is visible.

is it possible to provide space between each bars??

Bar Chart Code

    CategorySeries series = new CategorySeries("Bar Graph");

    for (int i = 0; i < availCatList.size(); i++)
       series.add(availCatList.get(i), mTotal.get(i));

        XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset();
        dataset.addSeries(series.toXYSeries());

        XYSeriesRenderer seriesRenderer = new XYSeriesRenderer();
        seriesRenderer.setChartValuesSpacing(0.5f);
        seriesRenderer.setDisplayChartValues(true);
        seriesRenderer.setColor(Color.GREEN);

        XYMultipleSeriesRenderer mRenderer = new XYMultipleSeriesRenderer();
        mRenderer.setChartTitle("Bar Chart");
        mRenderer.setShowGrid(true);
        mRenderer.setAxisTitleTextSize(15);
        mRenderer.setXLabelsAlign(Align.CENTER);
        mRenderer.setXTitle("Categories");
        mRenderer.setYTitle("Amount");
        mRenderer.setScale(1.0f);

        for (int i = 0; i < availCatList.size(); i++) {

            mRenderer.addXTextLabel(i + 1, availCatList.get(i));
        }

        mRenderer.setXLabels(0);

        mRenderer.addSeriesRenderer(seriesRenderer);

        view = ChartFactory.getBarChartView(this, dataset, mRenderer,
                Type.DEFAULT);

        // layout.removeAllViews();

        layout.addView(view);

Any Help would be highly appreciated..

Thanks


回答1:


  1. mRenderer.setShowGrid(true) works fine in all the examples in the demo code. Try to set another color using mRenderer.setGridColor(color);
  2. You mean the legend: mRenderer.setShowLegend(false);
  3. series.add(mTotal.get(i)); is the correct usage for bar charts.
  4. That's probably from the profile. Just set your own background color.

Space between bars: read the APIs for mRenderer.setBarSpacing();



来源:https://stackoverflow.com/questions/14851820/bar-chart-not-working-in-achartengine

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!