Example usage for org.jfree.chart JFreeChart getXYPlot

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

Introduction

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

Prototype

public XYPlot getXYPlot() 

Source Link

Document

Returns the plot cast as an XYPlot .

Usage

From source file:com.wsntools.iris.tools.Graph.java

private void setupChartType(JFreeChart chart) {

    chart.setBackgroundPaint(Color.white);

    // plot = chart.getCategoryPlot();
    plot = chart.getXYPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);
    // plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 4, 4, 4, 4));

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

    rangeAxis.setAutoRangeIncludesZero(false);
    rangeAxis.setAutoRange(true);/*from w  w  w.ja  v  a 2  s.  c  o  m*/
    domainAxis.setAutoRangeIncludesZero(false);
    rangeAxis.setAutoRange(true);
    domainAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    chartPanel.setChart(chart);
}

From source file:org.mwc.cmap.LiveDataMonitor.views.LiveDataMonitor.java

/**
 * Creates the Chart based on a dataset// ww  w . j  a  v a2  s.  c o m
 */
private JFreeChart createChart(final TimeSeriesCollection dataset) {

    final String annTitle = "[PENDING]";
    final String catLabel = "Time";
    final String valueLabel = "Value";
    final JFreeChart chart = ChartFactory.createXYLineChart(annTitle, catLabel, valueLabel, dataset,
            PlotOrientation.VERTICAL, false, true, false);

    final XYPlot plot = chart.getXYPlot();
    final DateAxis dateA = new DateAxis();
    plot.setDomainAxis(dateA);
    plot.setRenderer(new XYLineAndShapeRenderer());
    plot.setNoDataMessage("No data available");
    return chart;

}

From source file:userinterface.patientRole.LineChart.java

public LineChart(String applicationTitle, String chartTitle, XYSeries bR, XYSeries pR, XYSeries bS, XYSeries bP,
        JFrame parent) {/*w  w w  .jav  a2  s .  c om*/
    // super(applicationTitle);
    this.bR = bR;
    this.pR = pR;
    this.bS = bS;
    this.bP = bP;
    this.parent = parent;
    dataset = createDataset();
    JFreeChart xylineChart = ChartFactory.createXYLineChart(chartTitle, "Category", "Vital Signs",
            createDataset(), PlotOrientation.VERTICAL, true, true, false);
    ChartPanel chartPanel = new ChartPanel(xylineChart);
    chartPanel.setPreferredSize(new java.awt.Dimension(560, 367));
    final XYPlot plot = xylineChart.getXYPlot();
    plot.setBackgroundPaint(Color.white);
    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    renderer.setSeriesPaint(0, Color.RED);
    renderer.setSeriesPaint(1, Color.GREEN);
    renderer.setSeriesPaint(2, Color.YELLOW);
    renderer.setSeriesPaint(3, Color.BLUE);
    renderer.setSeriesStroke(0, new BasicStroke(1.0f));
    renderer.setSeriesStroke(1, new BasicStroke(1.0f));
    renderer.setSeriesStroke(2, new BasicStroke(1.0f));
    renderer.setSeriesStroke(3, new BasicStroke(1.0f));
    plot.setRenderer(renderer);
    setContentPane(chartPanel);
    addWindowListener(new java.awt.event.WindowAdapter() {
        public void windowClosing(java.awt.event.WindowEvent evt) {
            formWindowClosing(evt);
        }
    });
}

From source file:com.intel.stl.ui.performance.PerformanceChartsCreator.java

protected JFreeChart getBwHistogramChart(Dataset dataset) {
    JFreeChart chart = ComponentFactory.createXYBarChart(STLConstants.K0053_CAPABILITY.getValue(),
            STLConstants.K0044_NUM_PORTS.getValue(), (IntervalXYDataset) dataset, (XYItemLabelGenerator) null);
    NumberAxis axis = (NumberAxis) chart.getXYPlot().getDomainAxis();
    axis.setTickUnit(new NumberTickUnit(0.2, UIConstants.PERCENTAGE));

    axis = (NumberAxis) chart.getXYPlot().getRangeAxis();
    axis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    return chart;
}

From source file:arduinouno.TimeChartGenerator.java

/**
 * Creates a sample chart.//from  w w w.j av  a2 s  . com
 *
 * @param dataset the dataset.
 *
 * @return A sample chart.
 */
private JFreeChart createChart(final XYDataset dataset, final XYDataset dataset0, final XYDataset dataset1,
        final XYDataset dataset2, final XYDataset dataset3, final XYDataset dataset4,
        final XYDataset dataset5) {
    final JFreeChart result = ChartFactory.createTimeSeriesChart("Arduino Serial Reader", "Time", "Value",
            dataset, true, true, false);

    plot = result.getXYPlot();

    //Set Graph Parameters
    plot.setBackgroundPaint(new Color(0xffffe0));
    plot.setDomainGridlinesVisible(true);
    plot.setDomainGridlinePaint(Color.lightGray);
    plot.setRangeGridlinesVisible(true);
    plot.setRangeGridlinePaint(Color.lightGray);

    ValueAxis xaxis = plot.getDomainAxis();
    xaxis.setAutoRange(true);
    xaxis.setTickLabelsVisible(false);

    //Domain axis would show data of 30 seconds for a time
    xaxis.setFixedAutoRange(30000.0); // 30 seconds

    xaxis.setVerticalTickLabels(false);

    ValueAxis yaxis = plot.getRangeAxis();
    yaxis.setRange(0.0, 6.0);

    if (dataset0 != null) {
        plot.setDataset(1, dataset0);
        plot.setRenderer(1, new StandardXYItemRenderer());
    }
    if (dataset1 != null) {
        plot.setDataset(2, dataset1);
        plot.setRenderer(2, new StandardXYItemRenderer());
    }
    if (dataset2 != null) {
        plot.setDataset(3, dataset2);
        plot.setRenderer(3, new StandardXYItemRenderer());
    }
    if (dataset3 != null) {
        plot.setDataset(4, dataset3);
        plot.setRenderer(4, new StandardXYItemRenderer());
    }
    if (dataset4 != null) {
        plot.setDataset(5, dataset4);
        plot.setRenderer(5, new StandardXYItemRenderer());
    }
    if (dataset5 != null) {
        plot.setDataset(6, dataset5);
        plot.setRenderer(6, new StandardXYItemRenderer());
    }

    return result;
}

From source file:clonalgtcc.PlotTest.java

private JFreeChart createChart(final XYDataset dataset) {
    final JFreeChart chart = ChartFactory.createScatterPlot("Ruspini", // chart title
            "X", // x axis label
            "Y", // y axis label
            dataset, // data
            PlotOrientation.VERTICAL, true, // include legend
            true, // tooltips
            false // urls
    );//from www .j a  v  a  2 s . c o  m
    XYPlot xyPlot = chart.getXYPlot();
    XYItemRenderer renderer = xyPlot.getRenderer();

    //        renderer.setSeriesPaint( 4, Color.BLUE );
    //        renderer.setSeriesShape(1, new Ellipse2D.Double(-3, -3, 6, 6));
    //        renderer.setSeriesShape(2, new Ellipse2D.Double(-3, -3, 6, 6));
    //        renderer.setSeriesShape(3, new Ellipse2D.Double(-3, -3, 6, 6));
    //        renderer.setSeriesShape(4, new Ellipse2D.Double(-3, -3, 6, 6));

    // Comentando essas linhas abaixo;
    //        XYPlot plot = (XYPlot) chart.getPlot();
    //        XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    //        renderer.setSeriesLinesVisible(0, true);
    //        plot.setRenderer(renderer);
    // At aqui
    return chart;
}

From source file:in.BBAT.presenter.DualAxisDemo2.java

/**
 * A demonstration application showing how to create a time series chart with dual axes.
 *
 * @param title  the frame title./*from   www.  ja v  a 2  s  . c  o  m*/
 */
public DualAxisDemo2(final String title) {

    super(title);

    // create a title...
    final String chartTitle = "Memory & CPU usage";
    final XYDataset dataset = createDataset1();

    final JFreeChart chart = ChartFactory.createTimeSeriesChart(chartTitle, "Time", "Memory usage (kB)",
            dataset, true, true, false);

    //      final StandardLegend legend = (StandardLegend) chart.getLegend();
    //    legend.setDisplaySeriesShapes(true);

    final XYPlot plot = chart.getXYPlot();
    final NumberAxis axis2 = new NumberAxis("CPU usage (%)");
    axis2.setAutoRangeIncludesZero(false);
    plot.setRangeAxis(1, axis2);
    plot.setDataset(1, createDataset2());
    plot.mapDatasetToRangeAxis(1, 1);
    final XYItemRenderer renderer = plot.getRenderer();
    renderer.setToolTipGenerator(StandardXYToolTipGenerator.getTimeSeriesInstance());
    if (renderer instanceof StandardXYItemRenderer) {
        final StandardXYItemRenderer rr = (StandardXYItemRenderer) renderer;
        //            rr.setPlotShapes(true);
        rr.setShapesFilled(true);
    }

    final StandardXYItemRenderer renderer2 = new StandardXYItemRenderer();
    renderer2.setSeriesPaint(0, Color.black);
    //        renderer2.setPlotShapes(true);
    renderer.setToolTipGenerator(StandardXYToolTipGenerator.getTimeSeriesInstance());
    plot.setRenderer(1, renderer2);

    final DateAxis axis = (DateAxis) plot.getDomainAxis();
    axis.setDateFormatOverride(new SimpleDateFormat("hh:mm:ss"));

    final ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
    setContentPane(chartPanel);

}

From source file:Views.GraphView.java

private JFreeChart createChart(final XYDataset dataset) {
    final JFreeChart result = ChartFactory.createTimeSeriesChart(graphTitle, "Time", "Price", dataset, true,
            true, false);//from  www  .  j a v  a2  s  .  c om

    plot = result.getXYPlot();

    plot.setBackgroundPaint(new Color(0xffffe0));
    plot.setDomainGridlinesVisible(true);
    plot.setDomainGridlinePaint(Color.lightGray);
    plot.setRangeGridlinesVisible(true);
    plot.setRangeGridlinePaint(Color.lightGray);

    ValueAxis xaxis = plot.getDomainAxis();
    xaxis.setAutoRange(true);
    xaxis.setVisible(false);

    xaxis.setFixedAutoRange(16000.0); // 60 seconds
    xaxis.setVerticalTickLabels(true);

    ValueAxis yaxis = plot.getRangeAxis();
    yaxis.setRange(0, 100.0);

    xaxis2 = new NumberAxis("Volume");

    plot.setDataset(1, dataset2);

    plot.setRangeAxis(1, xaxis2);
    plot.mapDatasetToRangeAxis(1, 1);

    XYBarRenderer renderer2 = new XYBarRenderer(0.20);
    renderer2.setToolTipGenerator(
            new StandardXYToolTipGenerator(StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT,
                    new SimpleDateFormat("d-MMM-yyyy"), new DecimalFormat("0,000.00")));
    renderer2.setToolTipGenerator(StandardXYToolTipGenerator.getTimeSeriesInstance());

    plot.setRenderer(1, renderer2);

    plot.setDataset(2, dataset3);

    plot.mapDatasetToRangeAxis(2, 0);

    XYErrorRenderer renderer3 = new XYErrorRenderer();
    plot.setRenderer(2, renderer3);

    plot.setDataset(3, dataset4);
    plot.mapDatasetToRangeAxis(3, 1);
    XYBarRenderer renderer4 = new XYBarRenderer(0.20);

    plot.setRenderer(3, renderer4);

    return result;
}

From source file:iDynoOptimizer.MOEAFramework26.src.org.moeaframework.analysis.diagnostics.ApproximationSetPlot.java

@Override
protected void update() {
    XYSeriesCollection dataset = new XYSeriesCollection();

    for (ResultKey key : frame.getSelectedResults()) {
        NondominatedPopulation population = new EpsilonBoxDominanceArchive(EPSILON);

        for (Accumulator accumulator : controller.get(key)) {
            if (!accumulator.keySet().contains(metric)) {
                continue;
            }/*from   w w w  . j  a v a  2 s.  c o  m*/

            List<?> list = (List<?>) accumulator.get(metric, accumulator.size(metric) - 1);

            for (Object object : list) {
                population.add((Solution) object);
            }
        }

        if (!population.isEmpty()) {
            XYSeries series = new XYSeries(key, false, true);

            for (Solution solution : population) {
                if (solution.getNumberOfObjectives() == 1) {
                    series.add(solution.getObjective(0), solution.getObjective(0));
                } else if (solution.getNumberOfObjectives() > 1) {
                    series.add(solution.getObjective(0), solution.getObjective(1));
                }
            }

            dataset.addSeries(series);
        }
    }

    JFreeChart chart = ChartFactory.createScatterPlot(metric, localization.getString("text.objective", 1),
            localization.getString("text.objective", 2), dataset, PlotOrientation.VERTICAL, true, true, false);

    XYPlot plot = chart.getXYPlot();
    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(false, true);

    for (int i = 0; i < dataset.getSeriesCount(); i++) {
        Paint paint = frame.getPaintHelper().get(dataset.getSeriesKey(i));

        renderer.setSeriesStroke(i, new BasicStroke(3f, 1, 1));
        renderer.setSeriesPaint(i, paint);
        renderer.setSeriesFillPaint(i, paint);
    }

    plot.setRenderer(renderer);

    //add overlay
    if (controller.getShowLastTrace() && (controller.getLastAccumulator() != null)
            && controller.getLastAccumulator().keySet().contains(metric)) {
        XYSeriesCollection dataset2 = new XYSeriesCollection();
        NondominatedPopulation population = new EpsilonBoxDominanceArchive(EPSILON);

        if (controller.getLastAccumulator().keySet().contains(metric)) {
            List<?> list = (List<?>) controller.getLastAccumulator().get(metric,
                    controller.getLastAccumulator().size(metric) - 1);

            for (Object object : list) {
                population.add((Solution) object);
            }
        }

        if (!population.isEmpty()) {
            XYSeries series = new XYSeries(localization.getString("text.last"), false, true);

            for (Solution solution : population) {
                series.add(solution.getObjective(0), solution.getObjective(1));
            }

            dataset2.addSeries(series);
        }

        XYLineAndShapeRenderer renderer2 = new XYLineAndShapeRenderer(false, true);
        renderer2.setSeriesPaint(0, Color.BLACK);

        plot.setDataset(1, dataset2);
        plot.setRenderer(1, renderer2);
        plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);
    }

    removeAll();
    add(new ChartPanel(chart), BorderLayout.CENTER);
    revalidate();
    repaint();
}

From source file:org.drugis.addis.gui.ConvergencePlotsDialog.java

private JFreeChart createVhatVsWChart(final XYDataset dataset) {
    final JFreeChart VhatVsWChart = ChartFactory.createXYLineChart("Plots of sqrt(vHat) and sqrt(W)",
            "Iteration No.", "Variance Estimates", dataset, PlotOrientation.VERTICAL, true, true, false);

    VhatVsWChart.setBackgroundPaint(Color.white);
    final XYPlot VhatVsWPlot = VhatVsWChart.getXYPlot();
    VhatVsWPlot.setDomainGridlinePaint(Color.white);
    VhatVsWPlot.setRangeGridlinePaint(Color.white);

    final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    renderer.setSeriesPaint(0, Color.red);
    renderer.setSeriesPaint(1, Color.blue);
    renderer.setSeriesShapesVisible(0, false);
    renderer.setSeriesShapesVisible(1, false);
    VhatVsWPlot.setRenderer(renderer);/* w w  w . j a va 2 s.  co m*/

    return VhatVsWChart;
}