How to remove unnecessary space between bars in AchartEngine?

家住魔仙堡 提交于 2020-01-01 16:58:53

问题


It just adds unnecessary space between each bars.. How i can reduce or remove it?? All data are dynamically generated.. I tried setting bar width but it doesn't work..

Please see the attached image..

Updated Code

        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);

Any help would be highly appreciated..


回答1:


When you only have one item per series, you could use renderer.setBarWidth(width), where value could be something like (screenWidth - leftMargin - rightMargin) / seriesCount.




回答2:


try Using :

mRenderer.setBarSpacing(0.0f);


来源:https://stackoverflow.com/questions/14875769/how-to-remove-unnecessary-space-between-bars-in-achartengine

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