微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

android – 使用多个系列的不同颜色条

我是 Android新手,我正在尝试使用AChartEngine创建一个条形图,它有3个条形图,每个条形图应该是不同的颜色.我尝试使用多个系列但不能使我的x轴值与条形对齐
protected void onResume() {
    super.onResume();
     layout = (LinearLayout) findViewById(R.id.chart);
     if (mChartView == null) 
     {
             PeakSeries = new XYSeries("Income");
             ForecastPeakSeries = new XYSeries("Expense");
             ForecastSeries = new XYSeries("Expense");

            int[] x = { 1,2,3};
            int income = 2000;
            int expense =  2700;
            System.out.println("Here");
            Series1.add(x[0],income);
            Series2.add(x[1],expense);
            Series3.add(x[2],expense);

            // Creating a dataset to hold each series
            XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset();

            dataset.addSeries(Series1);
            dataset.addSeries(Series2);
            dataset.addSeries(Series3);


            XYSeriesRenderer Renderer1 = new XYSeriesRenderer();
            Renderer1 .setColor(Color.RED);
            Renderer1 .setChartValuesTextSize(18);
            Renderer1 .setFillPoints(true);
            Renderer1 .setdisplayChartValues(true);

            // Creating XYSeriesRenderer to customize expenseSeries
            XYSeriesRenderer Renderer2 = new XYSeriesRenderer();
            Renderer2 .setColor(Color.YELLOW);
            Renderer2 .setChartValuesTextSize(18);
            Renderer2 .setdisplayChartValues(true);

            XYSeriesRenderer Renderer3 = new XYSeriesRenderer();
            Renderer3 .setColor(Color.CYAN);
            Renderer3 .setChartValuesTextSize(18);
            Renderer3 .setFillPoints(true);
            Renderer3 .setChartValuesTextAlign(Align.CENTER);
            Renderer3 .setdisplayChartValues(true);

            // Creating a XYMultipleSeriesRenderer to customize the whole chart
                double[] range = {0,5,5};
            multiRenderer.setMargins(new int[] {50,50,50});
            multiRenderer.setAxisTitleTextSize(16);
            multiRenderer.setChartTitleTextSize(30);
            multiRenderer.setLabelsTextSize(15);
            multiRenderer.setLegendTextSize(20);
            multiRenderer.setLegendHeight(40);
            multiRenderer.setBarSpacing(-0.7);
            multiRenderer.setAxesColor(Color.WHITE);
            multiRenderer.setinitialRange(range,1);
            multiRenderer.setXAxisMin(0.4);
            multiRenderer.setXAxisMax(4);
            multiRenderer.setYAxisMax(5000);
            multiRenderer.setYAxisMin(0);
            multiRenderer.setXLabelsAlign(Align.RIGHT);
            multiRenderer.setYLabelsAlign(Align.RIGHT);
            //multiRenderer.s(Align.LEFT);
            multiRenderer.setPanEnabled(false,false);
            multiRenderer.setZoomEnabled(true,true);

            multiRenderer.setChartTitle("7 Day Outlook - Maxiumum Demand");
            multiRenderer.setXTitle("Date");
            multiRenderer.setYTitle("MW");

            multiRenderer.addSeriesRenderer(Renderer1 );
            multiRenderer.addSeriesRenderer(Renderer2 );
            multiRenderer.addSeriesRenderer(Renderer3 );

            final GraphicalView mChartView = ChartFactory.getBarChartView(TestSevenday1.this,dataset,multiRenderer,Type.DEFAULT);
            layout.addView(mChartView);

     }
     else
     {
         mChartView.repaint();
     }
}

任何帮助是极大的赞赏.

解决方法

我通过在GetBarChartView中将Type从Type.Default设置为Type.Stacked来处理它.
ChartFactory.getBarChartView(TestSevenday1.this,Type.STACKED);

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐