2016-11-27 4 views
0

私のアプリでAndroidPlotを実装しましたが、正常に動作しますが、日付が明確でないため、原点の後に最初の値が必要です。最初のドメインラベルを原点から一歩移動する方法

私は、彼らがsetDomainValueFormat方法は、しかし、エラーメッセージが表示される追加質問hereで提案された解決策を試みた:

どれ

andriodplot

を "方法は解決できないの"原点の後にx軸ドメインを1ステップ開始する方法を提案しますか?

plot = (XYPlot) findViewById(R.id.plot); 

     XYSeries series = new SimpleXYSeries(Arrays.asList(dates_in_m_seconds), Arrays.asList(values_as_numbers), "BP Status"); 

     LineAndPointRenderer and configure them 
     LineAndPointFormatter seriesFormat = new LineAndPointFormatter(Color.RED, Color.GREEN,null, null); 


       plot.addSeries(series, seriesFormat); 

     // Specify x and y axes labels amount 
     plot.setRangeStep(StepMode.SUBDIVIDE,3); 
     plot.setDomainStep(StepMode.SUBDIVIDE,dates.size()); 

       plot.getGraph().getLineLabelStyle(XYGraphWidget.Edge.BOTTOM).setFormat(new Format() { 
      @Override 

      public StringBuffer format(Object obj, StringBuffer toAppendTo, FieldPosition pos) { 


       Date date_Label = new Date(Math.round(((Number) obj).doubleValue())); 

       return format.format(date_Label, toAppendTo, pos); 
      } 

      @Override 
      public Object parseObject(String source, ParsePosition pos) { 
       return null; 
      } 
     }); 



     plot.getGraph().getLineLabelStyle(XYGraphWidget.Edge.LEFT).setFormat(new Format() { 


      @Override 

      public StringBuffer format(Object obj, StringBuffer toAppendTo, FieldPosition pos) { 

       Number num = (Number) obj; 
       switch (num.intValue()) { 
        case 0: 
         toAppendTo.append("Low"); 
         break; 
        case 1: 
         toAppendTo.append("Normal"); 
         break; 
        case 2: 
         toAppendTo.append("High"); 
         break; 

        default: 
         toAppendTo.append("Unknown"); 
         break; 
       } 
       return toAppendTo; 

      } 

      @Override 
      public Object parseObject(String source, ParsePosition pos) { 
       return null; 
      } 
     }); 


      } 
+0

ですから、要素0,0のドメインと範囲ラベルが重ならないように右一歩にドメイン値を超えるシフトしたい、正しいですか?また、XYSeriesをインスタンス化するコードを投稿してください。 – Nick

+0

はい、これは私が何を意味するコードを確認してください、私はxyシリーズ@Nick投稿を更新することができます@ニック – user873101

答えて

0

この問題にはいくつかの方法があります。表面では、xVals間の厳密な一様な間隔を維持するのが望ましいと思われますが、あなたのxValはタイムスタンプだけではなく、丸められた生の入力であるため、ほぼ一様な間隔になります。この問題を完全に解決したい場合は、Y_VALS_ONLYを使用してXYSeriesをインスタンス化してから、ドメインのFormatインスタンスにラベルをレンダリングするルックアップテーブルとしてdates_as_m_secondsを使用します。

これまで、私はあなたの既存のコードで動作するはずのソリューションを用意しました。私はタイプミスがあるかもしれないので、それをコンパイルまたは実行しようdidntのが、一般的な考え方は動作します:

  1. 手動では、あなたのタイムスタンプデータの最初の要素の前にいくつかの余分なスペースが含まれるように、プロットのドメイン境界を設定します。
  2. ドメインエリアを細分化し、新しい不可視のステップ
  3. が効果的に目に見えない新しい最初の要素を作り、値<あなたのデータの最初のタイムスタンプをスキップするドメインラベルフォーマットのインスタンスを変更するための余地を作るために、余分な要素を追加。

コード:

  // this value must be final in order to be visible to the anonymous inner class instance 
      // of Format below. Note that this will fail miserably if you try to plot a series of 
      // size < 2. 
      final double firstX = Math.round(((Number) series.getX(0)).doubleValue()); 
      double secondX = Math.round(((Number) series.getX(1)).doubleValue()); 
      double lastX = Math.round(((Number) series.getX(series.size() - 1)).doubleValue()); 

      // assuming the step interval is uniform, this is the distance between each xVal: 
      double stepInterval = secondX - firstX; 

      // add in extra space for the first "invisible index" by setting the starting 
      // domain boundary exactly one interval before the first actual element: 
      plot.setDomainBoundaries(firstX - stepInterval, lastX, BoundaryMode.FIXED); 

      // add an extra "invisible index": 
      plot.setDomainStep(StepMode.SUBDIVIDE,dates.size() + 1); 

      ... 

      plot.getGraph().getLineLabelStyle(XYGraphWidget.Edge.BOTTOM).setFormat(new Format() { 

       @Override 
       public StringBuffer format(Object obj, StringBuffer toAppendTo, FieldPosition pos) { 
        double timestampMs = Math.round(((Number) obj).doubleValue()); 

        // only render indices corresponding to values in the series: 
        if(timestampMs >= firstX) { 
         Date date_Label = new Date(); 
         return format.format(date_Label, toAppendTo, pos); 
        } 
       } 

       @Override 
       public Object parseObject(String source, ParsePosition pos) { 
        return null; 
       } 
      }); 
+0

あなたの助けをお寄せいただきありがとうございますが、私はあなたの提案を静的タイプのエラー表示を試みたときに、ここに@Nick – user873101

+0

私の間違い - 最終的な、静的ではありませんでした。一定。 – Nick

+0

ありがとうございます=) – user873101

関連する問題