Java JFreeChart在同一数据系列的不同区域使用不同的颜色

Java JFreeChart在同一数据系列的不同区域使用不同的颜色,java,jfreechart,renderer,Java,Jfreechart,Renderer,在JFreeChart中,我试图根据y值为XY折线图/曲线的不同区域上色。我正在重写xylineandshaperender的getItemPaint(introw,intcol),但是我不确定它如何处理x之间的行的着色,因为它只在x上获取itemPaint(整数值) final xylineandshaperender渲染器=新的xylineandshaperender(){ @凌驾 @凌驾 公共绘制getItemPaint(int行,int列){ System.out.println(col

JFreeChart
中,我试图根据
y
值为XY折线图/曲线的不同区域上色。我正在重写
xylineandshaperender
getItemPaint(introw,intcol)
,但是我不确定它如何处理
x
之间的行的着色,因为它只在
x
上获取
itemPaint
(整数值)

final xylineandshaperender渲染器=新的xylineandshaperender(){
@凌驾
@凌驾
公共绘制getItemPaint(int行,int列){
System.out.println(col+”,“+dataset.getY(row,col));
双y=dataset.getYValue(行,列);

如果(y它看起来像是在
drawFirstPassShape

线条颜色似乎基于上一点

XYLineAndShapeRenderer的此修改使用渐变填充来混合线条颜色

XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(){
        @Override
        public Paint getItemPaint(int row, int col) {
            Paint cpaint = getItemColor(row, col);
            if (cpaint == null) {
                cpaint = super.getItemPaint(row, col);
            }
            return cpaint;
        }

    public Color getItemColor(int row, int col) {
        System.out.println(col + "," + dataset.getY(row, col));
        double y = dataset.getYValue(row, col);
        if(y<=3) return Color.black;
        if(y<=4) return Color.green;;
        if(y<=5) return Color.red;;
        if(y<=6) return Color.yellow;;
        if(y<=10) return Color.orange;;
        return null;
    }

    @Override
    protected void drawFirstPassShape(Graphics2D g2, int pass, int series,
        int item, Shape shape) {
        g2.setStroke(getItemStroke(series, item));
        Color c1 = getItemColor(series, item);
        Color c2 = getItemColor(series, item - 1);
        GradientPaint linePaint = new GradientPaint(0, 0, c1, 0, 300, c2);
        g2.setPaint(linePaint);
        g2.draw(shape);
    }
};
xylineandshaperender渲染器=新的xylineandshaperender(){
@凌驾
公共绘制getItemPaint(int行,int列){
Paint cpaint=getItemColor(行、列);
if(cpaint==null){
cpaint=super.getItemPaint(行、列);
}
返回cpaint;
}
公共颜色getItemColor(int行,int列){
System.out.println(col+”,“+dataset.getY(row,col));
双y=dataset.getYValue(行,列);
如果(y)
XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(){
        @Override
        public Paint getItemPaint(int row, int col) {
            Paint cpaint = getItemColor(row, col);
            if (cpaint == null) {
                cpaint = super.getItemPaint(row, col);
            }
            return cpaint;
        }

    public Color getItemColor(int row, int col) {
        System.out.println(col + "," + dataset.getY(row, col));
        double y = dataset.getYValue(row, col);
        if(y<=3) return Color.black;
        if(y<=4) return Color.green;;
        if(y<=5) return Color.red;;
        if(y<=6) return Color.yellow;;
        if(y<=10) return Color.orange;;
        return null;
    }

    @Override
    protected void drawFirstPassShape(Graphics2D g2, int pass, int series,
        int item, Shape shape) {
        g2.setStroke(getItemStroke(series, item));
        Color c1 = getItemColor(series, item);
        Color c2 = getItemColor(series, item - 1);
        GradientPaint linePaint = new GradientPaint(0, 0, c1, 0, 300, c2);
        g2.setPaint(linePaint);
        g2.draw(shape);
    }
};