2013-06-26 70 views

回答

1

我找到了解決自己

public class QualityChartRenderer extends XYLineAndShapeRenderer { 

    private int dataSeries; 

    public QualityChartRenderer(double high, double low, int dataSeries) { 
     this.dataSeries = dataSeries; 
    } 

    @Override 
    public void drawItem(Graphics2D g2, XYItemRendererState state, 
      Rectangle2D dataArea, PlotRenderingInfo info, XYPlot plot, 
      ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset, 
      int series, int item, CrosshairState crosshairState, int pass) { 

     Paint paint = getSeriesPaint(series); 

     if (series == dataSeries && item < 2) { 
      setSeriesPaint(series, Color.RED); 
     } 
     super.drawItem(g2, state, dataArea, info, plot, domainAxis, rangeAxis, 
       dataset, series, item, crosshairState, pass); 
     setSeriesPaint(series, paint); 
    } 

} 

對於繪製各種形狀,我檢查我的條件(這裏只item < 2),並改變整個系列的色彩。繪圖後我將它改回來。

這感覺就像一個黑客。框架內是否有更優雅的解決方案?