1

如何在android中的graphview上显示两个折线图从数据库中获取值?

这是我的代码

    gvp1=new GraphViewData[systolic.size()];
        for(int i=0;i<gvp1.length;i++)
        {
            gvp1[i]=new GraphViewData(Double.parseDouble(systolic.get(i).toString()), Double.parseDouble(diastolic.get(i).toString()));
        System.out.println("array avp1 is......."+Double.parseDouble(systolic.get(i).toString()));
        }

     LineGraphView graphView = new LineGraphView(
            this
            , "BP Graph"
    );


     graphView.addSeries(new GraphViewSeries(gvp1));

     System.out.println("in graphview......"+gvp1);

    /* 
     graphView.addSeries(new GraphViewSeries(new GraphViewData[] {

             new GraphViewData(1, 2.0d)
}));*/

    /*
     ViewHolder v = null;

     v = new ViewHolder();
     convertView=null;      
     */

     setContentView(graphView);
    // setContentView(R.layout.demo11);

     ImageView iv = new ImageView(this);
     iv.setImageResource(R.drawable.graph_header);
        graphView.addView(iv);






}

这就是我从数据库获取值到图形的方式。但我希望以相同的比例绘制另一个折线图。任何工作代码都会有很大帮助..

4

1 回答 1

4

只需调用 addSeries 放置折线图的其他数据。

查看我的实现:

    GraphViewSeries line1Series = new GraphViewSeries("LINE ONE", new GraphViewSeriesStyle(Color.GREEN, 3), new GraphViewData[] { new GraphViewData(0, 0) }); // put an complete array
    GraphViewSeries line2Series = new GraphViewSeries("LINE TWO", new GraphViewSeriesStyle(Color.BLUE, 3), new GraphViewData[] { new GraphViewData(0, 0) }); // put an complete array

    graphView = new LineGraphView(this, "Graph with 2 lines");
    graphView.addSeries(line1Series);
    graphView.addSeries(line2Series);

    graphView.setShowLegend(true);
    graphView.setLegendAlign(LegendAlign.TOP);
    graphView.setGraphViewStyle(new GraphViewStyle(Color.DKGRAY, Color.DKGRAY, Color.LTGRAY));

    graphView.redrawAll();

我希望这可以帮助你。

于 2013-07-10T14:36:21.987 回答