Achartengine线图使用来自JSON解析的数据

时间:2015-05-29 18:44:17

标签: json achartengine

我正在解析JSON链接以获得2个字符串系列(x轴中的日期和y轴中的整数)。 我想我需要将两个字符串转换为整数,我不确定。 我想使用achartengine库中的图形线显示x轴上的日期和y轴上的值。

来自JSON的字符串系列“格式化”: “54.5x” “28.8x” “80.7x” .......

来自JSON的字符串系列“enddates”: “2011-12-31” “2010-10-19” “2009-10-113” .......

2个字符串系列是“格式化”和“结束” 如何使用achartengine折线图在y轴上显示格式并在x轴上显示日期?下面是我可以修改的achartengine线图示例。提前谢谢。

public class LineGraph{



public Intent getIntent(Context context) {



    // Our first data
    int[] x = {1,2,3,4,5,6,7,8,9,10 }; // x values!
    int[] y =  { 30, 34, 45, 57, 77, 89, 100, 111 ,123 ,145 }; // y values!
    TimeSeries series = new TimeSeries("Line1");//That's the description of the line at the bottom
    for( int i = 0; i < y.length; i++)
    {
        series.add(x[i], y[i]);
    }



    XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset();//This object holds all the series(lines) in one graph
    dataset.addSeries(series);

    //each series has a renderer

    XYSeriesRenderer renderer = new XYSeriesRenderer(); // This will be used to customize line 1
    // Customization time for line 1!
    renderer.setColor(Color.WHITE);
    renderer.setPointStyle(PointStyle.SQUARE);
    renderer.setFillPoints(true);
    renderer.setDisplayChartValues(true);// it displays the y values right by the chart dots



    XYMultipleSeriesRenderer mRenderer = new XYMultipleSeriesRenderer(); // Holds a collection of XYSeriesRenderer and customizes the graph
    mRenderer.addSeriesRenderer(renderer);

    mRenderer.setZoomButtonsVisible(true);
    mRenderer.setYLabels(10);
    mRenderer.setXLabels(5); //sets x values on the x axis, for instance if x=5, it sets 5 values in total on the x axis
    mRenderer.setChartTitle("Bus Vs Taxy Chart");
    mRenderer.setXTitle("Dates");
    mRenderer.setYTitle("Number of Vehicles Sold");





    //the intent puts together the Context(context), the Dataset(dataset), the Renderer(mRenderer) and the Line Graph Title
    //The LineChartIntent specifies the type of chart that I want, in this case a line.
    Intent intent = ChartFactory.getLineChartIntent(context, dataset, mRenderer, "Line Graph");//here I set the Title
    return intent;

}

}

0 个答案:

没有答案