1

我有两个具有两个不同 Y 轴和一个 X 轴的数据系列。我正在尝试绘制双 Y 轴(或在 Excel 中称为辅助 Y 轴),以便缩放图表。但是对于两个数据系列,我只得到一个 Y 轴。注意:我使用的是 AChartEngine 1.1.0

任何人都可以请建议。

下面给出了我的代码和屏幕截图。

public class LineChart {
    public Intent getIntent(Context context){

        int[] x = {1,2,3,4,5,6,7,8,9,10};
        int[] y = {22,45,34,45,55,65,74,85,93,100};

        TimeSeries series = new TimeSeries("Data1");
        for(int i = 0; i<x.length; i++){
            series.add(x[i], y[i]);
        }

        int[] x2 = {1,2,3,4,5,6,7,8,9,10};
        int[] y2 = {223,454,334,454,554,655,745,855,935,510};

        TimeSeries series2 = new TimeSeries("Data2");
        for(int i = 0; i<x.length; i++){
            series2.add(x2[i], y2[i]);
        }


        //Multiple Series Data Set
        XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset(); 
        dataset.addSeries(series); //First Data Series
        dataset.addSeries(series2); //Second Data Series

        //Multiple Series Renderer
        XYMultipleSeriesRenderer mRenderer = new XYMultipleSeriesRenderer(2);
        //Background
        mRenderer.setApplyBackgroundColor(true);
        mRenderer.setBackgroundColor(Color.BLACK);
        //mRenderer.setMarginsColor(Color.parseColor("#F5F5F5"));
        //Grid
        mRenderer.setShowGridY(true);
        mRenderer.setShowGridX(true);
        mRenderer.setGridColor(Color.WHITE);
        //Label
        mRenderer.setLabelsTextSize(14);
        mRenderer.setXLabelsColor(Color.GREEN);
        //Min and Max
        mRenderer.setXAxisMax(series.getMaxX());
        mRenderer.setXAxisMin(series.getMinX());

        //Dual yaxis
        mRenderer.setYLabelsColor(0, Color.GREEN);
        mRenderer.setYLabelsColor(1, Color.RED); 
        mRenderer.setYTitle("Y-AXIS1", 0);
        mRenderer.setYTitle("Y-AXIS2", 1);
        mRenderer.setYAxisAlign(Align.LEFT, 0);
        mRenderer.setYAxisAlign(Align.RIGHT, 1);
        mRenderer.setYLabelsAlign(Align.LEFT, 0);
        mRenderer.setYLabelsAlign(Align.RIGHT, 1);


        //First Series - Single Series Renderer
        XYSeriesRenderer renderer = new XYSeriesRenderer();
        renderer.setColor(Color.RED);
        renderer.setPointStyle(PointStyle.CIRCLE);
        renderer.setFillPoints(true);

        //Second Series - Single Series Renderer
        XYSeriesRenderer renderer2 = new XYSeriesRenderer();
        renderer2.setColor(Color.GREEN);
        renderer2.setPointStyle(PointStyle.CIRCLE);
        renderer2.setFillPoints(true);

        //Add renderers to multiple series Renderer
        mRenderer.addSeriesRenderer(renderer);
        mRenderer.addSeriesRenderer(renderer2);


        Intent intent = ChartFactory.getLineChartIntent(context, dataset, mRenderer, "Line Graph Title");

        return intent;
    }

}

截图在这里

4

1 回答 1

0

最后,我使用这个例子完成了它 -这里

于 2013-08-19T15:34:57.307 回答