Example usage for org.jfree.chart JFreeChart getPlot

List of usage examples for org.jfree.chart JFreeChart getPlot

Introduction

In this page you can find the example usage for org.jfree.chart JFreeChart getPlot.

Prototype

public Plot getPlot() 

Source Link

Document

Returns the plot for the chart.

Usage

From source file:org.exist.xquery.modules.jfreechart.JFreeChartFactory.java

private static void setAxisColors(JFreeChart chart, Configuration config) {
    Color categoryAxisColor = config.getCategoryAxisColor();
    Color valueAxisColor = config.getValueAxisColor();

    if (categoryAxisColor != null) {
        if (chart.getPlot() instanceof SpiderWebPlot) {
            ((SpiderWebPlot) chart.getPlot()).setAxisLinePaint(categoryAxisColor);
        } else {//  ww w .  jav  a2  s  .com
            ((CategoryPlot) chart.getPlot()).getDomainAxis().setLabelPaint(categoryAxisColor);
        }
    }

    if (valueAxisColor != null) {
        if (chart.getPlot() instanceof SpiderWebPlot) {
            //((SpiderWebPlot) chart.getPlot()).setAxisLinePaint(valueAxisColor);
        } else {
            ((CategoryPlot) chart.getPlot()).getRangeAxis().setLabelPaint(valueAxisColor);
        }
    }
}

From source file:eu.cassandra.training.utils.ChartUtils.java

/**
 * This function is used for the visualization of a Gaussian Mixture
 * Distribution./*  w  w w. j a  v  a  2s . co  m*/
 * 
 * @param title
 *          The title of the chart.
 * @param x
 *          The unit on the X axis of the chart.
 * @param y
 *          The unit on the Y axis of the chart.
 * @param data
 *          The array of values.
 * @return a chart panel with the graphical representation.
 */
public static ChartPanel createMixtureDistribution(String title, String x, String y, double[] data) {
    XYSeries series1 = new XYSeries("First");

    for (int i = 0; i < data.length; i++) {
        series1.add(i, data[i]);
    }

    final XYSeriesCollection dataset = new XYSeriesCollection();
    dataset.addSeries(series1);

    PlotOrientation orientation = PlotOrientation.VERTICAL;
    boolean show = false;
    boolean toolTips = false;
    boolean urls = false;

    JFreeChart chart = ChartFactory.createXYLineChart(title, x, y, dataset, orientation, show, toolTips, urls);

    XYPlot xyplot = (XYPlot) chart.getPlot();
    xyplot.setDomainPannable(true);
    xyplot.setRangePannable(true);
    xyplot.setForegroundAlpha(0.85F);
    NumberAxis domainAxis = (NumberAxis) xyplot.getDomainAxis();
    if (data.length != 1440)
        domainAxis.setTickUnit(new NumberTickUnit(data.length / 10));
    else
        domainAxis.setTickUnit(new NumberTickUnit(100));
    NumberAxis numberaxis = (NumberAxis) xyplot.getRangeAxis();
    numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    return new ChartPanel(chart);

}

From source file:eu.cassandra.training.utils.ChartUtils.java

/**
 * This function is used for the visualization of a Comparative Response Model
 * Histogram./*from  w  w  w.j av  a 2 s.c o m*/
 * 
 * @param title
 *          The title of the chart.
 * @param x
 *          The unit on the X axis of the chart.
 * @param y
 *          The unit on the Y axis of the chart.
 * @param dataBefore
 *          The array of values before the response.
 * @param dataAfter
 *          The array of values after the response.
 * @return a chart panel with the graphical representation.
 */
public static ChartPanel createResponseHistogram(String title, String x, String y, double[] dataBefore,
        double[] dataAfter) {
    XYSeries series1 = new XYSeries("Basic Pricing Scheme");
    for (int i = 0; i < dataBefore.length; i++) {
        series1.add(i, dataBefore[i]);
    }

    XYSeries series2 = new XYSeries("New Pricing Scheme");
    for (int i = 0; i < dataAfter.length; i++) {
        series2.add(i, dataAfter[i]);
    }

    XYSeriesCollection dataset = new XYSeriesCollection();
    dataset.addSeries(series1);
    dataset.addSeries(series2);

    PlotOrientation orientation = PlotOrientation.VERTICAL;
    boolean show = true;
    boolean toolTips = false;
    boolean urls = false;

    JFreeChart chart = ChartFactory.createXYLineChart(title, x, y, dataset, orientation, show, toolTips, urls);
    XYPlot xyplot = (XYPlot) chart.getPlot();
    xyplot.setDomainPannable(true);
    xyplot.setRangePannable(true);
    xyplot.setForegroundAlpha(0.85F);
    NumberAxis domainAxis = (NumberAxis) xyplot.getDomainAxis();

    // domainAxis.setRange(0.0, 1440.0);
    domainAxis.setTickUnit(new NumberTickUnit(10));
    NumberAxis numberaxis = (NumberAxis) xyplot.getRangeAxis();
    numberaxis.setTickUnit(new NumberTickUnit(0.1));

    return new ChartPanel(chart);
}

From source file:org.jfree.chart.swt.demo.SWTMultipleAxisDemo1.java

/**
 * Creates the demo chart./*  ww  w .  jav  a  2 s  . c  om*/
 *
 * @return The chart.
 */
private static JFreeChart createChart() {

    XYDataset dataset1 = createDataset("Series 1", 100.0, new Minute(), 200);

    JFreeChart chart = ChartFactory.createTimeSeriesChart("Multiple Axis Demo 3", "Time of Day",
            "Primary Range Axis", dataset1, true, true, false);

    chart.setBackgroundPaint(Color.white);
    chart.setBorderVisible(true);
    chart.setBorderPaint(Color.BLACK);
    TextTitle subtitle = new TextTitle("Four datasets and four range axes.");
    chart.addSubtitle(subtitle);
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setOrientation(PlotOrientation.VERTICAL);
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    XYItemRenderer renderer = plot.getRenderer();
    renderer.setSeriesPaint(0, Color.black);

    // AXIS 2
    NumberAxis axis2 = new NumberAxis("Range Axis 2");
    axis2.setAutoRangeIncludesZero(false);
    axis2.setLabelPaint(Color.red);
    axis2.setTickLabelPaint(Color.red);
    plot.setRangeAxis(1, axis2);
    plot.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_LEFT);

    XYDataset dataset2 = createDataset("Series 2", 1000.0, new Minute(), 170);
    plot.setDataset(1, dataset2);
    plot.mapDatasetToRangeAxis(1, 1);
    XYItemRenderer renderer2 = new StandardXYItemRenderer();
    renderer2.setSeriesPaint(0, Color.red);
    plot.setRenderer(1, renderer2);

    // AXIS 3
    NumberAxis axis3 = new NumberAxis("Range Axis 3");
    axis3.setLabelPaint(Color.blue);
    axis3.setTickLabelPaint(Color.blue);
    //axis3.setPositiveArrowVisible(true);
    plot.setRangeAxis(2, axis3);

    XYDataset dataset3 = createDataset("Series 3", 10000.0, new Minute(), 170);
    plot.setDataset(2, dataset3);
    plot.mapDatasetToRangeAxis(2, 2);
    XYItemRenderer renderer3 = new StandardXYItemRenderer();
    renderer3.setSeriesPaint(0, Color.blue);
    plot.setRenderer(2, renderer3);

    // AXIS 4
    NumberAxis axis4 = new NumberAxis("Range Axis 4");
    axis4.setLabelPaint(Color.green);
    axis4.setTickLabelPaint(Color.green);
    plot.setRangeAxis(3, axis4);

    XYDataset dataset4 = createDataset("Series 4", 25.0, new Minute(), 200);
    plot.setDataset(3, dataset4);
    plot.mapDatasetToRangeAxis(3, 3);

    XYItemRenderer renderer4 = new StandardXYItemRenderer();
    renderer4.setSeriesPaint(0, Color.green);
    plot.setRenderer(3, renderer4);

    return chart;
}

From source file:cn.edu.thss.iise.bpmdemo.charts.SWTMultipleAxisDemo1.java

/**
 * Creates the demo chart.//  w ww  .  jav a 2s  . co  m
 *
 * @return The chart.
 */
private static JFreeChart createChart() {

    XYDataset dataset1 = createDataset("Series 1", 100.0, new Day(), 200);

    JFreeChart chart = ChartFactory.createTimeSeriesChart("Multiple Axis Demo 3", "Time of Day",
            "Primary Range Axis", dataset1, true, true, false);

    chart.setBackgroundPaint(Color.white);
    chart.setBorderVisible(true);
    chart.setBorderPaint(Color.BLACK);
    TextTitle subtitle = new TextTitle("Four datasets and four range axes.");
    chart.addSubtitle(subtitle);
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setOrientation(PlotOrientation.VERTICAL);
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    XYItemRenderer renderer = plot.getRenderer();
    renderer.setSeriesPaint(0, Color.black);

    // AXIS 2
    NumberAxis axis2 = new NumberAxis("Range Axis 2");
    axis2.setAutoRangeIncludesZero(false);
    axis2.setLabelPaint(Color.red);
    axis2.setTickLabelPaint(Color.red);
    plot.setRangeAxis(1, axis2);
    plot.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_LEFT);

    XYDataset dataset2 = createDataset("Series 2", 1000.0, new Day(), 170);
    plot.setDataset(1, dataset2);
    plot.mapDatasetToRangeAxis(1, 1);
    XYItemRenderer renderer2 = new StandardXYItemRenderer();
    renderer2.setSeriesPaint(0, Color.red);
    plot.setRenderer(1, renderer2);

    // AXIS 3
    NumberAxis axis3 = new NumberAxis("Range Axis 3");
    axis3.setLabelPaint(Color.blue);
    axis3.setTickLabelPaint(Color.blue);
    // axis3.setPositiveArrowVisible(true);
    plot.setRangeAxis(2, axis3);

    XYDataset dataset3 = createDataset("Series 3", 10000.0, new Day(), 170);
    plot.setDataset(2, dataset3);
    plot.mapDatasetToRangeAxis(2, 2);
    XYItemRenderer renderer3 = new StandardXYItemRenderer();
    renderer3.setSeriesPaint(0, Color.blue);
    plot.setRenderer(2, renderer3);

    // AXIS 4
    NumberAxis axis4 = new NumberAxis("Range Axis 4");
    axis4.setLabelPaint(Color.green);
    axis4.setTickLabelPaint(Color.green);
    plot.setRangeAxis(3, axis4);

    XYDataset dataset4 = createDataset("Series 4", 25.0, new Day(), 200);
    plot.setDataset(3, dataset4);
    plot.mapDatasetToRangeAxis(3, 3);

    XYItemRenderer renderer4 = new StandardXYItemRenderer();
    renderer4.setSeriesPaint(0, Color.green);
    plot.setRenderer(3, renderer4);

    return chart;
}

From source file:de.bfs.radon.omsimulation.gui.data.OMCharts.java

/**
 * Creates a chart displaying the radon concentration of a single room. Uses
 * red for normal rooms, blue for cellar rooms and green for misc rooms.
 * /*from   www . j  a v  a2s. c o m*/
 * @param title
 *          The headline of the chart. Will be hidden if set to null.
 * @param room
 *          The room object containing the radon data.
 * @param preview
 *          Will hide annotations, labels and headlines if true.
 * @return A chart displaying the radon concentration of a single room.
 */
public static JFreeChart createRoomChart(String title, OMRoom room, boolean preview) {
    Color lineColor = new Color(0, 0, 0, 128);
    Color rangeColor = new Color(222, 222, 222, 128);
    if (room.getType() == OMRoomType.Room) {
        lineColor = new Color(255, 0, 0, 128);
        rangeColor = new Color(255, 222, 222, 128);
    } else {
        if (room.getType() == OMRoomType.Cellar) {
            lineColor = new Color(0, 0, 255, 128);
            rangeColor = new Color(222, 222, 255, 128);
        } else {
            lineColor = new Color(0, 128, 0, 255);
            rangeColor = new Color(222, 255, 222, 128);
        }
    }
    double[] values = room.getValues();
    XYSeriesCollection dataSet = new XYSeriesCollection();
    XYSeries series = new XYSeries("Radon");
    int count = room.getCount();
    double maxPointerKey = 0;
    for (int i = 0; i < count; i++) {
        series.add(i, values[i]);
        if (values[i] == room.getMaximum()) {
            maxPointerKey = i;
        }
    }
    dataSet.addSeries(series);
    title = title + ": " + room.getType().toString() + " " + room.getId();
    JFreeChart chart = ChartFactory.createXYLineChart(title, "T [h]", "Rn [Bq/m\u00B3]", dataSet,
            PlotOrientation.VERTICAL, false, true, false);
    XYPlot plot = (XYPlot) chart.getPlot();
    double positiveDeviation = room.getAverage() + room.getDeviation();
    double negativeDeviation = room.getAverage() - room.getDeviation();
    IntervalMarker deviation = new IntervalMarker(negativeDeviation, positiveDeviation);
    float[] dash = { 5, 3 };
    deviation.setPaint(rangeColor);
    deviation.setStroke(new BasicStroke(2, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 1, dash, 0));
    plot.addRangeMarker(deviation, Layer.BACKGROUND);
    ValueMarker arithMarker = new ValueMarker(room.getAverage(), lineColor,
            new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 1, dash, 0));
    plot.addRangeMarker(arithMarker);
    ValueMarker maxiMarker = new ValueMarker(room.getMaximum(), lineColor,
            new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 1, dash, 0));
    plot.addRangeMarker(maxiMarker);
    XYTextAnnotation amLabel = new XYTextAnnotation("AM=" + (int) room.getAverage(), count,
            room.getAverage() * 1.01);
    plot.addAnnotation(amLabel);
    XYTextAnnotation sdLabel = new XYTextAnnotation("SD=" + (int) room.getDeviation(), count,
            (room.getAverage() + room.getDeviation()) * 1.01);
    plot.addAnnotation(sdLabel);
    XYTextAnnotation maxLabel = new XYTextAnnotation("MAX=" + (int) room.getMaximum(), count,
            room.getMaximum() * 1.01);
    plot.addAnnotation(maxLabel);
    XYPointerAnnotation maxPointer = new XYPointerAnnotation("", maxPointerKey, room.getMaximum(),
            Math.PI * 1.1);
    plot.addAnnotation(maxPointer);
    XYItemRenderer renderer = plot.getRenderer();
    renderer.setSeriesPaint(0, lineColor);
    if (preview) {
        chart.setTitle("");
        plot.clearAnnotations();
    }
    return chart;
}

From source file:org.hxzon.demo.jfreechart.XYDatasetDemo.java

private static JFreeChart createPolarChart(XYDataset dataset) {

    JFreeChart chart = ChartFactory.createPolarChart("Legal & General Unit Trust Prices", // chart title
            dataset, // data
            true, // include legend
            true, // tooltips?
            false // URLs?
    );/* w ww.ja v  a2  s  . c  om*/

    chart.setBackgroundPaint(Color.white);

    PolarPlot plot = (PolarPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.lightGray);

    return chart;
}

From source file:net.sf.jsfcomp.chartcreator.utils.ChartUtils.java

public static JFreeChart createChartWithPieDataSet(ChartData chartData) {
    PieDataset dataset = (PieDataset) chartData.getDatasource();
    String type = chartData.getType();
    boolean legend = chartData.isLegend();
    JFreeChart chart = null;

    if (type.equalsIgnoreCase("pie")) {
        if (chartData.isChart3d()) {
            chart = ChartFactory.createPieChart3D("", dataset, legend, true, false);
            PiePlot3D plot = (PiePlot3D) chart.getPlot();
            plot.setDepthFactor((float) chartData.getDepth() / 100);
        } else {//from   w w w  .j  a va  2  s .  c o m
            chart = ChartFactory.createPieChart("", dataset, legend, true, false);
        }
    } else if (type.equalsIgnoreCase("ring")) {
        chart = ChartFactory.createRingChart("", dataset, legend, true, false);
    }

    PiePlot plot = (PiePlot) chart.getPlot();
    plot.setStartAngle((float) chartData.getStartAngle());
    if (chartData.getGenerateMap() != null)
        plot.setURLGenerator(new StandardPieURLGenerator(""));

    setPieSectionColors(chart, chartData);

    return chart;
}

From source file:com.jolbox.benchmark.BenchmarkMain.java

/**
 * @param results//w  ww .j  av  a2 s . com
 * @param delay 
 * @param statementBenchmark 
 * @param noC3P0 
 */
private static void doPlotLineGraph(long[][] results, int delay, boolean statementBenchmark, boolean noC3P0) {
    XYSeriesCollection dataset = new XYSeriesCollection();
    for (int i = 0; i < ConnectionPoolType.values().length; i++) { //
        if (!ConnectionPoolType.values()[i].isEnabled()
                || (noC3P0 && ConnectionPoolType.values()[i].equals(ConnectionPoolType.C3P0))) {
            continue;
        }
        XYSeries series = new XYSeries(ConnectionPoolType.values()[i].toString());

        for (int j = 1 + BenchmarkTests.stepping; j < results[i].length; j += BenchmarkTests.stepping) {
            series.add(j, results[i][j]);
        }
        dataset.addSeries(series);
    }

    //         Generate the graph
    String title = "Multi-Thread test (" + delay + "ms delay)";
    if (statementBenchmark) {
        title += "\n(with PreparedStatements tests)";
    }
    JFreeChart chart = ChartFactory.createXYLineChart(title, // Title
            "threads", // x-axis Label
            "time (ns)", // y-axis Label
            dataset, // Dataset
            PlotOrientation.VERTICAL, // Plot Orientation
            true, // Show Legend
            true, // Use tooltips
            false // Configure chart to generate URLs?
    );

    XYPlot plot = (XYPlot) chart.getPlot();
    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(true, false);
    plot.setRenderer(renderer);
    renderer.setSeriesPaint(0, Color.BLUE);
    renderer.setSeriesPaint(1, Color.YELLOW);
    renderer.setSeriesPaint(2, Color.BLACK);
    renderer.setSeriesPaint(3, Color.DARK_GRAY);
    renderer.setSeriesPaint(4, Color.MAGENTA);
    renderer.setSeriesPaint(5, Color.RED);
    renderer.setSeriesPaint(6, Color.LIGHT_GRAY);
    //          renderer.setSeriesShapesVisible(1, true);   
    //          renderer.setSeriesShapesVisible(2, true);   

    try {
        String fname = System.getProperty("java.io.tmpdir") + File.separator + "bonecp-multithread-" + delay
                + "ms-delay";
        if (statementBenchmark) {
            fname += "-with-preparedstatements";
        }
        fname += "-poolsize-" + BenchmarkTests.pool_size + "-threads-" + BenchmarkTests.threads;
        if (noC3P0) {
            fname += "-noC3P0";
        }
        fname += ".png";
        ChartUtilities.saveChartAsPNG(new File(fname), chart, 1024, 768);
        System.out.println("******* Saved chart to: " + fname);
    } catch (IOException e) {
        System.err.println("Problem occurred creating chart.");
    }

}

From source file:bullioneconomy.bullionchart.java

/**
 * Creates a chart./* w  ww . j  a  v  a  2s  .  c  om*/
 * 
 * @param dataset  a dataset.
 * 
 * @return A chart.
 */
private static JFreeChart createChart(XYDataset dataset) {

    JFreeChart chart = ChartFactory.createTimeSeriesChart("Gold Price in Recent Years", // title
            "Date", // x-axis label
            "Price Per 10g", // y-axis label
            dataset, // data
            true, // create legend?
            true, // generate tooltips?
            false // generate URLs?
    );

    chart.setBackgroundPaint(Color.white);

    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);

    XYItemRenderer r = plot.getRenderer();
    if (r instanceof XYLineAndShapeRenderer) {
        XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r;
        //renderer.setDefaultShapesVisible(true);
        //renderer.setDefaultShapesFilled(true);
    }

    DateAxis axis = (DateAxis) plot.getDomainAxis();
    axis.setDateFormatOverride(new SimpleDateFormat("MMM-yyyy"));

    return chart;

}