2

I want Show a graph exactly like this.enter image description here

I am using GraphView Library version 4.x.

    public class MainActivity extends AppCompatActivity {


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        // we get graph view instance
        GraphView graphview = (GraphView) findViewById(R.id.graph);
        LineGraphSeries<DataPoint> bgseries= new LineGraphSeries<>(new DataPoint[]{

                new DataPoint(0, 1),
                new DataPoint(1, 5),
                new DataPoint(2, 3),
                new DataPoint(3, 2),
                new DataPoint(4, 6),
                new DataPoint(5, 1),
                new DataPoint(6, 5),
                new DataPoint(7, 3),
                new DataPoint(8, 2),
                new DataPoint(9, 6)
        });
        graphview.addSeries(bgseries);

//        LineGraphSeries<DataPoint> series2 = new LineGraphSeries<DataPoint>(new DataPoint[] {
//                new DataPoint(0, 3),
//                new DataPoint(1, 3),
//                new DataPoint(2, 6),
//                new DataPoint(3, 2),
//                new DataPoint(4, 5)
//        });
        //graphview.addSeries(series2);

        //graphview.setDrawBackground(true);
        graphview.setBackgroundColor(getResources().getColor(android.R.color.holo_blue_bright));
        graphview.getViewport().setScalable(true);
        graphview.getViewport().setScrollable(true);
        graphview.setTitle("BloodSugar");
        graphview.setTitleColor(getResources().getColor(android.R.color.white));
   // legend
   bgseries.setTitle("foo");
  bgseries.setThickness(20);
        bgseries.setDrawBackground(true);
        bgseries.setBackgroundColor(R.color.red_bg);

//   series2.setTitle("bar");
//            series2.setColor(R.color.red_bg);

   graphview.getLegendRenderer().setVisible(true);
   graphview.getLegendRenderer().setAlign(LegendRenderer.LegendAlign.TOP); }

}

I tried alot to set a color on line.I can increase the thickness .also i want a curved one other than spikes.nothing is successfull. Can you please help me?

Noufal M
  • 163
  • 1
  • 4
  • 12

1 Answers1

0

For any one else landing on this page in seek of above kind of graph, following library's class CurveGraphWithRegionActivity.java might come useful.

http://devcodemarket.com/android-app-source-code-android-hz-grapher

Sourab Sharma
  • 2,940
  • 1
  • 25
  • 38