如何在graphview android中显示double或float?

时间:2016-06-06 18:18:50

标签: android

我需要制作一个十进制数字图(浮点数或双精度数),我正在使用GraphView jjoe64库。

当我这样做时,图表没有显示:

  var button = new Button();
        if (button.WidthRequest < 120)
        {
            button.WidthRequest = 120;
        }

2 个答案:

答案 0 :(得分:0)

添加到xml这个

 <com.jjoe64.graphview.GraphView
        android:layout_width="match_parent"
        android:layout_height="200dip"
        android:title="Graph Title"
        android:id="@+id/graph"
        android:layout_below="@+id/linetext"/>

这段代码:

GraphView line_graph = (GraphView) findViewById(R.id.graph);
   LineGraphSeries<DataPoint> line_series =
           new LineGraphSeries<DataPoint>(new DataPoint[] {
           new DataPoint(0, 1),
           new DataPoint(1, 5),
           new DataPoint(2, 3),
           new DataPoint(3, 2),
           new DataPoint(4, 6)
   });
   line_graph.addSeries(line_series);

答案 1 :(得分:-1)

这是我使用Float变量的可行解决方案:

在onCreate之前定义变量:

public static float x1, y1 = 0;
public static float x2, y2 = 0;
public static float x3, y3 = 0;

在OnCreate之后,请使用以下代码:

try { //I use Try-Catch on here for not get an app crash
PointsGraphSeries<DataPoint> series = new PointsGraphSeries<>(new DataPoint[]{  //You can also use LineGraphSeries if you want to

        new DataPoint( x3, y3), //Your variables were defined above.
        new DataPoint( x2, y2),
        new DataPoint( x1, y1)


});
graph.addSeries(series); //Put those variables into "graph"

} catch (Exception e) {
e.printStackTrace();
Toast toast = Toast.makeText(getApplicationContext(), "Error: " + e, Toast.LENGTH_LONG);
toast.show();
}