Search in sources :

Example 11 with Crosshair

use of org.jfree.chart.plot.Crosshair 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);
}
Also used : Shape(java.awt.Shape) XYPlot(org.jfree.chart.plot.XYPlot) ValueAxis(org.jfree.chart.axis.ValueAxis) Crosshair(org.jfree.chart.plot.Crosshair) Rectangle2D(java.awt.geom.Rectangle2D) Iterator(java.util.Iterator) JFreeChart(org.jfree.chart.JFreeChart) RectangleEdge(org.jfree.chart.ui.RectangleEdge)

Aggregations

Crosshair (org.jfree.chart.plot.Crosshair)11 BasicStroke (java.awt.BasicStroke)7 Color (java.awt.Color)5 GridBagLayout (java.awt.GridBagLayout)5 JLabel (javax.swing.JLabel)5 ChartMouseEvent (org.jfree.chart.ChartMouseEvent)5 ChartMouseListener (org.jfree.chart.ChartMouseListener)5 ChartPanel (org.jfree.chart.ChartPanel)5 ChartEntity (org.jfree.chart.entity.ChartEntity)5 XYItemEntity (org.jfree.chart.entity.XYItemEntity)5 CrosshairOverlay (org.jfree.chart.panel.CrosshairOverlay)5 XYDataset (org.jfree.data.xy.XYDataset)5 JPanel (javax.swing.JPanel)4 GradientPaint (java.awt.GradientPaint)2 Paint (java.awt.Paint)2 Shape (java.awt.Shape)2 Rectangle2D (java.awt.geom.Rectangle2D)2 ArrayList (java.util.ArrayList)2 Iterator (java.util.Iterator)2 List (java.util.List)2