如何使用GraphView库在android studio中实现图形视图

时间:2015-09-22 11:53:04

标签: android android-graphview

我希望显示与此完全相同的图表。enter image description here

我正在使用GraphView Library版本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); }

}

我尝试了很多在线上设置颜色。我可以增加厚度。我也想要一个除了尖刺之外的弯曲的颜色。没有什么是成功的。 你能帮我吗?

0 个答案:

没有答案