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:vincent.DynamicDataDemo.java

/**
 * Creates a sample chart.//from w  ww .  j  a  v a  2s.  c om
 * 
 * @param dataset the dataset.
 * @return A sample chart.
 */
private JFreeChart createChart(final XYDataset dataset) {
    final JFreeChart result = ChartFactory.createTimeSeriesChart("", "Temps", "Temprature", dataset, true,
            true, false);
    final XYPlot plot = result.getXYPlot();
    ValueAxis axis = plot.getDomainAxis();
    axis.setAutoRange(true);
    axis.setFixedAutoRange(60000.0); // 60 seconds
    axis = plot.getRangeAxis();
    axis.setRange(10.0, 50.0);// 50C
    return result;
}

From source file:dbseer.gui.chart.DBSeerChartFactory.java

public static JFreeChart createXYLineChart(String chartName, DBSeerDataSet dataset) throws Exception {
    StatisticalPackageRunner runner = DBSeerGUI.runner;

    runner.eval("[title legends Xdata Ydata Xlabel Ylabel timestamp] = plotter.plot" + chartName + ";");

    String title = runner.getVariableString("title");
    Object[] legends = (Object[]) runner.getVariableCell("legends");
    Object[] xCellArray = (Object[]) runner.getVariableCell("Xdata");
    Object[] yCellArray = (Object[]) runner.getVariableCell("Ydata");
    String xLabel = runner.getVariableString("Xlabel");
    String yLabel = runner.getVariableString("Ylabel");

    timestamp = runner.getVariableDouble("timestamp");

    XYSeriesCollection XYdataSet = new XYSeriesCollection();

    int numLegends = legends.length;
    int numXCellArray = xCellArray.length;
    int numYCellArray = yCellArray.length;
    int dataCount = 0;

    if (numXCellArray != numYCellArray) {
        JOptionPane.showMessageDialog(null, "The number of X dataset and Y dataset does not match.",
                "The number of X dataset and Y dataset does not match.", JOptionPane.ERROR_MESSAGE);
        System.out.println(numXCellArray + " : " + numYCellArray);
        return null;
    }/*from w  w w  .  ja  v a  2s.  c o  m*/

    java.util.List<String> transactionNames = dataset.getTransactionTypeNames();

    for (int i = 0; i < numLegends; ++i) {
        String legend = (String) legends[i];
        for (int j = 0; j < transactionNames.size(); ++j) {
            if (legend.contains("Type " + (j + 1))) {
                legends[i] = legend.replace("Type " + (j + 1), transactionNames.get(j));
                break;
            }
        }
    }

    for (int i = 0; i < numYCellArray; ++i) {
        double[] xArray = (double[]) xCellArray[i];
        int row = 0, col = 0;
        int xLength = 0;

        runner.eval("yArraySize = size(Ydata{" + (i + 1) + "});");
        runner.eval("yArray = Ydata{" + (i + 1) + "};");
        double[] yArraySize = runner.getVariableDouble("yArraySize");
        double[] yArray = runner.getVariableDouble("yArray");

        xLength = xArray.length;
        row = (int) yArraySize[0];
        col = (int) yArraySize[1];

        for (int c = 0; c < col; ++c) {
            XYSeries series;
            String legend = "";
            int legendIdx = (dataCount >= numLegends) ? numLegends - 1 : dataCount;
            if (legendIdx >= 0) {
                legend = (String) legends[legendIdx];
            }
            if (numLegends == 0) {
                series = new XYSeries("Data " + dataCount + 1);
            } else if (dataCount >= numLegends) {
                series = new XYSeries(legend + (dataCount + 1));
            } else {
                series = new XYSeries(legend);
            }

            for (int r = 0; r < row; ++r) {
                int xRow = (r >= xLength) ? xLength - 1 : r;
                double yValue = yArray[r + c * row];
                // remove negatives
                if (yValue < 0) {
                    yValue = 0;
                }
                series.add(xArray[xRow], yValue);
            }
            XYdataSet.addSeries(series);
            ++dataCount;
        }
    }

    JFreeChart chart = ChartFactory.createXYLineChart(title, xLabel, yLabel, XYdataSet);
    boolean isTransactionSampleChart = false;
    for (String name : DBSeerGUI.transactionSampleCharts) {
        if (name.equals(chartName)) {
            isTransactionSampleChart = true;
            break;
        }
    }

    // Renderer to highlight selected normal or outlier points.
    if (isTransactionSampleChart) {
        chart.getXYPlot().setRenderer(new DBSeerXYLineAndShapeRenderer(timestamp, dataset));
    } else {
        chart.getXYPlot().setRenderer(new DBSeerXYLineAndShapeRenderer());

    }

    chart.getXYPlot().getDomainAxis().setUpperMargin(0);

    return chart;
}

From source file:edu.cmu.sv.modelinference.eventtool.charting.DataChart.java

private JFreeChart createChart(String yLabel) {
    //Create the chart
    final JFreeChart chart = ChartFactory.createXYLineChart("Chart", "Time", yLabel, null);

    chart.setBackgroundPaint(Color.white);

    XYPlot plot = chart.getXYPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    plot.setRenderer(renderer);//from w  w  w.  j a  va  2s  .co  m

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

From source file:org.webcat.grader.graphs.HistogramChart.java

protected JFreeChart generateChart(WCChartTheme chartTheme) {
    JFreeChart chart = ChartFactory.createHistogram(null, xAxisLabel(), yAxisLabel(), intervalXYDataset(),
            orientation(), false, false, false);

    XYPlot plot = chart.getXYPlot();
    XYBarRenderer renderer = (XYBarRenderer) plot.getRenderer();
    renderer.setAutoPopulateSeriesOutlinePaint(true);
    renderer.setDrawBarOutline(true);//from www.  j a va 2s .  c o m
    renderer.setShadowVisible(false);

    if (markValue != null) {
        plot.setDomainCrosshairVisible(true);
        plot.setDomainCrosshairValue(markValue.doubleValue());
        plot.setDomainCrosshairPaint(Color.red);
        plot.setDomainCrosshairStroke(MARKER_STROKE);
    }

    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    return chart;
}

From source file:jfreeechart.DynamicDataDemo.java

/**
 * Creates a sample chart./* w w  w  .ja  v a  2s .c om*/
 * 
 * @param dataset  the dataset.
 * 
 * @return A sample chart.
 */
private JFreeChart createChart(final XYDataset dataset) {
    final JFreeChart result = ChartFactory.createTimeSeriesChart("Dynamic Data Demo", "Time", "Value", dataset,
            true, true, false);
    final XYPlot plot = result.getXYPlot();
    ValueAxis axis = plot.getDomainAxis();
    axis.setAutoRange(true);
    axis.setFixedAutoRange(60000.0); // 60 seconds
    axis = plot.getRangeAxis();
    axis.setRange(0.0, 200.0);
    return result;
}

From source file:cloud.requestengine.ResponseTimeService.java

public JFreeChart getChart() {
    JFreeChart chart = ChartFactory.createScatterPlot("Response Time", "Time (ms)", "ResponseTime (ms)",
            getDataset(), PlotOrientation.VERTICAL, true, true, false);
    final XYPlot plot = chart.getXYPlot();
    final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    renderer.setSeriesLinesVisible(0, false);
    renderer.setSeriesShapesVisible(1, false);

    Shape shape = new Rectangle2D.Double(-1, -1, 2, 2);
    renderer.setSeriesShape(0, shape);// www .j  av  a  2s .c  o  m

    plot.setRenderer(renderer);

    return chart;
}

From source file:com.graphhopper.jsprit.analysis.toolbox.XYLineChartBuilder.java

/**
 * Builds and returns JFreeChart./*from  w ww.  j  ava  2 s  . c om*/
 *
 * @return
 */
public JFreeChart build() {
    XYSeriesCollection collection = new XYSeriesCollection();
    for (XYSeries s : seriesMap.values()) {
        collection.addSeries(s);
    }
    JFreeChart chart = ChartFactory.createXYLineChart(chartName, xDomain, yDomain, collection,
            PlotOrientation.VERTICAL, true, true, false);
    XYPlot plot = chart.getXYPlot();
    plot.setBackgroundPaint(Color.WHITE);
    plot.setDomainGridlinePaint(Color.LIGHT_GRAY);
    plot.setRangeGridlinePaint(Color.LIGHT_GRAY);
    return chart;
}

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

/**
 * Creates a chart.// w w w  .  j  ava  2 s  .  c  o m
 * 
 * @param dataset  the dataset.
 * 
 * @return a chart.
 */
private JFreeChart createChart(final XYDataset dataset) {

    final JFreeChart chart = ChartFactory.createTimeSeriesChart("Time Series Demo 6", "Date", "Value", dataset,
            true, true, false);

    final XYPlot plot = chart.getXYPlot();
    final DateAxis axis = (DateAxis) plot.getDomainAxis();
    axis.setDateFormatOverride(new SimpleDateFormat("MMM-yyyy"));
    final ValueAxis rangeAxis = plot.getRangeAxis();
    rangeAxis.setAutoRangeMinimumSize(1.0);
    return chart;

}

From source file:org.encog.workbench.tabs.visualize.weights.AnalyzeWeightsTab.java

/**
 * Creates a chart./*  w w  w . j  a  v  a  2s  .co  m*/
 * 
 * @param dataset  a dataset.
 * 
 * @return The chart.
 */
private JFreeChart createChart(IntervalXYDataset dataset) {
    JFreeChart chart = ChartFactory.createHistogram(null, null, null, dataset, PlotOrientation.VERTICAL, true,
            false, false);
    chart.getXYPlot().setForegroundAlpha(0.75f);
    return chart;
}

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

/**
 * Creates a new chart.// ww  w .j a  v  a2 s .  c  o  m
 * 
 * @param dataset  the dataset.
 * 
 * @return The dataset.
 */
private JFreeChart createChart(final XYDataset dataset) {
    final JFreeChart chart = ChartFactory.createTimeSeriesChart("Time Series Demo 3", "Time", "Value", dataset,
            true, true, false);
    final XYPlot plot = chart.getXYPlot();
    final DateAxis axis = (DateAxis) plot.getDomainAxis();
    axis.setTickUnit(new DateTickUnit(DateTickUnit.MONTH, 1, new SimpleDateFormat("MMM-yyyy")));
    axis.setVerticalTickLabels(true);

    final StandardXYItemRenderer renderer = (StandardXYItemRenderer) plot.getRenderer();
    renderer.setPlotShapes(true);
    renderer.setSeriesShapesFilled(0, Boolean.TRUE);
    renderer.setSeriesShapesFilled(1, Boolean.FALSE);

    return chart;
}