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

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

Introduction

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

Prototype

public XYPolygonAnnotation(double[] polygon, Stroke stroke, Paint outlinePaint, Paint fillPaint) 

Source Link

Document

Creates a new annotation.

Usage

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

private static JFreeChart createChart(XYDataset xydataset) {
    JFreeChart jfreechart = ChartFactory.createScatterPlot("XYPolygonAnnotationDemo1", "X", "Y", xydataset,
            PlotOrientation.VERTICAL, true, true, false);
    jfreechart.setBackgroundPaint(Color.white);
    XYPlot xyplot = (XYPlot) jfreechart.getPlot();
    xyplot.setBackgroundPaint(Color.lightGray);
    xyplot.setDomainGridlinePaint(Color.white);
    xyplot.setRangeGridlinePaint(Color.white);
    XYLineAndShapeRenderer xylineandshaperenderer = (XYLineAndShapeRenderer) xyplot.getRenderer();
    XYPolygonAnnotation xypolygonannotation = new XYPolygonAnnotation(
            new double[] { 2D, 5D, 2.5D, 8D, 3D, 5D, 2.5D, 2D }, null, null, new Color(200, 200, 255, 100));
    xypolygonannotation.setToolTipText("Target Zone");
    xylineandshaperenderer.addAnnotation(xypolygonannotation, Layer.BACKGROUND);
    return jfreechart;
}

From source file:com.juanhg.triangle.TriangleApplet.java

public void updateTriangle(double z) {
    double[] polygon = new double[6];
    polygon[1] = polygon[0] = polygon[3] = polygon[4] = 0;
    polygon[2] = model.getA(z);/*from  w  ww  .ja  v  a 2  s  .com*/
    polygon[5] = model.getB(z);
    yPulley = polygon[5] + 1;
    double yIncrement = normalize(60 - z, 0, 40, 0, 0.3);
    double xIncrement = normalize(z, 20, 60, 0, 0.09);
    oYBox = yBox = model.getB(z) + yIncrement;
    oXBox = xBox + xIncrement;

    chartTriangle.deleteAnnotation(ropeAnnotation);
    ropeAnnotation = chartTriangle.drawLine(xPulley, yPulley + 0.5, xBox, yBox, new BasicStroke(4f),
            Color.BLACK);

    chartTriangle.deleteAnnotation(baseAnnotation);
    baseAnnotation = chartTriangle.setImageAtPoint(baseImage, xBase, polygon[5] - 0.1);

    chartTriangle.deleteAnnotation(pulleyAnnotation);
    pulleyAnnotation = chartTriangle.setImageAtPoint(pulleyImage(), xPulley, yPulley);

    chartTriangle.deleteAnnotation(triangleAnnotation);
    triangleAnnotation = new XYPolygonAnnotation(polygon, new BasicStroke(2f), Color.BLACK, Color.gray);
    chartTriangle.setAnnotation(triangleAnnotation);

    boxImage = ImageProcessing.rotateDegrees(oBoxImage, -z);
    chartTriangle.deleteAnnotation(boxAnnotation);
    boxAnnotation = chartTriangle.setImageAtPoint(boxImage, xBox + xIncrement, yBox);

    updatePanels();
    repaint();
}

From source file:com.mgmtp.perfload.loadprofiles.ui.AppFrame.java

private void updateGraph() {
    XYSeriesCollection dataset = new XYSeriesCollection();
    Collection<Stairs> loadProfileEnities = transform(
            filter(loadProfilesController.getTreeItems(), new IsStairsPredicate()),
            new LoadProfileEntityToStairsFunction());
    GraphPointsCalculator calc = new GraphPointsCalculator();
    Map<String, Set<Point>> pointsMap = calc.calculatePoints(loadProfileEnities);

    for (Entry<String, Set<Point>> entry : pointsMap.entrySet()) {
        final XYSeries series = new XYSeries(entry.getKey());
        for (Point point : entry.getValue()) {
            series.add(point.getX(), point.getY());
        }//from  w  ww .j  av  a2 s  . c  o m
        dataset.addSeries(series);
    }

    String name = txtName.getText();
    chart = ChartFactory.createXYLineChart(name, "t (min)", "Executions (1/h)", dataset,
            PlotOrientation.VERTICAL, true, true, false);

    XYPlot plot = chart.getXYPlot();

    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    plot.setRenderer(renderer);

    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
    domainAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    double maxX = 0;

    for (OneTime oneTime : getOneTimes()) {
        String key = oneTime.operation.getName();
        XYSeries series;
        try {
            // We need the series in order to retrieve paint and stroke
            series = dataset.getSeries(key);
        } catch (UnknownKeyException ex) {
            series = new XYSeries(key);
            dataset.addSeries(series);
        }

        int index = dataset.getSeriesIndex(key);
        BasicStroke stroke = (BasicStroke) renderer.lookupSeriesStroke(index);
        stroke = new BasicStroke(stroke.getLineWidth() + 1f, stroke.getEndCap(), stroke.getLineJoin(),
                stroke.getMiterLimit(), stroke.getDashArray(), stroke.getDashPhase());
        Color paint = (Color) renderer.lookupSeriesPaint(index);
        paint = new Color(paint.getRed(), paint.getGreen(), paint.getBlue(), 160);

        double height = rangeAxis.getUpperBound() * .05; // five percent of range
        double width = domainAxis.getUpperBound() * .01; // one percent of range
        double center = oneTime.t0;
        double left = center - width / 2;
        double right = center + width / 2;

        // We only add annotations for one times, but nothing to the series
        plot.addAnnotation(new XYPolygonAnnotation(new double[] { left, 0d, center, height, right, 0d }, stroke,
                paint, paint));

        maxX = max(maxX, right);
    }

    for (Marker marker : getMarkers()) {
        IntervalMarker im = new IntervalMarker(marker.left, marker.right);
        im.setLabel(marker.name);
        im.setLabelFont(new Font(getFont().getName(), getFont().getStyle(), getFont().getSize() + 1));
        im.setLabelAnchor(RectangleAnchor.TOP);
        im.setLabelOffset(new RectangleInsets(8d, 0d, 0d, 0d));
        im.setLabelPaint(Color.BLACK);
        im.setAlpha(.3f);
        im.setPaint(Color.WHITE);
        im.setOutlinePaint(Color.BLACK);
        im.setOutlineStroke(new BasicStroke(1.0f));
        plot.addDomainMarker(im, Layer.BACKGROUND);

        maxX = max(maxX, marker.right);
    }

    if (domainAxis.getUpperBound() < maxX) {
        domainAxis.setUpperBound(maxX * 1.05);
    }
    chartPanel.setChart(chart);
}