Example usage for org.jfree.chart.renderer.xy XYLineAndShapeRenderer addAnnotation

List of usage examples for org.jfree.chart.renderer.xy XYLineAndShapeRenderer addAnnotation

Introduction

In this page you can find the example usage for org.jfree.chart.renderer.xy XYLineAndShapeRenderer addAnnotation.

Prototype

@Override
public void addAnnotation(XYAnnotation annotation) 

Source Link

Document

Adds an annotation and sends a RendererChangeEvent to all registered listeners.

Usage

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

private static JFreeChart createChart() {
    XYDataset xydataset = createDataset1();
    JFreeChart jfreechart = ChartFactory.createXYLineChart("Annotation Demo 2", "Date", "Price Per Unit",
            xydataset, PlotOrientation.VERTICAL, false, true, false);
    XYPlot xyplot = (XYPlot) jfreechart.getPlot();
    NumberAxis numberaxis = (NumberAxis) xyplot.getRangeAxis();
    numberaxis.setAutoRangeIncludesZero(false);
    NumberAxis numberaxis1 = new NumberAxis("Secondary");
    numberaxis1.setAutoRangeIncludesZero(false);
    xyplot.setRangeAxis(1, numberaxis1);
    xyplot.setDataset(1, createDataset2());
    xyplot.mapDatasetToRangeAxis(1, 1);//from w  ww  . ja  va 2  s.com
    XYLineAndShapeRenderer xylineandshaperenderer = (XYLineAndShapeRenderer) xyplot.getRenderer();
    xylineandshaperenderer.setBaseToolTipGenerator(StandardXYToolTipGenerator.getTimeSeriesInstance());
    xylineandshaperenderer.setBaseShapesVisible(true);
    xylineandshaperenderer.setBaseShapesFilled(true);
    XYPointerAnnotation xypointerannotation = new XYPointerAnnotation("Annotation 1 (2.0, 167.3)", 2D,
            167.30000000000001D, -0.78539816339744828D);
    xypointerannotation.setTextAnchor(TextAnchor.BOTTOM_LEFT);
    xypointerannotation.setPaint(Color.red);
    xypointerannotation.setArrowPaint(Color.red);
    xylineandshaperenderer.addAnnotation(xypointerannotation);
    XYLineAndShapeRenderer xylineandshaperenderer1 = new XYLineAndShapeRenderer(true, true);
    xylineandshaperenderer1.setSeriesPaint(0, Color.black);
    xylineandshaperenderer.setBaseToolTipGenerator(StandardXYToolTipGenerator.getTimeSeriesInstance());
    XYPointerAnnotation xypointerannotation1 = new XYPointerAnnotation("Annotation 2 (15.0, 613.2)", 15D,
            613.20000000000005D, 1.5707963267948966D);
    xypointerannotation1.setTextAnchor(TextAnchor.TOP_CENTER);
    xylineandshaperenderer1.addAnnotation(xypointerannotation1);
    xyplot.setRenderer(1, xylineandshaperenderer1);
    LegendTitle legendtitle = new LegendTitle(xylineandshaperenderer);
    LegendTitle legendtitle1 = new LegendTitle(xylineandshaperenderer1);
    BlockContainer blockcontainer = new BlockContainer(new BorderArrangement());
    blockcontainer.add(legendtitle, RectangleEdge.LEFT);
    blockcontainer.add(legendtitle1, RectangleEdge.RIGHT);
    blockcontainer.add(new EmptyBlock(2000D, 0.0D));
    CompositeTitle compositetitle = new CompositeTitle(blockcontainer);
    compositetitle.setPosition(RectangleEdge.BOTTOM);
    jfreechart.addSubtitle(compositetitle);
    return jfreechart;
}

From source file:org.jfree.graphics2d.demo.SVGChartWithAnnotationsDemo1.java

/**
 * Creates a sample chart./*from   ww w .  ja  va  2s . c  o m*/
 *
 * @param dataset  a dataset for the chart.
 *
 * @return A sample chart.
 */
private static JFreeChart createChart(XYDataset dataset) {
    JFreeChart chart = ChartFactory.createTimeSeriesChart("XYDrawableAnnotationDemo1", null, "$ million",
            dataset);
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setDomainPannable(true);
    plot.setRangePannable(true);
    DateAxis xAxis = (DateAxis) plot.getDomainAxis();
    xAxis.setLowerMargin(0.2);
    xAxis.setUpperMargin(0.2);
    xAxis.setStandardTickUnits(createStandardDateTickUnits());

    NumberAxis yAxis = (NumberAxis) plot.getRangeAxis();
    yAxis.setLowerMargin(0.2);
    yAxis.setUpperMargin(0.2);

    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    renderer.setBaseShapesVisible(true);
    renderer.setBaseLinesVisible(true);
    renderer.setSeriesShape(0, new Ellipse2D.Double(-5.0, -5.0, 10.0, 10.0));
    renderer.setSeriesShape(1, new Ellipse2D.Double(-5.0, -5.0, 10.0, 10.0));
    renderer.setSeriesStroke(0, new BasicStroke(3.0f));
    renderer.setSeriesStroke(1, new BasicStroke(3.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 5.0f,
            new float[] { 10.0f, 5.0f }, 0.0f));
    renderer.setSeriesFillPaint(0, Color.white);
    renderer.setSeriesFillPaint(1, Color.white);
    renderer.setUseFillPaint(true);

    renderer.setDefaultToolTipGenerator(new StandardXYToolTipGenerator());
    renderer.setDefaultEntityRadius(6);

    renderer.addAnnotation(new XYDrawableAnnotation(new Month(4, 2005).getFirstMillisecond(), 600, 180, 100,
            3.0, createPieChart()));
    renderer.addAnnotation(new XYDrawableAnnotation(new Month(9, 2007).getFirstMillisecond(), 1250, 120, 100,
            2.0, createBarChart()));
    plot.setRenderer(renderer);
    return chart;
}

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

private static JFreeChart createChart(XYDataset xydataset) {
    JFreeChart jfreechart = ChartFactory.createTimeSeriesChart("XYDrawableAnnotationDemo1", null, "$ million",
            xydataset, true, true, false);
    XYPlot xyplot = (XYPlot) jfreechart.getPlot();
    xyplot.setDomainPannable(true);//w  ww.  j a va 2s. c  om
    xyplot.setRangePannable(true);
    DateAxis dateaxis = (DateAxis) xyplot.getDomainAxis();
    dateaxis.setLowerMargin(0.20000000000000001D);
    dateaxis.setUpperMargin(0.20000000000000001D);
    dateaxis.setStandardTickUnits(createStandardDateTickUnits());
    NumberAxis numberaxis = (NumberAxis) xyplot.getRangeAxis();
    numberaxis.setLowerMargin(0.20000000000000001D);
    numberaxis.setUpperMargin(0.20000000000000001D);
    XYLineAndShapeRenderer xylineandshaperenderer = new XYLineAndShapeRenderer();
    xylineandshaperenderer.setBaseShapesVisible(true);
    xylineandshaperenderer.setBaseLinesVisible(true);
    xylineandshaperenderer.setSeriesShape(0, new java.awt.geom.Ellipse2D.Double(-5D, -5D, 10D, 10D));
    xylineandshaperenderer.setSeriesShape(1, new java.awt.geom.Ellipse2D.Double(-5D, -5D, 10D, 10D));
    xylineandshaperenderer.setSeriesStroke(0, new BasicStroke(3F));
    xylineandshaperenderer.setSeriesStroke(1, new BasicStroke(3F, 1, 1, 5F, new float[] { 10F, 5F }, 0.0F));
    xylineandshaperenderer.setSeriesFillPaint(0, Color.white);
    xylineandshaperenderer.setSeriesFillPaint(1, Color.white);
    xylineandshaperenderer.setUseFillPaint(true);
    xylineandshaperenderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator());
    xylineandshaperenderer.setDefaultEntityRadius(6);
    xylineandshaperenderer.addAnnotation(new XYDrawableAnnotation((new Month(4, 2005)).getFirstMillisecond(),
            600D, 180D, 100D, 3D, createPieChart()));
    xylineandshaperenderer.addAnnotation(new XYDrawableAnnotation((new Month(9, 2007)).getFirstMillisecond(),
            1250D, 120D, 100D, 2D, createBarChart()));
    xyplot.setRenderer(xylineandshaperenderer);
    return jfreechart;
}

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

private static JFreeChart createChart(XYDataset xydataset) {
    JFreeChart jfreechart = ChartFactory.createTimeSeriesChart("Breakdowns", "Production Date",
            "Hours of Operation", xydataset, true, true, false);
    jfreechart.setBackgroundPaint(Color.white);
    XYPlot xyplot = (XYPlot) jfreechart.getPlot();
    XYLineAndShapeRenderer xylineandshaperenderer = (XYLineAndShapeRenderer) xyplot.getRenderer();
    xylineandshaperenderer.setSeriesShape(0, new Rectangle(2, 2));
    xylineandshaperenderer.setSeriesShape(1, new Rectangle(2, 2));
    xylineandshaperenderer.setBaseLinesVisible(false);
    xylineandshaperenderer.setBaseShapesFilled(true);
    xylineandshaperenderer.setBaseShapesVisible(true);
    xylineandshaperenderer.setBaseToolTipGenerator(null);
    xylineandshaperenderer.setSeriesPaint(0, Color.blue);
    xylineandshaperenderer.setSeriesPaint(1, Color.red);
    xyplot.setDomainGridlineStroke(new BasicStroke(1.0F));
    xyplot.setRangeGridlineStroke(new BasicStroke(1.0F));
    NumberAxis numberaxis = (NumberAxis) xyplot.getRangeAxis();
    numberaxis.setTickUnit(new NumberTickUnit(50000D));
    DateAxis dateaxis = (DateAxis) xyplot.getDomainAxis();
    dateaxis.setTickUnit(new DateTickUnit(DateTickUnitType.MONTH, 1));
    dateaxis.setDateFormatOverride(new SimpleDateFormat("MMM.yy"));
    dateaxis.setVerticalTickLabels(true);
    Color color = new Color(255, 0, 0, 60);
    Color color1 = new Color(0, 255, 0, 60);
    XYBoxAnnotation xyboxannotation = new XYBoxAnnotation((new Day(1, 1, 2004)).getMiddleMillisecond(), 0.0D,
            (new Day(31, 1, 2004)).getMiddleMillisecond(), 50000D, new BasicStroke(0.0F), color, color);
    xyboxannotation.setToolTipText("Value: 2.9");
    xylineandshaperenderer.addAnnotation(xyboxannotation);
    xyboxannotation = new XYBoxAnnotation((new Day(1, 2, 2004)).getMiddleMillisecond(), 0.0D,
            (new Day(29, 2, 2004)).getMiddleMillisecond(), 50000D, new BasicStroke(0.0F), color, color);
    xyboxannotation.setToolTipText("Value: 2.5");
    xylineandshaperenderer.addAnnotation(xyboxannotation);
    xyboxannotation = new XYBoxAnnotation((new Day(1, 5, 2004)).getMiddleMillisecond(), 50000D,
            (new Day(31, 5, 2004)).getMiddleMillisecond(), 100000D, new BasicStroke(0.0F), color, color);
    xyboxannotation.setToolTipText("Value: 1.8");
    xylineandshaperenderer.addAnnotation(xyboxannotation);
    xyboxannotation = new XYBoxAnnotation((new Day(1, 6, 2005)).getMiddleMillisecond(), 0.0D,
            (new Day(30, 6, 2005)).getMiddleMillisecond(), 50000D, new BasicStroke(0.0F), color1, color1);
    xyboxannotation.setToolTipText("Value: 3.7");
    xylineandshaperenderer.addAnnotation(xyboxannotation);
    return jfreechart;
}