AndroidPlot:如何在一个图上组合不同的图表类型?

时间:2014-01-19 16:51:42

标签: charts androidplot

如何在一个图上组合折线图和条形图?该文档未提及此功能。这对AndroidPlot来说是否可行?

1 个答案:

答案 0 :(得分:0)

在活动的oncreate()中使用此功能。

setContentView(R.layout.main);
    XYPlot plot = (XYPlot) findViewById(R.id.mySimpleXYPlot);

    Number[] series1Numeros = { 1, 8, 5, 2, 7, 4 };
    XYSeries series1 = new SimpleXYSeries(Arrays.asList(series1Numeros), 
            SimpleXYSeries.ArrayFormat.Y_VALS_ONLY, "Intereses");

    XYSeries series = new SimpleXYSeries(Arrays.asList(new Number[] { 1, 2, 3, 4, 5 }),
            SimpleXYSeries.ArrayFormat.Y_VALS_ONLY, "title");
    BarFormatter formatter = new BarFormatter(Color.rgb(0, 200, 0), Color.rgb(100, 0, 0));
    plot.addSeries(series, BarRenderer.class, formatter);
    BarRenderer renderer = (BarRenderer) plot.getRenderer(BarRenderer.class);
    LineAndPointFormatter series1Format = new LineAndPointFormatter(Color.rgb(0, 200, 0),
            Color.rgb(0, 100, 0),
            null); 

    plot.addSeries(series1, series1Format);