use of org.jfree.chart.ui.RectangleEdge in project n2a by frothga.
the class Raster method createChart.
public JFreeChart createChart(final XYDataset dataset) {
final JFreeChart chart = ChartFactory.createScatterPlot(// chart title
null, // x axis label
null, // y axis label
null, // data
dataset, PlotOrientation.VERTICAL, // include legend
false, // tooltips
true, // urls
false);
XYPlot plot = chart.getXYPlot();
plot.setBackgroundPaint(Color.white);
plot.setRangeGridlinePaint(Color.lightGray);
plot.setDomainPannable(true);
plot.setRangePannable(true);
plot.setRenderer(new XYDotRenderer() {
public void drawItem(java.awt.Graphics2D g2, XYItemRendererState state, java.awt.geom.Rectangle2D dataArea, PlotRenderingInfo info, XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset, int series, int item, CrosshairState crosshairState, int pass) {
if (!getItemVisible(series, item))
return;
int dotWidth = 1;
double rasterLines = rangeAxis.getRange().getLength();
int pixels = g2.getClipBounds().height;
double height = pixels / rasterLines;
if (height > 10)
height -= 2;
else if (height > 2)
height -= 1;
int dotHeight = (int) Math.min(20, Math.max(1, Math.floor(height)));
double x = dataset.getXValue(series, item);
double y = dataset.getYValue(series, item);
if (Double.isNaN(y))
return;
double adjx = (dotWidth - 1) / 2.0;
double adjy = (dotHeight - 1) / 2.0;
RectangleEdge xAxisLocation = plot.getDomainAxisEdge();
RectangleEdge yAxisLocation = plot.getRangeAxisEdge();
double transX = domainAxis.valueToJava2D(x, dataArea, xAxisLocation) - adjx;
double transY = rangeAxis.valueToJava2D(y, dataArea, yAxisLocation) - adjy;
g2.setPaint(Color.black);
PlotOrientation orientation = plot.getOrientation();
if (orientation == PlotOrientation.HORIZONTAL)
g2.fillRect((int) transY, (int) transX, dotHeight, dotWidth);
else
g2.fillRect((int) transX, (int) transY, dotWidth, dotHeight);
int datasetIndex = plot.indexOf(dataset);
updateCrosshairValues(crosshairState, x, y, datasetIndex, transX, transY, orientation);
}
});
NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
// Integer units only
rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
return chart;
}
use of org.jfree.chart.ui.RectangleEdge in project jfreechart-fx by jfree.
the class CrosshairOverlayFX method paintOverlay.
@Override
public void paintOverlay(Graphics2D g2, ChartCanvas chartCanvas) {
if (chartCanvas.getRenderingInfo() == null) {
return;
}
Shape savedClip = g2.getClip();
Rectangle2D dataArea = chartCanvas.getRenderingInfo().getPlotInfo().getDataArea();
g2.clip(dataArea);
JFreeChart chart = chartCanvas.getChart();
XYPlot plot = (XYPlot) chart.getPlot();
ValueAxis xAxis = plot.getDomainAxis();
RectangleEdge xAxisEdge = plot.getDomainAxisEdge();
Iterator iterator = getDomainCrosshairs().iterator();
while (iterator.hasNext()) {
Crosshair ch = (Crosshair) iterator.next();
if (ch.isVisible()) {
double x = ch.getValue();
double xx = xAxis.valueToJava2D(x, dataArea, xAxisEdge);
if (plot.getOrientation() == PlotOrientation.VERTICAL) {
drawVerticalCrosshair(g2, dataArea, xx, ch);
} else {
drawHorizontalCrosshair(g2, dataArea, xx, ch);
}
}
}
ValueAxis yAxis = plot.getRangeAxis();
RectangleEdge yAxisEdge = plot.getRangeAxisEdge();
iterator = getRangeCrosshairs().iterator();
while (iterator.hasNext()) {
Crosshair ch = (Crosshair) iterator.next();
if (ch.isVisible()) {
double y = ch.getValue();
double yy = yAxis.valueToJava2D(y, dataArea, yAxisEdge);
if (plot.getOrientation() == PlotOrientation.VERTICAL) {
drawHorizontalCrosshair(g2, dataArea, yy, ch);
} else {
drawVerticalCrosshair(g2, dataArea, yy, ch);
}
}
}
g2.setClip(savedClip);
}
Aggregations