2016-10-11 11 views
0

天気予報アプリのために時間をかけてandroid-graphviewを使って時間をプロットしています。Android GraphViewラベルの書式設定時のX軸のステップが正しくありません

私のタブの「24時間」では、現在の時刻から24時間後までのデータをプロットします。私は3時間のステップで天気予報を持っています。 x軸に適切な表示を実現するには、まず、日が変更されたときに時間を追加する必要があります。したがって、現在の時刻が18:00になってから18:00までデータをプロットすると、x軸の値は - > 18 21 24 27 30 33 36 39 42. です。次に、ラベルフォーマッタを使用して、 x軸ラベル - > 18 21 0 3 6 9 12 15 18. グラフは正しいポイントで正しく表示されますが、ラベルは3ではなく2のステップに従いますが、範囲は正しいです。

System.out.println( "WHAT1?" ..は入力データポイントのペアを3時間単位で正しく表示しますが、 System.out.println( "pout"と "pour"はx軸の値が(正しい位置にあることが)2のステップで増加 がどのようにラベルが3hour段階で表示することができ

私が間違って何をやっているここでのコードは次のとおりです。??

DataPoint b= new DataPoint(0,0);//test 
      DataPoint[] point_array= new DataPoint[9]; 
      String[] time_label_24=new String[9]; 

      GraphView graph = (GraphView) findViewById(R.id.graph); 
      hour=Integer.parseInt(Lista.get(x)[15]); 

      for(int i=x;i<=x+8;i++){ 
       if((i-x)<Lista.size()) { 
        b = new DataPoint(hour, Float.parseFloat(Lista.get(i)[4])); 
        point_array[i - x] = b; 
        System.out.println("WHAT1? " + (i - x) + " " + point_array[i - x] + " " + hour); 
        time_label_24[i-x]=Lista.get(i)[15]; 
        hour = hour + 3; 
       } 
      } 

      LineGraphSeries<DataPoint> series = new LineGraphSeries<DataPoint>(point_array); 
      graph.addSeries(series);                


      h=Integer.parseInt(Lista.get(x)[15]); 

      graph.getViewport().setXAxisBoundsManual(true); 

      //graph.getViewport().setMinX(Integer.parseInt(Lista.get(x)[15])-1); 
      //graph.getViewport().setMaxX(Integer.parseInt(Lista.get(x)[15])+8*3+1); 

      graph.getViewport().setMinX(Integer.parseInt(Lista.get(x)[15])); 
      graph.getViewport().setMaxX(Integer.parseInt(Lista.get(x)[15])+8*3); 

      graph.getGridLabelRenderer().setNumHorizontalLabels(9); //9 

      graph.getGridLabelRenderer().setTextSize(12f); 
      graph.getGridLabelRenderer().reloadStyles(); 



      graph.getGridLabelRenderer().setLabelFormatter(new DefaultLabelFormatter() { 
       @Override 
       public String formatLabel(double value, boolean isValueX) { 
        int xylabel; 
        if (isValueX) { 

         if (value < 24) { 
          System.out.println("pout "+value+" " + String.valueOf(value)); 
          xylabel = (int) Math.round(value); 
          return String.valueOf(xylabel); 
         } else{ 
          System.out.println("pour "+value+" " + String.valueOf(value%24)); 
          xylabel = (int) Math.round(value); 
          return String.valueOf(xylabel%24); 
         } 
        }else { 
         xylabel = (int) Math.round(value); 
         return String.valueOf(xylabel); // let graphview generate Y-axis label for us 
        } 
       } 
      }); 
     //////// 


      hour=Integer.parseInt(Lista.get(x)[15]); 
      for(int i=x;i<=x+8;i++){ // Same process for Temp FEEL           
       if((i-x)<Lista.size()) { 
        b = new DataPoint(hour, Float.parseFloat(Lista.get(i)[13])); 
        point_array[i - x] = b; 
        hour = hour + 3; 
        time_label_24[i-x]=Lista.get(i)[15];   
        System.out.println("What2? " + point_array[i - x]); 
       } 
      } 



      LineGraphSeries<DataPoint> series2 = new LineGraphSeries<DataPoint>(point_array); 
      graph.addSeries(series2); 

      series.setTitle("Temp"); 
      series2.setTitle("Feel"); 

      series.setColor(Color.WHITE); 
      series2.setColor(Color.RED); 

      graph.getLegendRenderer().setVisible(true); 
      graph.getLegendRenderer().setAlign(LegendRenderer.LegendAlign.TOP); 

グラフのイメージは次のとおりです。

resulting graph

答えて

0

graph.getGridLabelRenderer().setHumanRounding(false);

を経由して、人間の丸めを無効にしよう
関連する問題