2016-11-27 1 views
0

내 앱에서 AndroidPlot을 구현했지만 제대로 작동하지만 날짜가 명확하지 않아 원점에서 한 단계 뒤의 첫 번째 값이 필요합니다.첫 번째 도메인 레이블을 원점에서 한 단계 이동하는 방법

andriodplot

하나를 "방법은 해결할 수없는"

나는 그들이 그러나 setDomainValueFormat 방법 오류 메시지가 표시 추가 묻는 질문 here에서 제안 된 솔루션을 시도 원점 후 x 축 도메인을 한 단계 시작하는 방법 제안?

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 사이의 엄격한 균일 한 간격을 유지하는 것이 바람직하지만, xVals는 타임 스탬프 일뿐만 아니라 원시 입력의 반올림 버전이기 때문에 거의 균일 한 간격을 얻게됩니다. 이 문제를 완전히 해결하려면 Y_VALS_ONLY를 사용하여 XYSeries를 인스턴스화 한 다음 조회 테이블로 dates_as_m_seconds를 사용하여 도메인 Format 인스턴스의 레이블을 렌더링하십시오.

그런데, 나는 기존 코드와 함께 작동해야하는 솔루션을 포함 시켰습니다. 나는 오타가있을 수 있습니다 있도록 컴파일하거나 실행하려고 didnt는하지만 일반적인 생각은 작동합니다

  1. 가 수동으로 타임 스탬프 데이터의 첫 번째 요소 전에 몇 가지 여분의 공간을 포함하도록 플롯의 도메인 경계를 설정합니다. 도메인 영역을 세분하면
  2. 효과적으로 새로운 첫 번째 요소는 보이지 않게, 데이터의 값 < 최초의 타임 스탬프를 건너 뛸 도메인 라벨 형식의 인스턴스를 수정 새로운 보이지 않는 단계를위한 공간을 만들기 위해 추가 요소를 추가 .

코드 :

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