Example usage for org.jfree.chart.annotations XYTextAnnotation setFont

List of usage examples for org.jfree.chart.annotations XYTextAnnotation setFont

Introduction

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

Prototype

public void setFont(Font font) 

Source Link

Document

Sets the font for the annotation and sends an AnnotationChangeEvent to all registered listeners.

Usage

From source file:no.met.jtimeseries.chart.ErrorPlot.java

public static XYPlot getMarinogramErrorPlot() {
    XYItemRenderer renderer = new StandardXYItemRenderer();
    NumberAxis rangeAxis = new NumberAxis();
    XYPlot plot = new XYPlot(null, null, rangeAxis, renderer);
    XYTextAnnotation annotation = new XYTextAnnotation("Hello!", 0.5, 0.5);
    annotation.setFont(new Font("SansSerif", Font.PLAIN, 9));
    plot.addAnnotation(annotation);//from   ww w  .  j ava  2 s  .  com
    return plot;
}

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

private static JFreeChart createChart(XYDataset xydataset) {
    JFreeChart jfreechart = ChartFactory.createXYLineChart(null, "Age in Months", "Weight (kg)", xydataset,
            PlotOrientation.VERTICAL, true, true, false);
    TextTitle texttitle = new TextTitle("Growth Charts: United States", new Font("SansSerif", 1, 14));
    TextTitle texttitle1 = new TextTitle("Weight-for-age percentiles: boys, birth to 36 months",
            new Font("SansSerif", 0, 11));
    jfreechart.addSubtitle(texttitle);/*from w  ww .ja v  a 2 s .  c om*/
    jfreechart.addSubtitle(texttitle1);
    XYPlot xyplot = (XYPlot) jfreechart.getPlot();
    NumberAxis numberaxis = (NumberAxis) xyplot.getDomainAxis();
    numberaxis.setUpperMargin(0.12D);
    numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    NumberAxis numberaxis1 = (NumberAxis) xyplot.getRangeAxis();
    numberaxis1.setAutoRangeIncludesZero(false);
    XYTextAnnotation xytextannotation = null;
    Font font = new Font("SansSerif", 0, 9);
    xytextannotation = new XYTextAnnotation("3rd", 36.5D, 11.76D);
    xytextannotation.setFont(font);
    xytextannotation.setTextAnchor(TextAnchor.HALF_ASCENT_LEFT);
    xyplot.addAnnotation(xytextannotation);
    xytextannotation = new XYTextAnnotation("5th", 36.5D, 12.039999999999999D);
    xytextannotation.setFont(font);
    xytextannotation.setTextAnchor(TextAnchor.HALF_ASCENT_LEFT);
    xyplot.addAnnotation(xytextannotation);
    xytextannotation = new XYTextAnnotation("10th", 36.5D, 12.493D);
    xytextannotation.setFont(font);
    xytextannotation.setTextAnchor(TextAnchor.HALF_ASCENT_LEFT);
    xyplot.addAnnotation(xytextannotation);
    xytextannotation = new XYTextAnnotation("25th", 36.5D, 13.313000000000001D);
    xytextannotation.setFont(font);
    xytextannotation.setTextAnchor(TextAnchor.HALF_ASCENT_LEFT);
    xyplot.addAnnotation(xytextannotation);
    xytextannotation = new XYTextAnnotation("50th", 36.5D, 14.33D);
    xytextannotation.setFont(font);
    xytextannotation.setTextAnchor(TextAnchor.HALF_ASCENT_LEFT);
    xyplot.addAnnotation(xytextannotation);
    xytextannotation = new XYTextAnnotation("75th", 36.5D, 15.478D);
    xytextannotation.setFont(font);
    xytextannotation.setTextAnchor(TextAnchor.HALF_ASCENT_LEFT);
    xyplot.addAnnotation(xytextannotation);
    xytextannotation = new XYTextAnnotation("90th", 36.5D, 16.641999999999999D);
    xytextannotation.setFont(font);
    xytextannotation.setTextAnchor(TextAnchor.HALF_ASCENT_LEFT);
    xyplot.addAnnotation(xytextannotation);
    xytextannotation = new XYTextAnnotation("95th", 36.5D, 17.408000000000001D);
    xytextannotation.setFont(font);
    xytextannotation.setTextAnchor(TextAnchor.HALF_ASCENT_LEFT);
    xyplot.addAnnotation(xytextannotation);
    xytextannotation = new XYTextAnnotation("97th", 36.5D, 17.936D);
    xytextannotation.setFont(font);
    xytextannotation.setTextAnchor(TextAnchor.HALF_ASCENT_LEFT);
    xyplot.addAnnotation(xytextannotation);
    return jfreechart;
}

From source file:com.che.software.testato.util.jfreechart.LineChartGraphistUtil.java

/**
 * Colorized and transforms a given JFreeChart.
 * /*from ww w .j  a v  a 2 s. c om*/
 * @author Clement HELIOU (clement.heliou@che-software.com).
 * @param lineChart the given chart.
 * @param maxAbscissaValue the max abscissa value of the chart.
 * @param xValues the x axis values list.
 * @param yValues the y axis values list.
 * @param xExcludedValues the x axis excluded values.
 * @param yExcludedValues the y axis excluded values.
 * @return the transformed chart.
 * @since August, 2011.
 */
public static JFreeChart getColorizedChartFromChart(JFreeChart lineChart, double maxAbscissaValue,
        List<MatrixResult> xValues, List<MatrixResult> yValues, List<MatrixResult> xExcludedValues,
        List<MatrixResult> yExcludedValues) {
    LOGGER.debug("getColorizedChartFromChart().");
    lineChart.setBackgroundPaint(Color.WHITE);
    XYPlot plot = (XYPlot) lineChart.getPlot();
    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    renderer.setSeriesLinesVisible(0, false);
    renderer.setSeriesLinesVisible(1, false);
    renderer.setSeriesStroke(2, new BasicStroke(2));
    renderer.setSeriesStroke(3, new BasicStroke(2));
    renderer.setSeriesShapesVisible(2, false);
    renderer.setSeriesShapesVisible(3, false);
    renderer.setSeriesPaint(0,
            ColorUtil.getHSBColor(ColorUtil.BLUE_COLOR[0], ColorUtil.BLUE_COLOR[1], ColorUtil.BLUE_COLOR[2]));
    renderer.setSeriesPaint(1, ColorUtil.getHSBColor(ColorUtil.ORANGE_COLOR[0], ColorUtil.ORANGE_COLOR[1],
            ColorUtil.ORANGE_COLOR[2]));
    renderer.setSeriesPaint(2, ColorUtil.getHSBColor(ColorUtil.DARK_BLUE_COLOR[0], ColorUtil.DARK_BLUE_COLOR[1],
            ColorUtil.DARK_BLUE_COLOR[2]));
    renderer.setSeriesPaint(3, ColorUtil.getHSBColor(ColorUtil.DARK_BLUE_COLOR[0], ColorUtil.DARK_BLUE_COLOR[1],
            ColorUtil.DARK_BLUE_COLOR[2]));
    plot.setRenderer(renderer);
    XYTextAnnotation low = new XYTextAnnotation(
            LocaleUtil.getResourceBundleStringByName(LocaleUtil.AREA_LOW_NAME), (0.5 * maxAbscissaValue) - 1,
            maxAbscissaValue + 1),
            medium = new XYTextAnnotation(LocaleUtil.getResourceBundleStringByName(LocaleUtil.AREA_MEDIUM_NAME),
                    (1.5 * maxAbscissaValue) - 2, maxAbscissaValue + 1),
            high = new XYTextAnnotation(LocaleUtil.getResourceBundleStringByName(LocaleUtil.AREA_HIGH_NAME),
                    1.5 * maxAbscissaValue, maxAbscissaValue - 2);
    low.setFont(ColorUtil.TITLE_FONT);
    medium.setFont(ColorUtil.TITLE_FONT);
    high.setFont(ColorUtil.TITLE_FONT);
    low.setPaint(ColorUtil.getHSBColor(ColorUtil.DARK_BLUE_COLOR[0], ColorUtil.DARK_BLUE_COLOR[1],
            ColorUtil.DARK_BLUE_COLOR[2]));
    medium.setPaint(ColorUtil.getHSBColor(ColorUtil.DARK_BLUE_COLOR[0], ColorUtil.DARK_BLUE_COLOR[1],
            ColorUtil.DARK_BLUE_COLOR[2]));
    high.setPaint(ColorUtil.getHSBColor(ColorUtil.DARK_BLUE_COLOR[0], ColorUtil.DARK_BLUE_COLOR[1],
            ColorUtil.DARK_BLUE_COLOR[2]));
    plot.addAnnotation(low);
    plot.addAnnotation(medium);
    plot.addAnnotation(high);
    for (int i = 0; i < xValues.size(); i++) {
        XYTextAnnotation itemLabel = new XYTextAnnotation(xValues.get(i).getScriptLabel(),
                (yValues.get(i).getPercentage() * 100), (xValues.get(i).getPercentage() * 100) + 0.5);
        itemLabel.setFont(ColorUtil.DEFAULT_FONT);
        itemLabel.setPaint(ColorUtil.getHSBColor(ColorUtil.BLUE_COLOR[0], ColorUtil.BLUE_COLOR[1],
                ColorUtil.BLUE_COLOR[2]));
        plot.addAnnotation(itemLabel);
    }
    if (null != xExcludedValues) {
        for (int j = 0; j < xExcludedValues.size(); j++) {
            XYTextAnnotation itemLabel = new XYTextAnnotation(xExcludedValues.get(j).getScriptLabel(),
                    (yExcludedValues.get(j).getPercentage() * 100),
                    (xExcludedValues.get(j).getPercentage() * 100) + 0.5);
            itemLabel.setFont(ColorUtil.DEFAULT_FONT);
            itemLabel.setPaint(ColorUtil.getHSBColor(ColorUtil.ORANGE_COLOR[0], ColorUtil.ORANGE_COLOR[1],
                    ColorUtil.ORANGE_COLOR[2]));
            plot.addAnnotation(itemLabel);
        }
    }
    return lineChart;
}

From source file:utils.ChartUtils.java

/**
 * Update XY chart/*from   w  w  w  .  j  a va  2 s  . c  o  m*/
 * 
 * @param plot ChartPanel Plot
 * @param sortedArray Sorted array of values
 */
public static void updateXYChart(ChartPanel plot, double[] sortedArray) {

    XYPlot xyplot = plot.getChart().getXYPlot();

    double min = sortedArray[0];
    double max = sortedArray[sortedArray.length - 1];

    double median = Utils.getMedian(sortedArray);

    double q1 = Utils.getQ1(sortedArray);
    double q3 = Utils.getQ3(sortedArray);

    XYTextAnnotation annotation;

    //min-lowlimit horizontal
    XYSeries serie15 = new XYSeries("15");
    serie15.add(min, 0.5);

    //max-toplimit horizontal
    XYSeries serie16 = new XYSeries("16");
    serie16.add(max, 0.5);

    //min vertical
    XYSeries serie1 = new XYSeries("0");
    serie1.add(min, 0.45);
    serie1.add(min, 0.55);

    annotation = new XYTextAnnotation("Min", min, 0.40);
    annotation.setFont(new Font("SansSerif", Font.PLAIN, 11));
    xyplot.addAnnotation(annotation);

    //min-q1 horizontal
    XYSeries serie2 = new XYSeries("1");
    serie2.add(min, 0.5);
    serie2.add(q1, 0.5);

    //q1 vertical  
    XYSeries serie3 = new XYSeries("2");
    serie3.add(q1, 0.1);
    serie3.add(q1, 0.9);

    annotation = new XYTextAnnotation("Q1", q1, 0.08);
    annotation.setFont(new Font("SansSerif", Font.PLAIN, 11));
    xyplot.addAnnotation(annotation);

    // median 
    XYSeries serie_mediana = new XYSeries("11");
    serie_mediana.add(median, 0.1);
    serie_mediana.add(median, 0.9);

    annotation = new XYTextAnnotation("Median", median, 0.04);
    annotation.setFont(new Font("SansSerif", Font.PLAIN, 11));
    xyplot.addAnnotation(annotation);

    //q1-q3 horizontal sup
    XYSeries serie4 = new XYSeries("3");
    serie4.add(q1, 0.9);
    serie4.add(q3, 0.9);

    //q1-q3 horizontal inf
    XYSeries serie5 = new XYSeries("4");
    serie5.add(q1, 0.1);
    serie5.add(q3, 0.1);

    //q3 vertical
    XYSeries serie6 = new XYSeries("5");
    serie6.add(q3, 0.1);
    serie6.add(q3, 0.9);

    annotation = new XYTextAnnotation("Q3", q3, 0.08);
    annotation.setFont(new Font("SansSerif", Font.PLAIN, 11));
    xyplot.addAnnotation(annotation);

    //q3-max horizontal
    XYSeries serie7 = new XYSeries("6");
    serie7.add(q3, 0.5);
    serie7.add(max, 0.5);

    //max vertical
    XYSeries serie8 = new XYSeries("7");
    serie8.add(max, 0.45);
    serie8.add(max, 0.55);

    annotation = new XYTextAnnotation("Max", max, 0.4);
    annotation.setFont(new Font("SansSerif", Font.PLAIN, 11));
    xyplot.addAnnotation(annotation);

    XYSeriesCollection xyseriescollection = new XYSeriesCollection();

    xyseriescollection.addSeries(serie1);
    xyseriescollection.addSeries(serie2);
    xyseriescollection.addSeries(serie3);
    xyseriescollection.addSeries(serie4);
    xyseriescollection.addSeries(serie5);
    xyseriescollection.addSeries(serie6);
    xyseriescollection.addSeries(serie7);
    xyseriescollection.addSeries(serie8);
    xyseriescollection.addSeries(serie15);
    xyseriescollection.addSeries(serie16);
    xyseriescollection.addSeries(serie_mediana);

    xyplot.getRenderer().setSeriesPaint(9, Color.black);
    xyplot.getRenderer().setSeriesPaint(10, Color.black);

    xyplot.getRenderer().setSeriesPaint(0, Color.black);
    xyplot.getRenderer().setSeriesPaint(1, Color.black);
    xyplot.getRenderer().setSeriesPaint(2, Color.black);
    xyplot.getRenderer().setSeriesPaint(3, Color.black);
    xyplot.getRenderer().setSeriesPaint(4, Color.black);
    xyplot.getRenderer().setSeriesPaint(5, Color.black);
    xyplot.getRenderer().setSeriesPaint(6, Color.black);
    xyplot.getRenderer().setSeriesPaint(7, Color.black);
    xyplot.getRenderer().setSeriesPaint(8, Color.black);
    xyplot.getRenderer().setSeriesPaint(9, Color.black);
    xyplot.getRenderer().setSeriesPaint(10, Color.black);
    xyplot.getRenderer().setSeriesPaint(11, Color.black);
    xyplot.getRenderer().setSeriesPaint(12, Color.black);
    xyplot.getRenderer().setSeriesPaint(13, Color.black);

    //add dataset
    xyplot.setDataset(xyseriescollection);

    // add a second dataset and renderer... 
    XYSeriesCollection anotherserie = new XYSeriesCollection();

    XYSeries serie_point = new XYSeries("21");

    double[] yValue = { 0.47, 0.49, 0.51, 0.53 };

    for (int i = 0, j = 0; i < sortedArray.length; i++, j++) {
        if (j % 4 == 0) {
            j = 0;
        }
        serie_point.add(sortedArray[i], yValue[j]);
    }

    anotherserie.addSeries(serie_point);

    XYLineAndShapeRenderer renderer1 = new XYLineAndShapeRenderer(false, true);
    renderer1.setSeriesPaint(0, Color.lightGray);

    xyplot.setDataset(1, anotherserie);
    xyplot.setRenderer(1, renderer1);
}

From source file:statUtil.TurnMovementPlot.java

public TurnMovementPlot(String title) throws IOException {
    super(title);
    Data data = CSVData.getCSVData(TURN_CSV_LOG);
    JFreeChart chart = ChartFactory.createXYLineChart(title, "X", "Y",
            XYDatasetGenerator.generateXYDataset(data.csvData));
    final XYPlot xyPlot = chart.getXYPlot();
    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    renderer.setSeriesStroke(0, new BasicStroke(3f));
    renderer.setSeriesLinesVisible(0, true);
    renderer.setSeriesShapesVisible(0, false);
    renderer.setSeriesLinesVisible(1, false);
    renderer.setSeriesShapesVisible(1, true);
    Shape cross = ShapeUtilities.createDiagonalCross(2f, 0.5f);
    renderer.setSeriesShape(1, cross);//from   w  w  w . j  a  v a  2 s.  c o  m
    xyPlot.setRenderer(renderer);
    xyPlot.setQuadrantOrigin(new Point(0, 0));

    int i = 0;
    for (Double[] csvRow : data.csvData) {
        if (i % 20 == 1) {
            final XYTextAnnotation annotation = new XYTextAnnotation(Double.toString(csvRow[3]), csvRow[0],
                    csvRow[1]);
            annotation.setFont(new Font("SansSerif", Font.PLAIN, 10));
            xyPlot.addAnnotation(annotation);
        }
        i++;
    }

    int width = (int) Math.round(data.maxX - data.minX) + 50;
    int height = (int) Math.round(data.maxY - data.minY) + 50;
    ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new Dimension(width, height));
    setContentPane(chartPanel);
    File XYChart = new File(FILE_PATH + "\\TurnMovementPlot.png");
    ChartUtilities.saveChartAsPNG(XYChart, chart, width, height);
}

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

/**
 * Creates an overlaid chart./*from ww w .ja  va2  s.  c  om*/
 *
 * @return The chart.
 */
private JFreeChart createOverlaidChart() {

    // create plot ...
    final IntervalXYDataset data1 = createDataset1();
    final XYItemRenderer renderer1 = new XYBarRenderer(0.20);
    renderer1.setToolTipGenerator(
            new StandardXYToolTipGenerator(StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT,
                    new SimpleDateFormat("d-MMM-yyyy"), new DecimalFormat("0.00")));
    final DateAxis domainAxis = new DateAxis("Date");
    domainAxis.setTickMarkPosition(DateTickMarkPosition.MIDDLE);
    final ValueAxis rangeAxis = new NumberAxis("Value");
    final XYPlot plot = new XYPlot(data1, domainAxis, rangeAxis, renderer1);
    final double x = new Day(9, SerialDate.MARCH, 2002).getMiddleMillisecond();
    final XYTextAnnotation annotation = new XYTextAnnotation("Hello!", x, 10000.0);
    annotation.setFont(new Font("SansSerif", Font.PLAIN, 9));
    plot.addAnnotation(annotation);

    // add a second dataset and renderer...
    final XYDataset data2 = createDataset2();
    final XYItemRenderer renderer2 = new StandardXYItemRenderer();
    renderer2.setToolTipGenerator(
            new StandardXYToolTipGenerator(StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT,
                    new SimpleDateFormat("d-MMM-yyyy"), new DecimalFormat("0.00")));
    plot.setDataset(1, data2);
    plot.setRenderer(1, renderer2);

    plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);

    // return a new chart containing the overlaid plot...
    return new JFreeChart("Overlaid Plot Example", JFreeChart.DEFAULT_TITLE_FONT, plot, true);

}

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

/**
 * Creates a combined chart./* ww  w .j av  a2s  .  c  om*/
 *
 * @return the combined chart.
 */
private JFreeChart createCombinedChart() {

    // create subplot 1...
    final XYDataset data1 = createDataset1();
    final XYItemRenderer renderer1 = new StandardXYItemRenderer();
    final NumberAxis rangeAxis1 = new NumberAxis("Range 1");
    final XYPlot subplot1 = new XYPlot(data1, null, rangeAxis1, renderer1);
    subplot1.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);

    final XYTextAnnotation annotation = new XYTextAnnotation("Hello!", 50.0, 10000.0);
    annotation.setFont(new Font("SansSerif", Font.PLAIN, 9));
    annotation.setRotationAngle(Math.PI / 4.0);
    subplot1.addAnnotation(annotation);

    // create subplot 2...
    final XYDataset data2 = createDataset2();
    final XYItemRenderer renderer2 = new StandardXYItemRenderer();
    final NumberAxis rangeAxis2 = new NumberAxis("Range 2");
    rangeAxis2.setAutoRangeIncludesZero(false);
    final XYPlot subplot2 = new XYPlot(data2, null, rangeAxis2, renderer2);
    subplot2.setRangeAxisLocation(AxisLocation.TOP_OR_LEFT);

    // parent plot...
    final CombinedDomainXYPlot plot = new CombinedDomainXYPlot(new NumberAxis("Domain"));
    plot.setGap(10.0);

    // add the subplots...
    plot.add(subplot1, 1);
    plot.add(subplot2, 1);
    plot.setOrientation(PlotOrientation.VERTICAL);

    // return a new chart containing the overlaid plot...
    return new JFreeChart("CombinedDomainXYPlot Demo", JFreeChart.DEFAULT_TITLE_FONT, plot, true);

}

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

/**
 * Creates a combined chart.//  ww w . j ava  2  s. c  o  m
 *
 * @return The combined chart.
 */
private JFreeChart createCombinedChart() {

    // create subplot 1...
    final XYDataset data1 = createDataset1();
    final XYItemRenderer renderer1 = new StandardXYItemRenderer();
    final NumberAxis rangeAxis1 = new NumberAxis("Range 1");
    final XYPlot subplot1 = new XYPlot(data1, null, rangeAxis1, renderer1);
    subplot1.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);

    // add secondary axis
    subplot1.setDataset(1, createDataset2());
    final NumberAxis axis2 = new NumberAxis("Range Axis 2");
    axis2.setAutoRangeIncludesZero(false);
    subplot1.setRangeAxis(1, axis2);
    subplot1.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_RIGHT);
    subplot1.setRenderer(1, new StandardXYItemRenderer());
    subplot1.mapDatasetToRangeAxis(1, 1);

    final XYTextAnnotation annotation = new XYTextAnnotation("Hello!", 50.0, 10000.0);
    annotation.setFont(new Font("SansSerif", Font.PLAIN, 9));
    annotation.setRotationAngle(Math.PI / 4.0);
    subplot1.addAnnotation(annotation);

    // create subplot 2...
    final XYDataset data2 = createDataset2();
    final XYItemRenderer renderer2 = new StandardXYItemRenderer();
    final NumberAxis rangeAxis2 = new NumberAxis("Range 2");
    rangeAxis2.setAutoRangeIncludesZero(false);
    final XYPlot subplot2 = new XYPlot(data2, null, rangeAxis2, renderer2);
    subplot2.setRangeAxisLocation(AxisLocation.TOP_OR_LEFT);

    // parent plot...
    final CombinedDomainXYPlot plot = new CombinedDomainXYPlot(new NumberAxis("Domain"));
    plot.setGap(10.0);

    // add the subplots...
    plot.add(subplot1, 1);
    plot.add(subplot2, 1);
    plot.setOrientation(PlotOrientation.VERTICAL);

    // return a new chart containing the overlaid plot...
    return new JFreeChart("CombinedDomainXYPlot Demo", JFreeChart.DEFAULT_TITLE_FONT, plot, true);

}

From source file:wef.articulab.view.ui.BNXYPlot.java

public IntervalXYDataset refreshDataset() {
    if (behaviors != null) {
        int sizeSeries = series.length - 1;

        //keep number of samples no bigger than maxNumSamples
        if (behaviors[0].size() > maxNumSamples) {
            for (int i = 0; i < behaviors.length; i++) {
                behaviors[i].remove(0);/*from  www  .j ava 2s .  c  o  m*/
            }
            thresholds.remove(0);
            activations.remove(0);
            offset++;
        }

        //Activation thresholds
        XYSeries ts = dataset.getSeries(series[sizeSeries]);
        ts.clear();
        for (int j = 0; j < thresholds.size(); j++) {
            ts.addOrUpdate(j + offset, thresholds.get(j).doubleValue());
        }
        target.setStartValue(minThreshold);
        target.setEndValue(maxThreshold);

        //behaviors
        for (int i = 0; i < sizeSeries; i++) {
            int size = behaviors[i].size();
            ts = dataset.getSeries(series[i]);
            ts.clear();
            for (int j = 0; j < size; j++) {
                ts.add(j + offset, behaviors[i].get(j).doubleValue());
            }
        }

        //who is activated?
        for (int x = 0; x < activations.size(); x++) {
            String name = (String) activations.get(x)[0];
            double y = (Double) activations.get(x)[1];
            if (name != null && !name.isEmpty()) {
                XYTextAnnotation annotation = new XYTextAnnotation(name, (x + offset), y);
                annotation.setFont(new Font("SansSerif", Font.ITALIC, 11));
                chart.getXYPlot().addAnnotation(annotation);
            }
        }
    }
    return dataset;
}

From source file:OverlaidXYPlotDemo2.java

/**
 * Creates an overlaid chart.//from   w  ww .  j a v a 2s.c  o m
 *
 * @return The chart.
 */
private JFreeChart createOverlaidChart() {

    final DateAxis domainAxis = new DateAxis("Date");
    domainAxis.setTickMarkPosition(DateTickMarkPosition.MIDDLE);
    final ValueAxis rangeAxis = new NumberAxis("Value");

    // create plot...
    final IntervalXYDataset data1 = createDataset1();
    final XYItemRenderer renderer1 = new XYBarRenderer(0.20);
    renderer1.setToolTipGenerator(
            new StandardXYToolTipGenerator(StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT,
                    new SimpleDateFormat("d-MMM-yyyy"), new DecimalFormat("0.00")));
    final XYPlot plot = new XYPlot(data1, domainAxis, rangeAxis, renderer1);
    final double x = new Day(9, SerialDate.MARCH, 2002).getMiddleMillisecond();
    final XYTextAnnotation annotation = new XYTextAnnotation("Hello!", x, 10000.0);
    annotation.setFont(new Font("SansSerif", Font.PLAIN, 9));
    plot.addAnnotation(annotation);

    final ValueAxis rangeAxis2 = new NumberAxis("Value 2");
    plot.setRangeAxis(1, rangeAxis2);

    // create subplot 2...
    final XYDataset data2A = createDataset2A();
    final XYItemRenderer renderer2A = new StandardXYItemRenderer();
    renderer2A.setToolTipGenerator(
            new StandardXYToolTipGenerator(StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT,
                    new SimpleDateFormat("d-MMM-yyyy"), new DecimalFormat("0.00")));
    plot.setDataset(1, data2A);
    plot.setRenderer(1, renderer2A);

    final XYDataset data2B = createDataset2B();
    plot.setDataset(2, data2B);
    plot.setRenderer(2, new StandardXYItemRenderer());
    plot.mapDatasetToRangeAxis(2, 1);

    plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);
    plot.setOrientation(PlotOrientation.VERTICAL);

    // return a new chart containing the overlaid plot...
    return new JFreeChart("Overlaid Plot Example", JFreeChart.DEFAULT_TITLE_FONT, plot, true);

}