JFree XYBarRenderer getItemPaint问题

时间:2015-12-22 14:58:06

标签: jfreechart

让我首先说明我已经在JFree论坛上发布了这个,所以如果我双重发帖,我会道歉......

嗨 - 我写了一个自定义渲染器,我正在使用XYBarPlot。我的数据集有41个点,如下所示

Row 0 Column 0 X-Value -1.70000000298 Y-Value 0.0 Row 0 Column 1 X-Value -1.615000002831 Y-Value 0.0 Row 0 Column 2 X-Value -1.530000002682 Y-Value 0.0 Row 0 Column 3 X-Value -1.445000002533 Y-Value 0.0 Row 0 Column 4 X-Value -1.360000002384 Y-Value 0.0 Row 0 Column 5 X-Value -1.275000002235 Y-Value 0.0 Row 0 Column 6 X-Value -1.190000002086 Y-Value 0.0 Row 0 Column 7 X-Value -1.105000001937 Y-Value 0.0 Row 0 Column 8 X-Value -1.020000001788 Y-Value 0.0 Row 0 Column 9 X-Value -0.935000001639 Y-Value 0.0 Row 0 Column 10 X-Value -0.85000000149 Y-Value 0.0 Row 0 Column 11 X-Value -0.765000001341 Y-Value 0.0 Row 0 Column 12 X-Value -0.680000001192 Y-Value 0.0 Row 0 Column 13 X-Value -0.595000001043 Y-Value 0.0 Row 0 Column 14 X-Value -0.510000000894 Y-Value 0.0 Row 0 Column 15 X-Value -0.425000000745 Y-Value 0.0 Row 0 Column 16 X-Value -0.340000000596 Y-Value 0.0 Row 0 Column 17 X-Value -0.255000000447 Y-Value 0.0 Row 0 Column 18 X-Value -0.170000000298 Y-Value 0.0 Row 0 Column 19 X-Value -0.085000000149 Y-Value 336.0 Row 0 Column 20 X-Value 0.0 Y-Value 33.0 Row 0 Column 21 X-Value 0.085000000149 Y-Value 2.0 Row 0 Column 22 X-Value 0.170000000298 Y-Value 2.0 Row 0 Column 23 X-Value 0.255000000447 Y-Value 1.0 Row 0 Column 24 X-Value 0.340000000596 Y-Value 0.0 Row 0 Column 25 X-Value 0.425000000745 Y-Value 0.0 Row 0 Column 26 X-Value 0.510000000894 Y-Value 0.0 Row 0 Column 27 X-Value 0.595000001043 Y-Value 0.0 Row 0 Column 28 X-Value 0.680000001192 Y-Value 0.0 Row 0 Column 29 X-Value 0.765000001341 Y-Value 0.0 Row 0 Column 30 X-Value 0.85000000149 Y-Value 0.0 Row 0 Column 31 X-Value 0.935000001639 Y-Value 0.0 Row 0 Column 32 X-Value 1.020000001788 Y-Value 0.0 Row 0 Column 33 X-Value 1.105000001937 Y-Value 0.0 Row 0 Column 34 X-Value 1.190000002086 Y-Value 0.0 Row 0 Column 35 X-Value 1.275000002235 Y-Value 0.0 Row 0 Column 36 X-Value 1.360000002384 Y-Value 0.0 Row 0 Column 37 X-Value 1.445000002533 Y-Value 0.0 Row 0 Column 38 X-Value 1.530000002682 Y-Value 0.0 Row 0 Column 39 X-Value 1.615000002831 Y-Value 0.0 Row 0 Column 40 X-Value 1.70000000298 Y-Value 0.0

当我将图表设置为自动缩放X轴时,我看到为以下项目调用了getItemPaint,我希望这对我有意义 Row 0 Column 19 X-Value -0.085000000149 Y-Value 336.0 Row 0 Column 20 X-Value 0.0 Y-Value 33.0 Row 0 Column 21 X-Value 0.085000000149 Y-Value 2.0 Row 0 Column 22 X-Value 0.170000000298 Y-Value 2.0 Row 0 Column 23 X-Value 0.255000000447 Y-Value 1.0

然而,当我手动将X轴上的刻度设置为-1到+1时,我看到为以下项目调用了getItemPaint Row 0 Column 12 X-Value -0.680000001192 Y-Value 0.0 Row 0 Column 13 X-Value -0.595000001043 Y-Value 0.0 Row 0 Column 14 X-Value -0.510000000894 Y-Value 0.0 Row 0 Column 15 X-Value -0.425000000745 Y-Value 0.0 Row 0 Column 16 X-Value -0.340000000596 Y-Value 0.0

如果我选择-0.14到+0.14,我会看到调用getItemPaint Row 0 Column 2 X-Value -1.530000002682 Y-Value 0.0 Row 0 Column 3 X-Value -1.445000002533 Y-Value 0.0 Row 0 Column 4 X-Value -1.360000002384 Y-Value 0.0

最后-0.05到+0.05我看到要调用getItemPaint Row 0 Column 2 X-Value -1.530000002682 Y-Value 0.0

对我来说,看到getItemPaint被称为reduce的次数是有意义的,因为图表上显示的条形较少,但为什么列值不能反映数据集中的正确值?即,当我将范围缩小到-0.05到+0.05时,图表上唯一的条形应该是Y值33,我希望传递给getItemPaint的列值为20,而不是2?

我缺少什么或不理解?

以下是我的自定义渲染器使用的代码。

import java.awt.Color;
import java.awt.Paint;
import org.jfree.chart.renderer.xy.XYBarRenderer;
import org.jfree.data.xy.XYDataset;

/**
 *
 * @author a344254
 */
public class ExtendedBarRenderer extends XYBarRenderer {

double UCL, LCL, USL, LSL;
/**
 * Creates a new renderer.
 */
public ExtendedBarRenderer(double USL, double LSL, double UCL, double LCL) {
    super();
    this.UCL = UCL;
    this.LCL = LCL;
    this.USL = USL;
    this.LSL = LSL;
}

public Paint getItemPaint(int row, int column) {
    XYDataset dataDataset = getPlot().getDataset(0);

    if (dataDataset.getX(row, column).doubleValue() >= this.USL || dataDataset.getX(row, column).doubleValue() <= this.LSL){
        return (Color.red);
    }
    else if (dataDataset.getX(row, column).doubleValue() >= this.UCL || dataDataset.getX(row, column).doubleValue() <= this.LCL){
        return (Color.yellow);
    }
    else{
        return (Color.green);
    }
}

}

由于

0 个答案:

没有答案