2014-07-21 4 views
0

누구든지이 문제를 해결할 수 있습니까? 즉, 단일 LineAndPointFormatter로 안드로이드 플롯을 사용하여 여러 가지 색상의 그래프를 그려 볼 수 있습니까? 범위 값에 따라 LineAndPointFormatter 색상이 변경됩니다. 즉, 범위 값이 0-50 사이에 있다고 가정하면 범위 색상 값은 50-100이고 범위 값은 100-200이고 색상 값은 녹색입니다. 검은 색과 100 이상은 회색입니다. 어떻게 든 범위의 값이 그에 따라 나는 paint.setColor (Color.BLUE)를 사용하여 색상을 변경할 수 있습니다 얻을 것이다 경우 AndroidPlot Multi color LineAndPointFormatter

Check and let me know if below solution is fine or not i.e. 

LineAndPointFormatter formatter; 

formatter = new LineAndPointFormatter(Color.rgb(50, 143, 222), 
       null, null, null); 

Paint paint = formatter.getLinePaint(); 
paint.setStrokeWidth(10); // Set the formatter width 
paint.setColor(Color.BLUE); // Set the formatter color 
formatter.setLinePaint(paint); 

하지만, 어떻게 범위의 값을 가져 및 색상을 변경하는 문제에 직면하고있다;

해결 방법이 있으면 알려주십시오.

답변

1

정적 차트라고 가정하면 계열 데이터 (getMaxY() 메소드)에서 가장 큰 yVal을 찾고 아래에서 조회 (getColorForMaxVal() 메소드)를 수행하는 것처럼 간단해야합니다. 이 같은 뭔가 위의 코드를 바꿉니다 :

formatter = new LineAndPointFormatter(getColorForMaxVal(getMaxY(series1)), 
    null, null, null); 

/** 
* 
* @param maxVal 
* @return A color value appropriate for maxVal. 
*/ 
int getColorForMaxVal(Number maxVal) { 
    double max = maxVal.doubleValue(); 
    if(max > 50) { 
     return Color.GREEN; 
    } else if(max > 100) { 
     return Color.BLACK; 
    } else if(max > 200) { 
     return Color.GRAY; 
    } else { 
     return Color.BLUE; 
    } 
} 

/** 
* 
* @param series 
* @return The largest yVal in the series or null if the series contains no non-null yVals. 
*/ 
Number getMaxY(XYSeries series) { 
    Number max = null; 
    for(int i = 0; i < series.size(); i++) { 
     Number thisNumber = series.getY(i); 
     if(max == null || thisNumber != null && thisNumber.doubleValue() > max.doubleValue()) { 
      max = thisNumber; 
     } 
    } 
    return max; 
} 
필자 어딘가에 버그가있을 수 있습니다 있도록 컴파일 또는이 코드를 실행하려고하지,하지만 당신은 아이디어를 얻을