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:main.GUI.java

public void createKrivka() {

    XYSeriesCollection dataset = carlo.getDataSetKrivka();

    JFreeChart lineChart = ChartFactory.createXYLineChart("Pravdepodobnos splnenia termnu",
            "Trvanie projektu v doch", "Pravdepodobnos v %", dataset);
    final NumberAxis rangeAxis = (NumberAxis) lineChart.getXYPlot().getRangeAxis();
    rangeAxis.setAutoRangeIncludesZero(false);
    ChartPanel chartPanel = new ChartPanel(lineChart);

    panelKrivka.setLayout(new java.awt.BorderLayout());
    panelKrivka.add(chartPanel, BorderLayout.CENTER);
    panelKrivka.validate();/*from   ww  w .j a  v  a  2 s.com*/
}

From source file:web.diva.server.model.LineChartGenerator.java

/**
 * Creates a chart.//  w ww .j  a va2s.  c  o m
 *
 * @param dataset the data for the chart.
 * @param lcr the line chart result
 *
 * @return a chart.
 */
private JFreeChart createChart(final XYDataset dataset, String[] colors, String[] columnIds, int[] selection) {

    final JFreeChart chart = ChartFactory.createXYLineChart("", // chart title
            "", // x axis label
            "", // y axis label
            dataset, // data
            PlotOrientation.VERTICAL, false, // include legend
            false, // tooltips
            false // urls
    );

    chart.setBackgroundPaint(Color.white);

    final XYPlot plot = chart.getXYPlot();
    plot.setBackgroundPaint(Color.WHITE);
    plot.setDomainGridlinePaint(Color.WHITE);
    plot.setRangeGridlinePaint(Color.WHITE);

    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();

    if (selection == null) {
        for (int x = 0; x < colors.length; x++) {

            renderer.setSeriesShapesVisible(x, false);
            renderer.setSeriesPaint(x, imgGenerator.hex2Rgb(colors[x]));

        }
    } else {
        for (int x = 0; x < selection.length; x++) {

            renderer.setSeriesShapesVisible(x, false);
            renderer.setSeriesPaint(x, imgGenerator.hex2Rgb(colors[selection[x]]));

        }

    }

    plot.setRenderer(renderer);

    SymbolAxis rangeAxis = new SymbolAxis("", columnIds);
    rangeAxis.setGridBandsVisible(false);
    rangeAxis.setVerticalTickLabels(true);
    rangeAxis.setVisible(true);
    //        rangeAxis.setLabelFont(new Font("Arial", Font.PLAIN, 1));
    rangeAxis.setFixedDimension(51.0);

    boolean auto = rangeAxis.getAutoRangeIncludesZero();
    rangeAxis.setAutoRangeIncludesZero(true ^ auto);
    rangeAxis.setTickUnit(new NumberTickUnit(1));
    rangeAxis.setRange(0, columnIds.length);

    plot.setDomainAxis(rangeAxis);

    return chart;

}

From source file:org.apache.qpid.disttest.charting.chartbuilder.ChartProductionTest.java

private void assertChartTitlesAndWriteToFile(ChartBuilder builder) {
    JFreeChart chart = builder.buildChart(_chartingDefinition);
    assertEquals(TEST_CHARTTITLE, chart.getTitle().getText());
    assertEquals(TEST_CHARTSUBTITLE, ((ShortTextTitle) chart.getSubtitle(1)).getText());
    assertEquals(TEST_SERIESLEGEND, chart.getPlot().getLegendItems().get(0).getLabel());

    if (chart.getPlot() instanceof XYPlot) {
        assertEquals(1, chart.getXYPlot().getDatasetCount());
    } else {/*www .ja  v  a 2s.com*/
        assertEquals(1, chart.getCategoryPlot().getDatasetCount());
    }

    _writer.writeChartToFileSystem(chart, _chartingDefinition);
}

From source file:chart.XYChart.java

public XYChart(String applicationTitle, String chartTitle, double[] xData, double[] YDataAnalitic,
        double[] YDataNumerical1, double[] YDataNumerical2, double[] YDataNumerical3) {

    super(applicationTitle);

    JFreeChart xylineChart = ChartFactory.createXYLineChart(chartTitle, "", "",
            createDatasetForFour(xData, YDataAnalitic, YDataNumerical1, YDataNumerical2, YDataNumerical3),
            PlotOrientation.VERTICAL, true, true, false);
    ChartPanel chartPanel = new ChartPanel(xylineChart);
    chartPanel.setPreferredSize(new java.awt.Dimension(560, 367));
    final XYPlot plot = xylineChart.getXYPlot();
    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    renderer.setSeriesPaint(0, Color.RED);
    renderer.setSeriesPaint(1, Color.GREEN);
    renderer.setSeriesPaint(2, Color.YELLOW);
    renderer.setSeriesStroke(0, new BasicStroke(1.0f));
    renderer.setSeriesStroke(1, new BasicStroke(1.0f));
    renderer.setSeriesStroke(2, new BasicStroke(1.0f));
    plot.setRenderer(renderer);//from   w  ww  .ja v a2  s .  c o  m
    setContentPane(chartPanel);

    // panel.removeAll();
    //  panel.add(chartPanel);
    //  panel.validate();

}

From source file:eu.stratosphere.addons.visualization.swt.SWTGateToolTip.java

private ChartComposite createChart(GateVisualizationData visualizationData, Color backgroundColor) {

    final String yAxisLabel = this.managementGate.isInputGate() ? "No data available/sec."
            : "Capacity limit reached/sec.";

    final JFreeChart chart = ChartFactory.createXYLineChart(null, "Time [sec.]", yAxisLabel,
            visualizationData.getChartCollection(), PlotOrientation.VERTICAL, false, false, false);

    chart.setBackgroundPaint(new java.awt.Color(backgroundColor.getRed(), backgroundColor.getGreen(),
            backgroundColor.getBlue()));

    // Set axis properly
    final XYPlot xyPlot = chart.getXYPlot();
    xyPlot.getDomainAxis().setAutoRange(true);
    xyPlot.getDomainAxis().setAutoRangeMinimumSize(60);

    xyPlot.getRangeAxis().setAutoRange(true);
    // xyPlot.getRangeAxis().setRange(0, 100);

    return new ChartComposite(getShell(), SWT.NONE, chart, true);
}

From source file:org.streamspinner.harmonica.application.CQGraphTerminal.java

private JPanel getJPanel() {
    if (jPanel == null) {

        c = new TimeSeriesCollection();
        JFreeChart ch = ChartFactory.createTimeSeriesChart("", "", "", c, true, true, true);
        XYPlot plot = ch.getXYPlot();
        plot.setBackgroundPaint(Color.BLACK);
        plot.setRangeGridlinePaint(Color.WHITE);

        jPanel = new ChartPanel(ch, false);
        jPanel.setMaximumSize(new Dimension(400, Short.MAX_VALUE));
        jPanel.setPreferredSize(new Dimension(400, Short.MAX_VALUE));
    }//from  w  w  w .  j ava2  s  .  com
    return jPanel;
}

From source file:service.chart.TimeSeriesChart.java

/**
 * Utworz wykres szeregu czasowego na podstawie zestawu danych
 * /*from  ww w  . j a  v a2 s  .co  m*/
 * @param dataset Zestaw danych
 * @return Wykres szeregu czasowego
 */
private JFreeChart createChart(XYDataset dataset) {

    JFreeChart chart = ChartFactory.createTimeSeriesChart("Time series", // title
            "Date", // x-axis label
            "Value", // y-axis label
            dataset, // data
            true, // create legend?
            true, // generate tooltips?
            false // generate URLs?
    );

    chart.setBackgroundPaint(Color.white);

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

    XYItemRenderer r = plot.getRenderer();
    if (r instanceof XYLineAndShapeRenderer) {
        XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r;
        renderer.setBaseShapesVisible(false);
        renderer.setBaseShapesFilled(false);
    }

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

    return chart;
}

From source file:edu.ucla.stat.SOCR.chart.demo.CrosshairDemo4.java

/**
 * Creates a chart.//from   w  ww  . ja  v a 2  s.  c  o m
 * 
 * @param dataset  the data for the chart.
 * 
 * @return a chart.
 */
protected JFreeChart createChart(XYDataset dataset) {

    JFreeChart chart = ChartFactory.createXYLineChart(chartTitle, // chart title
            domainLabel, // x axis label
            rangeLabel, // y axis label
            dataset, // data
            PlotOrientation.VERTICAL, !legendPanelOn, // include legend
            true, // tooltips
            false // urls
    );

    chart.setBackgroundPaint(Color.white);

    XYPlot plot = chart.getXYPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);

    XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer();
    renderer.setBaseShapesVisible(true);
    renderer.setBaseShapesFilled(true);
    renderer.setLegendItemLabelGenerator(new SOCRXYSeriesLabelGenerator());

    // change the auto tick unit selection to integer units only...
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    setXSummary(dataset);
    return chart;

}

From source file:de.citec.csra.allocation.vis.MovingChart.java

/**
 * Creates a sample chart.//from  ww w . jav a2 s .co  m
 *
 * @param dataset the dataset.
 *
 * @return A sample chart.
 */
private JFreeChart createChart(final XYDataset dataset) {
    final JFreeChart result = ChartFactory.createTimeSeriesChart(null, "Time", "Resource", dataset, false, true,
            false);

    final XYPlot plot = result.getXYPlot();

    plot.addDomainMarker(this.marker);
    plot.setBackgroundPaint(new Color(0xf8f8ed));
    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 60 seconds for a time
    xaxis.setFixedAutoRange(this.past + this.future); // 60 seconds
    xaxis.setVerticalTickLabels(true);
    ValueAxis yaxis = plot.getRangeAxis();
    yaxis.setAutoRangeMinimumSize(1.8);
    yaxis.setAutoRange(true);

    NumberAxis range = (NumberAxis) plot.getRangeAxis();
    range.setTickUnit(new NumberTickUnit(1));
    range.setNumberFormatOverride(new NumberFormat() {
        @Override
        public StringBuffer format(double number, StringBuffer toAppendTo, FieldPosition pos) {
            return format((long) number, toAppendTo, pos);
        }

        private String getID(long number) {
            return values.entrySet().stream().filter(e -> e.equals(number)).findFirst().get().getKey();
        }

        @Override
        public StringBuffer format(long number, StringBuffer ap, FieldPosition pos) {
            String id = "N/A";
            if (number == 0) {
                id = "(Time)";
            }
            if (values.containsValue(number)) {
                for (Map.Entry<String, Long> entry : values.entrySet()) {
                    if (entry.getValue() == number) {
                        id = entry.getKey();
                        break;
                    }
                }
            }
            id = id.replaceFirst("/$", "");
            ap.append(id);
            if (id.length() > 32) {
                ap.replace(15, ap.length() - 15, "..");
            }
            return ap;
        }

        @Override
        public Number parse(String source, ParsePosition parsePosition) {
            return null;
        }
    });

    //      this.chart.getXYPlot().getRenderer(1).set
    //      XYLineAndShapeRenderer r = (XYLineAndShapeRenderer) this.chart.getXYPlot().getRendererForDataset(dataset);
    return result;
}

From source file:playground.christoph.evacuation.analysis.AgentsInEvacuationAreaWriter.java

/**
 * @return a graphic showing the number of agents in the evacuated area
 *//*  w w w  .  java 2s . c  om*/
private JFreeChart getGraphic(String title, String legend, String modeName, int inputData[]) {

    /*
     * Write only the number of defined picture bins to the plot.
     */
    int data[];
    if (inputData.length > this.nofPictureBins) {
        data = Arrays.copyOfRange(inputData, 0, this.nofPictureBins);
    } else
        data = inputData;

    final XYSeriesCollection xyData = new XYSeriesCollection();
    final XYSeries dataSerie = new XYSeries(legend, false, true);

    for (int i = 0; i < data.length; i++) {
        double hour = i * this.binSize / 60.0 / 60.0;
        dataSerie.add(hour, data[i]);
    }

    xyData.addSeries(dataSerie);
    final JFreeChart chart = ChartFactory.createXYStepChart(title + ", " + modeName + ", it." + this.iteration,
            "time", "# agents", xyData, PlotOrientation.VERTICAL, true, // legend
            false, // tooltips
            false // urls
    );

    XYPlot plot = chart.getXYPlot();

    final CategoryAxis axis1 = new CategoryAxis("hour");
    axis1.setTickLabelFont(new Font("SansSerif", Font.PLAIN, 7));
    plot.setDomainAxis(new NumberAxis("time"));
    return chart;
}