2016-11-13 79 views
0

我有一個問題與graphView在Android上,當我嘗試與x軸的日期顯示我的圖我得到了這樣的結果:每次 graph不顯示Android的圖形視圖日期軸正確

X值改變我生成圖形,圖形中的條有時會顯示,有時候不是真正的隨機。

這裏是我的代碼:

  Cursor weeklySale = db.getWeeklySale(login); 

      DataPoint[] dp= new DataPoint[weeklySale.getCount()]; 
      Date[] dates= new Date[weeklySale.getCount()]; 

      int i=0; 
      while(weeklySale.moveToNext()) 
      { 
       SimpleDateFormat sdf = new SimpleDateFormat("dd MM yyyy"); 
       Calendar cal = Calendar.getInstance(); 
       cal.set(Calendar.WEEK_OF_YEAR, Integer.valueOf(weeklySale.getString(1))); 
       cal.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY); 

       // Date c = new Date(weeklySale.getLong(1)); 
       dp[i]= new DataPoint(cal.getTime(), (long)weeklySale.getFloat(0)); 
       dates[i]= cal.getTime(); 

       System.out.println(weeklySale.getFloat(0)+" + "+weeklySale.getString(1)+" , "+sdf.format(cal.getTime())); 
      } 

      graph.removeAllSeries(); 

      GridLabelRenderer gridLabel = graph.getGridLabelRenderer(); 
      gridLabel.setHorizontalAxisTitle("Semaine"); 
      gridLabel.setVerticalAxisTitle("CA"); 

      LineGraphSeries series = new LineGraphSeries<DataPoint>(dp); 
      series.setColor(Color.RED); 
      graph.addSeries(series); 

感謝

回答

0

嘗試通過改變標籤的數量:

graph.getGridLabelRenderer().setNumHorizontalLabels()

你也應該將這一行了while循環節省內存和性能: SimpleDateFormat sdf = new SimpleDateFormat("dd MM yyyy");