how to display two line charts on a graphview in android getting the values from database?

Pankaj Dahiya picture Pankaj Dahiya · Jun 19, 2013 · Viewed 8.4k times · Source

how to display two line charts on a graphview in android getting the values from database?

here is my code

    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);






}

this is how i am getting values from database to graph. but i want another line graph to be plotted on same scale. any working code will be a great help..

Answer

williamlopes picture williamlopes · Jul 10, 2013

Just call addSeries putting the other data of line graph.

See my implementation:

    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();

I hope this can help you.