如何删除AchartEngine中栏之间不必要的空格?

时间:2013-02-14 13:18:31

标签: android achartengine

它只是在每个栏之间添加了不必要的空间..我如何减少或删除它?所有数据都是动态生成的。我尝试设置条宽但不起作用..

请参阅附图..

更新代码

        XYMultipleSeriesRenderer mRenderer = new XYMultipleSeriesRenderer();
        mRenderer.setXLabelsColor(Color.BLUE);
        mRenderer.setYLabelsColor(0, Color.BLUE);
        mRenderer.setScale(0.5f);
        mRenderer.setBarSpacing(0.5f);
        mRenderer.setBarWidth(75);
        mRenderer.setAxisTitleTextSize(10);

        mRenderer.setXLabelsAlign(Align.CENTER);
        mRenderer.setYLabelsAlign(Align.RIGHT);

        mRenderer.setMargins(new int[] { 20, 30, 20, 0 });
        mRenderer.setXTitle("Categories");
        mRenderer.setYTitle("Amount");

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

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

        mRenderer.setXLabels(0);

        mRenderer.setChartTitle("Bar Chart");

        XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset();

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

            XYSeries series = new XYSeries(availCatList.get(i));

            series.add(i + 1, mTotal.get(i));

            dataset.addSeries(series);

            XYSeriesRenderer seriesRenderer = new XYSeriesRenderer();

            seriesRenderer.setChartValuesSpacing(0.5f);
            seriesRenderer.setChartValuesTextAlign(Align.CENTER);
            seriesRenderer.setChartValuesTextSize(10.0f);
            seriesRenderer.setDisplayChartValues(true);

            Random r = new Random();
            int color = Color.argb(255, r.nextInt(256), r.nextInt(256),
                    r.nextInt(256));

            seriesRenderer.setColor(color);

            mRenderer.addSeriesRenderer(seriesRenderer);
        }

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

          layout.addView(view);

任何帮助都将受到高度赞赏..

Bar Chart

2 个答案:

答案 0 :(得分:2)

如果每个系列只有一个项目,则可以使用renderer.setBarWidth(width),其中value可能类似于(screenWidth - leftMargin - rightMargin) / seriesCount

答案 1 :(得分:0)

尝试使用:

mRenderer.setBarSpacing(0.0f);