如何在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);
}
这就是我从数据库到图表获取值的方式。但我希望在同一比例下绘制另一个折线图。 任何工作代码都会有很大的帮助..
答案 0 :(得分: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();
我希望这可以帮到你。