2017-03-12 28 views
0

我正在从数据库中取出股票的日期,其中公司的股票历史记录保留在数据库列中。每天的数据以{date,stock_value}的格式显示,并由其他日期的“\ n”分隔。Android GraphView仅在X轴上呈现一个日期

String[] allStocks = history.split("\n"); 
    String[] singleStock; 

    ArrayList<DataPoint> points = new ArrayList<>(); 
    GraphView graph = (GraphView) findViewById(R.id.graph); 

    for(int i=0; i<3; i++) 
     { 
      singleStock = allStocks[i].split(","); 
      Date date = new Date(Long.parseLong(singleStock[0])); 
      System.out.println(date); 
      points.add(new DataPoint(new Date(Long.parseLong(singleStock[0])), Float.parseFloat(singleStock[1]))); 
     } 

    DataPoint[] dbPoint = points.toArray(new DataPoint[points.size()]); 
    System.out.println(points); 
    LineGraphSeries<DataPoint> series = new LineGraphSeries<DataPoint>(dbPoint); 
    graph.addSeries(series); 
    graph.getGridLabelRenderer().setLabelFormatter(new DateAsXAxisLabelFormatter(this)); 
    graph.getGridLabelRenderer().setNumHorizontalLabels(2); 
    // set manual x bounds to have nice steps 

    graph.getViewport().setXAxisBoundsManual(true); 

    // as we use dates as labels, the human rounding to nice readable numbers 
    // is not necessary 
    graph.getGridLabelRenderer().setHumanRounding(false); 

以下是点的可变内容: [[1.4887386E12/117.55000305175781],[1.4881338E12/118.62000274658203],[1.4876154E12/118.79000091552734]]

该图显示为: The graph appears only for one date

这是我的图表中的XML:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="vertical" android:layout_width="match_parent" 
android:layout_height="match_parent"> 

<com.jjoe64.graphview.GraphView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:id="@+id/graph" /> 

</LinearLayout> 

只有一个日期出现在图表。当我尝试来自'GraphView'的示例代码的日期时,一切都按预期工作。请让我知道我的代码是否有缺陷。

回答

0

我不GraphView工作过,但我发现日期的例子似乎水平标签的数量被设定为一个比项目数量多,图表绘制,所以我会尝试:

graph.getGridLabelRenderer().setNumHorizontalLabels(points.size()+1); 
+0

不工作。同样的问题仍然存在。 –