I am using an XYShapeRenderer with a LookUpPaintScale and I want to lock the crosshair on the data that I use.
Howerver, it doesn't work, however it works with XYShapeAndLineRenderer...
Here is my code :
Code: Select all
private void createPanel() throws FileNotFoundException, IOException {
List<String> listX = new ArrayList<>();
List<String> listY = new ArrayList<>();
List<String> listZ = new ArrayList<>();
String strFileName = "C:\\Users\\Daivy\\Documents\\NetBeansProjects\\TestFreeChart\\Test1.xyz";
ReadXYZFile(strFileName, listX, listY, listZ);
double[] arrayOfDoubleX = new double[listX.size()];
double[] arrayOfDoubleY = new double[listY.size()];
double[] arrayOfDoubleZ = new double[listZ.size()];
for (int x = 0; x < arrayOfDoubleX.length; ++x) {
arrayOfDoubleX[x] = Double.parseDouble(listX.get(x));
}
for (int y = 0; y < arrayOfDoubleY.length; ++y) {
arrayOfDoubleY[y] = Double.parseDouble(listY.get(y));
}
for (int z = 0; z < arrayOfDoubleZ.length; ++z) {
arrayOfDoubleZ[z] = Double.parseDouble(listZ.get(z));
}
double[][] arrayOfDouble = {arrayOfDoubleX, arrayOfDoubleY, arrayOfDoubleZ};
//AXIS X
NumberAxis localNumberAxisX = new NumberAxis("X");
localNumberAxisX.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
//AXISY
NumberAxis localNumberAxisY = new NumberAxis("Y");
localNumberAxisY.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
//DATASET, where values need to be added
DefaultXYZDataset defaultXYZDataset = new DefaultXYZDataset();
defaultXYZDataset.addSeries("Series 1", arrayOfDouble);
//LOOKUP PAINTSCALE
LookupPaintScale localLookupPaintScale = new LookupPaintScale(-4, 4, Color.blue);
localLookupPaintScale.add(-4.0D, new Color(238, 152, 255));
localLookupPaintScale.add(-3.0D, new Color(214, 152, 255));
localLookupPaintScale.add(-0.1D, new Color(191, 152, 255));
localLookupPaintScale.add(-2.0D, new Color(157, 159, 255));
localLookupPaintScale.add(-1.0D, new Color(152, 185, 255));
localLookupPaintScale.add(-0.5D, new Color(152, 245, 255));
localLookupPaintScale.add(-0.1D, new Color(255, 255, 0));
localLookupPaintScale.add(0.1D, new Color(255, 204, 0));
localLookupPaintScale.add(1.0D, new Color(255, 153, 0));
localLookupPaintScale.add(2.0D, new Color(255, 102, 0));
localLookupPaintScale.add(3.0D, new Color(255, 51, 0));
localLookupPaintScale.add(4.0D, new Color(255, 0, 0));
// localLookupPaintScale.add(5.0D, new Color(255, 0, 0));
//RENDERER TO PRINT CHART ON SCREEN
XYShapeRenderer xyShapeRenderer = new XYShapeRenderer();
xyShapeRenderer.setPaintScale(localLookupPaintScale);
xyShapeRenderer.setSeriesShape(0, new Rectangle2D.Double(-1,-1,10,10));
XYPlot xyPlot = new XYPlot(defaultXYZDataset, localNumberAxisX, localNumberAxisY, xyShapeRenderer);
xyPlot.setDomainCrosshairVisible(true);
xyPlot.setDomainCrosshairLockedOnData(true);
xyPlot.setRangeCrosshairVisible(true);
xyPlot.setRangeCrosshairLockedOnData(true);
xyPlot.setDomainZeroBaselineVisible(true);
xyPlot.setRangeZeroBaselineVisible(true);
//
JFreeChart jFreeChart = new JFreeChart("Test", xyPlot);
//PAINT SCALE
NumberAxis localNumberAxis = new NumberAxis("Error(mm)");
localNumberAxis.setAxisLinePaint(Color.white);
localNumberAxis.setTickMarkPaint(Color.white);
localNumberAxis.setTickLabelFont(new Font("Dialog", 0, 7));
PaintScaleLegend localPaintScaleLegend = new PaintScaleLegend(localLookupPaintScale, localNumberAxis);
localPaintScaleLegend.setStripOutlineVisible(false);
localPaintScaleLegend.setAxisLocation(AxisLocation.BOTTOM_OR_LEFT);
localPaintScaleLegend.setAxisOffset(5.0D);
localPaintScaleLegend.setMargin(new RectangleInsets(5.0D, 5.0D, 5.0D, 5.0D));//NO
localPaintScaleLegend.setFrame(new BlockBorder(Color.red));
localPaintScaleLegend.setPadding(new RectangleInsets(10.0D, 10.0D, 10.0D, 10.0D)); //NO
localPaintScaleLegend.setStripWidth(10.0D); //NO
localPaintScaleLegend.setPosition(RectangleEdge.LEFT);
jFreeChart.addSubtitle(localPaintScaleLegend);
ChartUtilities.applyCurrentTheme(jFreeChart);
this.chartPanel = new ChartPanel(jFreeChart);
this.chartPanel.setMouseWheelEnabled(true);
}