2017-03-12 39 views
0

회사의 주식 기록이 DB 열에 보관되는 데이터베이스에서 주식 날짜를 가져옵니다. 매일 데이터는 {date, stock_value} 형식으로 표시되며 다른 날짜는 "\ n"으로 구분됩니다. 는 [1.4887386E12/117.55000305175781]를 [1.4881338E12/118.62000274658203]가 [1.4876154E12은/118.79000091552734]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); 

는 다음 변수 점의 내용이다 The graph appears only for one date

<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> 

하나의 날짜가 나타납니다

이 내 그래프에 대한 XML이다 그래프. 'GraphView'에서 날짜 용 예제 코드를 사용하면 모든 것이 예상대로 작동합니다. 제 코드에 결함이 있는지 알려주세요.

답변

0

내가 전에 GraphView 함께 일한 적이 없다,하지만 난 날짜에 ​​대해 발견 된 예는 그래프되는 항목의 수보다 하나의 수평 레이블 수를 설정하는 것 같았다, 그래서 나는 그 시도 할 것이다 :

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

'작동하지 않습니다. 같은 문제가 계속 발생합니다. –