Example usage for org.jfree.chart.annotations XYLineAnnotation XYLineAnnotation

List of usage examples for org.jfree.chart.annotations XYLineAnnotation XYLineAnnotation

Introduction

In this page you can find the example usage for org.jfree.chart.annotations XYLineAnnotation XYLineAnnotation.

Prototype

public XYLineAnnotation(double x1, double y1, double x2, double y2) 

Source Link

Document

Creates a new annotation that draws a line from (x1, y1) to (x2, y2) where the coordinates are measured in data space (that is, against the plot's axes).

Usage

From source file:inflor.core.gates.ui.PolygonGateAdapter.java

@Override
public void mouseClicked(MouseEvent e) {
    Point2D v = ChartUtils.getPlotCoordinates(e, panel);
    if (SwingUtilities.isLeftMouseButton(e)) {
        // add the next segment
        anchorPoint = v;/*  w  ww  . java  2s .  co m*/
        vertices.add(v);
        updateTemporaryAnnotation();
    }
    if (SwingUtilities.isLeftMouseButton(e) && e.getClickCount() == 2) {
        XYLineAnnotation closingSegment = new XYLineAnnotation(anchorPoint.getX(), anchorPoint.getY(),
                vertices.get(0).getX(), vertices.get(0).getY());
        segments.add(closingSegment);
        panel.addTemporaryAnnotation(closingSegment);

        // Finish the polygon and ask for a name
        int pointCount = vertices.size() * 2;
        double[] polygon = new double[pointCount];
        for (int i = 0; i < pointCount; i++) {
            polygon[i] = vertices.get(i / 2).getX();
            polygon[i + 1] = vertices.get(i / 2).getY();
            i++;//Sonar warning but wont fix, I think.
        }
        // Pop a gate editor dialog
        GateNameEditor dialog = new GateNameEditor();
        dialog.setVisible(true);
        // On Close...
        if (dialog.isOK()) {
            PolygonGateAnnotation finalPolygon = new PolygonGateAnnotation(dialog.getGateName(),
                    panel.getDomainAxisName(), panel.getRangeAxisName(), polygon, LookAndFeel.DEFAULT_STROKE,
                    LookAndFeel.DEFAULT_GATE_COLOR);
            panel.createGateAnnotation(finalPolygon);
        }
        dialog.dispose();

        // remove the anchor point && cleanup segments.
        vertices.clear();
        panel.removeTemporaryAnnotation(anchorSegment);
        anchorSegment = null;
        anchorPoint = null;
        segments.forEach(panel::removeTemporaryAnnotation);//TODO:if this is broken, maybe sonar was wrong?
        segments = null;
        panel.activateGateSelectButton();
    }
}

From source file:net.sourceforge.processdash.ui.web.reports.snippets.EstErrorScatterChart.java

@Override
public JFreeChart createChart() {
    JFreeChart chart = super.createChart();

    // set minimum/maximum bounds on the two axes
    XYPlot xyPlot = chart.getXYPlot();//from   w w  w .j  a v  a2  s  . c  om
    double cutoff = getPercentParam("cut", 100, 200, 5000);
    xyPlot.setDomainAxis(truncAxis(xyPlot.getDomainAxis(), cutoff));
    xyPlot.setRangeAxis(truncAxis(xyPlot.getRangeAxis(), cutoff));
    xyPlot.setRenderer(new TruncatedItemRenderer(xyPlot.getRenderer()));

    // add a box illustrating the target range
    if (data.numRows() > 0) {
        double box = getPercentParam("pct", 0, 50, 100);
        xyPlot.addAnnotation(new XYBoxAnnotation(-box, -box, box, box));
        xyPlot.addAnnotation(new XYLineAnnotation(-box, 0, box, 0));
        xyPlot.addAnnotation(new XYLineAnnotation(0, -box, 0, box));
    }

    return chart;
}

From source file:org.jfree.chart.demo.PlotOrientationDemo.java

/**
 * Creates a new demo instance./*from   www  .j  av  a2  s.  c o m*/
 * 
 * @param title  the frame title.
 */
public PlotOrientationDemo(String title) {

    super(title);
    JPanel panel = new JPanel(new GridLayout(2, 4));
    for (int i = 0; i < CHART_COUNT; i++) {
        this.datasets[i] = createDataset(i);
        this.charts[i] = createChart(i, this.datasets[i]);
        XYPlot plot = this.charts[i].getXYPlot();
        XYShapeAnnotation a1 = new XYShapeAnnotation(new Rectangle2D.Double(1.0, 2.0, 2.0, 3.0),
                new BasicStroke(1.0f), Color.blue);
        XYLineAnnotation a2 = new XYLineAnnotation(0.0, -5.0, 10.0, -5.0);
        XYImageAnnotation a3 = new XYImageAnnotation(5.0, 2.0, JFreeChart.INFO.getLogo());
        plot.addAnnotation(a1);
        plot.addAnnotation(a2);
        plot.addAnnotation(a3);
        plot.setQuadrantPaint(0, new Color(230, 230, 255));
        plot.setQuadrantPaint(1, new Color(230, 255, 230));
        plot.setQuadrantPaint(2, new Color(255, 230, 230));
        plot.setQuadrantPaint(3, new Color(255, 230, 255));
        this.panels[i] = new ChartPanel(this.charts[i]);
    }
    this.charts[1].getXYPlot().getDomainAxis().setInverted(true);
    this.charts[2].getXYPlot().getRangeAxis().setInverted(true);
    this.charts[3].getXYPlot().getDomainAxis().setInverted(true);
    this.charts[3].getXYPlot().getRangeAxis().setInverted(true);

    this.charts[5].getXYPlot().getDomainAxis().setInverted(true);
    this.charts[6].getXYPlot().getRangeAxis().setInverted(true);
    this.charts[4].getXYPlot().getDomainAxis().setInverted(true);
    this.charts[4].getXYPlot().getRangeAxis().setInverted(true);

    this.charts[4].getXYPlot().setOrientation(PlotOrientation.HORIZONTAL);
    this.charts[5].getXYPlot().setOrientation(PlotOrientation.HORIZONTAL);
    this.charts[6].getXYPlot().setOrientation(PlotOrientation.HORIZONTAL);
    this.charts[7].getXYPlot().setOrientation(PlotOrientation.HORIZONTAL);

    panel.add(this.panels[0]);
    panel.add(this.panels[1]);
    panel.add(this.panels[4]);
    panel.add(this.panels[5]);
    panel.add(this.panels[2]);
    panel.add(this.panels[3]);
    panel.add(this.panels[6]);
    panel.add(this.panels[7]);

    panel.setPreferredSize(new Dimension(800, 600));
    setContentPane(panel);

}

From source file:org.jfree.chart.demo.PlotOrientationDemo2.java

/**
 * Creates a new demo instance./*from  ww  w  .  j  a  va  2 s  .  c  o m*/
 * 
 * @param title  the frame title.
 */
public PlotOrientationDemo2(String title) {

    super(title);
    JPanel panel = new JPanel(new GridLayout(2, 4));
    for (int i = 0; i < CHART_COUNT; i++) {
        this.datasets[i] = createDataset(i);
        this.charts[i] = createChart(i, this.datasets[i]);
        XYPlot plot = this.charts[i].getXYPlot();
        XYShapeAnnotation a1 = new XYShapeAnnotation(new Rectangle2D.Double(1.0, 2.0, 2.0, 3.0),
                new BasicStroke(1.0f), Color.blue);
        XYLineAnnotation a2 = new XYLineAnnotation(0.0, -5.0, 10.0, -5.0);

        plot.addAnnotation(a1);
        plot.addAnnotation(a2);
        plot.addDomainMarker(new IntervalMarker(5.0, 10.0), Layer.BACKGROUND);
        plot.addRangeMarker(new IntervalMarker(-2.0, 0.0), Layer.BACKGROUND);

        this.panels[i] = new ChartPanel(this.charts[i]);
    }
    this.charts[1].getXYPlot().getDomainAxis().setInverted(true);
    this.charts[2].getXYPlot().getRangeAxis().setInverted(true);
    this.charts[3].getXYPlot().getDomainAxis().setInverted(true);
    this.charts[3].getXYPlot().getRangeAxis().setInverted(true);

    this.charts[5].getXYPlot().getDomainAxis().setInverted(true);
    this.charts[6].getXYPlot().getRangeAxis().setInverted(true);
    this.charts[4].getXYPlot().getDomainAxis().setInverted(true);
    this.charts[4].getXYPlot().getRangeAxis().setInverted(true);

    this.charts[4].getXYPlot().setOrientation(PlotOrientation.HORIZONTAL);
    this.charts[5].getXYPlot().setOrientation(PlotOrientation.HORIZONTAL);
    this.charts[6].getXYPlot().setOrientation(PlotOrientation.HORIZONTAL);
    this.charts[7].getXYPlot().setOrientation(PlotOrientation.HORIZONTAL);

    panel.add(this.panels[0]);
    panel.add(this.panels[1]);
    panel.add(this.panels[4]);
    panel.add(this.panels[5]);
    panel.add(this.panels[2]);
    panel.add(this.panels[3]);
    panel.add(this.panels[6]);
    panel.add(this.panels[7]);

    panel.setPreferredSize(new Dimension(800, 600));
    setContentPane(panel);

}

From source file:inflor.core.gates.ui.PolygonGateAdapter.java

@Override
public void mouseMoved(MouseEvent e) {
    if (anchorSegment != null) {
        panel.removeTemporaryAnnotation(anchorSegment);
    }// ww  w. java2 s .  c  om
    if (anchorPoint != null) {
        Point2D p = ChartUtils.getPlotCoordinates(e, panel);
        anchorSegment = new XYLineAnnotation(anchorPoint.getX(), anchorPoint.getY(), p.getX(), p.getY());
        panel.addTemporaryAnnotation(anchorSegment);
    }
}

From source file:inflor.core.gates.ui.PolygonGateAdapter.java

private void updateTemporaryAnnotation() {
    Point2D previousVertex = null;
    if (segments != null) {
        segments.stream().forEach(panel::removeTemporaryAnnotation);
    }//from   w w w . jav a2s.c om
    segments = new ArrayList<>();
    for (Point2D v : vertices) {
        if (previousVertex == null) {
            previousVertex = v;
        } else {
            segments.add(
                    new XYLineAnnotation(previousVertex.getX(), previousVertex.getY(), v.getX(), v.getY()));
            previousVertex = v;
        }
    }
    segments.stream().forEach(panel::addTemporaryAnnotation);
}

From source file:org.openscience.cdk.applications.taverna.basicutilities.ChartTool.java

/**
 * Creates a scatter plot./*from  w  w w.j ava2  s . co m*/
 * 
 * @param dataset
 * @param header
 * @param xAxis
 * @param yAxis
 * @return
 */
public JFreeChart createScatterPlot(XYDataset dataset, String header, String xAxis, String yAxis) {
    JFreeChart chart = ChartFactory.createScatterPlot(header, xAxis, yAxis, dataset, PlotOrientation.VERTICAL,
            true, false, false);

    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setNoDataMessage("NO DATA");
    plot.setDomainZeroBaselineVisible(true);
    plot.setRangeZeroBaselineVisible(true);
    XYLineAnnotation annotation = new XYLineAnnotation(-1000000, -1000000, 1000000, 1000000);
    plot.addAnnotation(annotation);
    XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer();
    renderer.setSeriesOutlinePaint(0, Color.black);
    renderer.setUseOutlinePaint(true);
    NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
    domainAxis.setAutoRangeIncludesZero(false);
    domainAxis.setTickMarkInsideLength(2.0f);
    domainAxis.setTickMarkOutsideLength(0.0f);

    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setTickMarkInsideLength(2.0f);
    rangeAxis.setTickMarkOutsideLength(0.0f);

    return chart;
}

From source file:org.matsim.contrib.analysis.vsp.traveltimedistance.TravelTimeValidationRunner.java

private void writeTravelTimeValidation(String folder, List<CarTrip> trips) {
    BufferedWriter bw = IOUtils.getBufferedWriter(folder + "/validated_trips.csv");
    XYSeriesCollection times = new XYSeriesCollection();
    XYSeriesCollection distances = new XYSeriesCollection();

    XYSeries distancess = new XYSeries("distances", true, true);
    XYSeries timess = new XYSeries("times", true, true);
    times.addSeries(timess);/*from ww  w.j  a v  a  2 s  .  com*/
    distances.addSeries(distancess);
    try {
        bw.append(
                "agent;departureTime;fromX;fromY;toX;toY;traveltimeActual;traveltimeValidated;traveledDistance;validatedDistance");
        for (CarTrip trip : trips) {
            if (trip.getValidatedTravelTime() != null) {
                bw.newLine();
                bw.append(trip.toString());
                timess.add(trip.getActualTravelTime(), trip.getValidatedTravelTime());
                distancess.add(trip.getTravelledDistance(), trip.getValidatedTravelDistance());
            }
        }

        bw.flush();
        bw.close();
        final JFreeChart chart2 = ChartFactory.createScatterPlot("Travel Times", "Simulated travel time [s]",
                "Validated travel time [s]", times);
        final JFreeChart chart = ChartFactory.createScatterPlot("Travel Distances",
                "Simulated travel distance [m]", "Validated travel distance [m]", distances);

        NumberAxis yAxis = (NumberAxis) ((XYPlot) chart2.getPlot()).getRangeAxis();
        NumberAxis xAxis = (NumberAxis) ((XYPlot) chart2.getPlot()).getDomainAxis();
        NumberAxis yAxisd = (NumberAxis) ((XYPlot) chart.getPlot()).getRangeAxis();
        NumberAxis xAxisd = (NumberAxis) ((XYPlot) chart.getPlot()).getDomainAxis();
        yAxisd.setUpperBound(xAxisd.getUpperBound());
        yAxis.setUpperBound(xAxis.getUpperBound());
        yAxis.setTickUnit(new NumberTickUnit(500));
        xAxis.setTickUnit(new NumberTickUnit(500));

        XYAnnotation diagonal = new XYLineAnnotation(xAxis.getRange().getLowerBound(),
                yAxis.getRange().getLowerBound(), xAxis.getRange().getUpperBound(),
                yAxis.getRange().getUpperBound());
        ((XYPlot) chart2.getPlot()).addAnnotation(diagonal);

        XYAnnotation diagonald = new XYLineAnnotation(xAxisd.getRange().getLowerBound(),
                yAxisd.getRange().getLowerBound(), xAxisd.getRange().getUpperBound(),
                yAxisd.getRange().getUpperBound());
        ((XYPlot) chart.getPlot()).addAnnotation(diagonald);

        ChartUtilities.writeChartAsPNG(new FileOutputStream(folder + "/validated_traveltimes" + ".png"), chart2,
                1500, 1500);
        ChartUtilities.writeChartAsPNG(new FileOutputStream(folder + "/validated_traveldistances.png"), chart,
                1500, 1500);
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

}

From source file:my.electrochem.ElectrochemUI.java

private void createLineAnn(XYPlot plot, double a1, double b1, double a2, double b2) {
    if (!(a1 == 0.0)) {
        XYLineAnnotation ann1 = new XYLineAnnotation(a1, b1, a2, b2);
        plot.addAnnotation(ann1);/*w w  w  . j  a v  a 2  s  .c  om*/
        x1 = -423.0;
    }
}

From source file:org.esa.beam.timeseries.ui.graph.TimeSeriesGraphModel.java

void updateAnnotation(RasterDataNode raster) {
    removeAnnotation();//from ww w . j  a v a 2s.com

    final AbstractTimeSeries timeSeries = getTimeSeries();
    TimeCoding timeCoding = timeSeries.getRasterTimeMap().get(raster);
    if (timeCoding != null) {
        final ProductData.UTC startTime = timeCoding.getStartTime();
        final Millisecond timePeriod = new Millisecond(startTime.getAsDate(), ProductData.UTC.UTC_TIME_ZONE,
                Locale.getDefault());

        double millisecond = timePeriod.getFirstMillisecond();
        Range valueRange = null;
        for (int i = 0; i < timeSeriesPlot.getRangeAxisCount(); i++) {
            valueRange = Range.combine(valueRange, timeSeriesPlot.getRangeAxis(i).getRange());
        }
        if (valueRange != null) {
            XYAnnotation annotation = new XYLineAnnotation(millisecond, valueRange.getLowerBound(), millisecond,
                    valueRange.getUpperBound());
            timeSeriesPlot.addAnnotation(annotation, true);
        }
    }
}