2017-03-12 22 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

不工作。同樣的問題仍然存在。 –