Example usage for org.jfree.chart.plot XYPlot mapDatasetToRangeAxis

List of usage examples for org.jfree.chart.plot XYPlot mapDatasetToRangeAxis

Introduction

In this page you can find the example usage for org.jfree.chart.plot XYPlot mapDatasetToRangeAxis.

Prototype

public void mapDatasetToRangeAxis(int index, int axisIndex) 

Source Link

Document

Maps a dataset to a particular range axis.

Usage

From source file:org.encog.workbench.dialogs.training.ChartPane.java

/**
 * Create the initial chart./*from   ww w  .  jav a  2 s .co  m*/
 * @return The chart.
 */
private JFreeChart createChart() {

    this.chart = ChartFactory.createXYLineChart(null, "Iteration", "Current Error", this.dataset1,
            PlotOrientation.VERTICAL, true, true, false);

    final XYPlot plot = (XYPlot) this.chart.getPlot();
    plot.setOrientation(PlotOrientation.VERTICAL);

    plot.getRangeAxis().setFixedDimension(15.0);

    // AXIS 2
    final NumberAxis axis2 = new NumberAxis("Error Improvement");
    axis2.setFixedDimension(10.0);
    axis2.setAutoRangeIncludesZero(false);
    axis2.setLabelPaint(Color.red);
    axis2.setTickLabelPaint(Color.red);
    plot.setRangeAxis(1, axis2);
    plot.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_RIGHT);

    plot.setDataset(1, this.dataset2);
    plot.mapDatasetToRangeAxis(1, 1);
    final XYItemRenderer renderer2 = new StandardXYItemRenderer();
    renderer2.setSeriesPaint(0, Color.red);
    plot.setRenderer(1, renderer2);

    ChartUtilities.applyCurrentTheme(this.chart);

    return this.chart;
}

From source file:com.seagate.kinetic.monitor.view.KineticSpecifiedNodeView.java

private void createStatChart() {
    TimeSeriesCollection putOpsTsc = new TimeSeriesCollection(putOpsTs);
    TimeSeriesCollection putTrgTsc = new TimeSeriesCollection(putTrgTs);
    TimeSeriesCollection getOpsTsc = new TimeSeriesCollection(getOpsTs);
    TimeSeriesCollection getTrgTsc = new TimeSeriesCollection(getTrgTs);
    TimeSeriesCollection deleteOpsTsc = new TimeSeriesCollection(deleteOpsTs);
    TimeSeriesCollection deleteTrgTsc = new TimeSeriesCollection(deleteTrgTs);

    statChart = ChartFactory.createTimeSeriesChart("", "Time", "put kvop/s", putOpsTsc, true, true, false);
    XYPlot xyplot = (XYPlot) statChart.getPlot();
    xyplot.setOrientation(PlotOrientation.VERTICAL);
    xyplot.setDomainPannable(true);// w ww .ja va2 s. com
    xyplot.setRangePannable(true);

    ValueAxis yAxis = xyplot.getDomainAxis();
    yAxis.setAutoRange(true);
    yAxis.setFixedAutoRange(60000.0);

    NumberAxis numberaxis1 = new NumberAxis("get kvop/s");
    xyplot.setRangeAxis(1, numberaxis1);
    xyplot.setDataset(1, getOpsTsc);
    xyplot.mapDatasetToRangeAxis(1, 1);
    StandardXYItemRenderer standardxyitemrenderer1 = new StandardXYItemRenderer();
    xyplot.setRenderer(1, standardxyitemrenderer1);

    NumberAxis numberaxis2 = new NumberAxis("delete kvop/s");
    numberaxis2.setAutoRangeIncludesZero(false);
    xyplot.setRangeAxis(2, numberaxis2);
    xyplot.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_LEFT);
    xyplot.setDataset(2, deleteOpsTsc);
    xyplot.mapDatasetToRangeAxis(2, 2);
    StandardXYItemRenderer standardxyitemrenderer2 = new StandardXYItemRenderer();
    xyplot.setRenderer(2, standardxyitemrenderer2);

    NumberAxis numberaxis3 = new NumberAxis("put MB/s");
    xyplot.setRangeAxis(3, numberaxis3);
    xyplot.setDataset(3, putTrgTsc);
    xyplot.mapDatasetToRangeAxis(3, 3);
    StandardXYItemRenderer standardxyitemrenderer3 = new StandardXYItemRenderer();
    xyplot.setRenderer(3, standardxyitemrenderer3);

    NumberAxis numberaxis4 = new NumberAxis("get MB/s");
    numberaxis4.setAutoRangeIncludesZero(false);
    xyplot.setRangeAxis(4, numberaxis4);
    xyplot.setRangeAxisLocation(2, AxisLocation.BOTTOM_OR_LEFT);
    xyplot.setDataset(4, getTrgTsc);
    xyplot.mapDatasetToRangeAxis(4, 4);
    StandardXYItemRenderer standardxyitemrenderer4 = new StandardXYItemRenderer();
    xyplot.setRenderer(4, standardxyitemrenderer4);

    NumberAxis numberaxis5 = new NumberAxis("delete MB/s");
    xyplot.setRangeAxis(5, numberaxis5);
    xyplot.setDataset(5, deleteTrgTsc);
    xyplot.mapDatasetToRangeAxis(5, 5);
    StandardXYItemRenderer standardxyitemrenderer5 = new StandardXYItemRenderer();
    xyplot.setRenderer(5, standardxyitemrenderer5);

    ChartUtilities.applyCurrentTheme(statChart);
    xyplot.getRenderer().setSeriesPaint(0, Color.black);
    standardxyitemrenderer1.setSeriesPaint(0, Color.red);
    numberaxis1.setLabelPaint(Color.red);
    numberaxis1.setTickLabelPaint(Color.red);
    standardxyitemrenderer2.setSeriesPaint(0, Color.green);
    numberaxis2.setLabelPaint(Color.green);
    numberaxis2.setTickLabelPaint(Color.green);
    standardxyitemrenderer3.setSeriesPaint(0, Color.orange);
    numberaxis3.setLabelPaint(Color.orange);
    numberaxis3.setTickLabelPaint(Color.orange);
    standardxyitemrenderer4.setSeriesPaint(0, Color.blue);
    numberaxis4.setLabelPaint(Color.blue);
    numberaxis4.setTickLabelPaint(Color.blue);
    standardxyitemrenderer5.setSeriesPaint(0, Color.cyan);
    numberaxis5.setLabelPaint(Color.cyan);
    numberaxis5.setTickLabelPaint(Color.cyan);

    final JPanel main = new JPanel(new BorderLayout());
    final JPanel optionsPanel = new JPanel();

    String[] options = { SYSTEM_TOTAL_IOPS_AND_THROUGHPUT_STATISTICS };
    this.orientationComboBox = new JComboBox<String>(options);
    this.orientationComboBox.setSize(600, 50);
    this.orientationComboBox.addActionListener(this);
    optionsPanel.add(this.orientationComboBox);

    chartPanel = new ChartPanel(statChart);
    chartPanel.setMouseWheelEnabled(false);
    chartPanel.setPreferredSize(new Dimension(900, 450));
    chartPanel.setDomainZoomable(true);
    chartPanel.setRangeZoomable(true);

    main.add(optionsPanel, BorderLayout.NORTH);
    main.add(this.chartPanel);
    setContentPane(main);
}

From source file:de.suse.swamp.modules.scheduledjobs.Statistics.java

/**
 * Generating the graphs that show the amount of running finished wfs over the time.
 *///from   w  ww . ja  va2  s.c  om
protected void generateWorkflowGraph(String templateName, Date startDate, Date endDate) throws Exception {
    List stats = StatisticStorage.loadStats(templateName, startDate, endDate);
    // only generate if we have stats: 
    if (stats != null && stats.size() > 0) {
        TimeSeriesCollection dataset = new TimeSeriesCollection();
        TimeSeriesCollection avgdataset = new TimeSeriesCollection();
        TimeSeries serie = new TimeSeries("running workflows", Day.class);
        TimeSeries avgserie = new TimeSeries("average age", Day.class);
        for (Iterator datait = stats.iterator(); datait.hasNext();) {
            Dbstatistics statisticItem = (Dbstatistics) datait.next();
            serie.addOrUpdate(new Day(statisticItem.getDate()), statisticItem.getRunningcount());
            avgserie.addOrUpdate(new Day(statisticItem.getDate()), statisticItem.getAvgage() / (3600 * 24));
        }
        dataset.addSeries(serie);
        avgdataset.addSeries(avgserie);

        JFreeChart chart = ChartFactory.createTimeSeriesChart("Running " + templateName + " workflows", "Date",
                "running workflows", dataset, false, false, false);

        // modify chart appearance
        chart.setBackgroundImageAlpha(0.5f);
        XYPlot plot = chart.getXYPlot();
        plot.setBackgroundPaint(Color.lightGray);
        plot.setDomainGridlinePaint(Color.white);
        plot.setRangeGridlinePaint(Color.white);
        plot.getRangeAxis().setLabelPaint(Color.blue);

        // add the second line: 
        final NumberAxis axis2 = new NumberAxis("Avg. age in days");
        axis2.setLabelPaint(Color.red);
        plot.setRangeAxis(1, axis2);
        plot.setDataset(1, avgdataset);
        plot.mapDatasetToRangeAxis(1, 1);

        final XYLineAndShapeRenderer renderer2 = new XYLineAndShapeRenderer();
        renderer2.setDrawOutlines(false);
        renderer2.setDrawSeriesLineAsPath(true);
        renderer2.setBaseShapesVisible(false);
        plot.setRenderer(1, renderer2);

        File image = new File(statPath + fs + templateName + ".png");
        if (image.exists())
            image.delete();
        try {
            ChartUtilities.saveChartAsPNG(image, chart, 750, 200);
        } catch (Exception e) {
            Logger.ERROR("Error generating graph for " + templateName + ", e: " + e.getMessage());
            e.printStackTrace();
            throw e;
        }
    }
}

From source file:no.met.jtimeseries.netcdf.plot.SimplePlotProvider.java

@Override
public XYPlot getPlot(List<NumberPhenomenon> dataList) {

    XYPlot plot = new XYPlot();

    plot.setDomainAxis(getDomainAxis(dataList));

    Map<String, Integer> axes = createRangeAxes(dataList, plot);

    for (int i = 0; i < dataList.size(); i++) {
        NumberPhenomenon phenomenon = dataList.get(i);
        //addTimeSeries(plot, phenomenon, i, colors[i % colors.length]);

        plot.setDataset(i, getTimeSeries(phenomenon));
        plot.setRenderer(i, new XYSplineRenderer());
        plot.getRenderer(i).setSeriesPaint(0, colors[i % colors.length]);

        plot.mapDatasetToRangeAxis(i, axes.get(phenomenon.getPhenomenonUnit()));
    }/*from  ww  w.j  ava 2  s .  com*/

    return plot;
}

From source file:ca.nengo.plot.impl.DefaultPlotter.java

private void doPlot(float[] x, float[][] ideal, float[][] actual, int dim) {
    XYSeriesCollection dataset = new XYSeriesCollection();

    XYSeries idealSeries = new XYSeries("Ideal");
    for (int i = 0; i < x.length; i++) {
        idealSeries.add(x[i], ideal[i][dim]);
    }/*from ww  w . ja va  2 s .  c om*/
    dataset.addSeries(idealSeries);

    XYSeries actualSeries = new XYSeries("Actual");
    for (int i = 0; i < x.length; i++) {
        actualSeries.add(x[i], actual[i][dim]);
    }
    dataset.addSeries(actualSeries);

    JFreeChart chart = ChartFactory.createXYLineChart("Distortion", "X", "Estimate", dataset,
            PlotOrientation.VERTICAL, true, false, false);

    XYSeries errorSeries = new XYSeries("Error");
    float[][] error = MU.difference(actual, ideal);
    for (int i = 0; i < x.length; i++) {
        //         errorSeries.add(x[i], actual[i][dim] - ideal[i][dim]);
        errorSeries.add(x[i], error[i][dim]);
    }
    XYSeriesCollection errorDataset = new XYSeriesCollection();
    errorDataset.addSeries(errorSeries);
    NumberAxis errorAxis = new NumberAxis("Error");
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setRangeAxis(1, errorAxis);
    plot.setRangeAxisLocation(AxisLocation.TOP_OR_RIGHT);
    plot.setDataset(1, errorDataset);
    plot.mapDatasetToRangeAxis(1, 1);
    XYItemRenderer renderer = new XYLineAndShapeRenderer(true, false);
    plot.setRenderer(1, renderer);

    float[] err = MU.transpose(error)[dim];
    float mse = MU.prod(err, err) / (float) err.length;
    showChart(chart, "Distortion Error Plot (MSE=" + mse + ")");
}

From source file:controletanquesproj1.Grafico.java

/**
 * Creates a chart./*ww w . j a  v a 2s .c o m*/
 * 
 * @param _datasets
 * @param datasets
 * @param dataset  the data for the chart.
 * 
 * @return a chart.
 */
public JFreeChart createChart() {

    // create the chart...
    final JFreeChart chart = ChartFactory.createXYLineChart("", // chart title
            "Amostra", // x axis label
            "Amplitude (V)", // y axis label
            getDatasets()[0], // data
            PlotOrientation.VERTICAL, true, // include legend
            true, // tooltips
            false // urls
    );

    // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...
    chart.setBackgroundPaint(Color.white);

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

    // get a reference to the plot for further customisation...
    final XYPlot plot = chart.getXYPlot();
    plot.setBackgroundPaint(Color.white);
    //    plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0));
    plot.setDomainGridlinePaint(Color.black);
    plot.setRangeGridlinePaint(Color.black);
    plot.getRangeAxis(0).setRange(-30, 30);

    final NumberAxis axis2 = new NumberAxis("Altura (cm)");
    axis2.setAutoRange(true);
    axis2.setAutoRangeIncludesZero(false);

    //axis2.setRange(-4.9, 34.9);
    plot.setRangeAxis(1, axis2);
    plot.setDataset(1, getDatasets()[1]);
    plot.mapDatasetToRangeAxis(1, 1);

    /*
    getRenderer().setSeriesLinesVisible(0, true);
    getRenderer().setSeriesShapesVisible(0, false);
    getRenderer().setSeriesShapesVisible(1, false);
    getRenderer().setSeriesShapesVisible(2, false);
    getRenderer().setSeriesLinesVisible(3, true);
    getRenderer().setSeriesShapesVisible(3, false);
    */

    renderer[0].setBaseShapesVisible(false);
    renderer[0].setAutoPopulateSeriesPaint(true);

    plot.setRenderer(renderer[0]);

    renderer[1] = new XYLineAndShapeRenderer();
    renderer[1].setBaseLinesVisible(true);
    renderer[1].setBaseShapesVisible(true);

    plot.setRenderer(1, renderer[1]);

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

    return chart;

}

From source file:com.fr3ts0n.ecu.gui.application.ObdDataPlotter.java

/**
 * add a new series to the graph/*w  ww  .  j  av  a2s . c  om*/
 *
 * @param series The new series to be added
 */
public synchronized void addSeries(TimeSeries series) {

    if (oneRangePerSeries) {
        // get paint for current axis/range/...
        Paint currPaint = DefaultDrawingSupplier.DEFAULT_PAINT_SEQUENCE[raIndex
                % DefaultDrawingSupplier.DEFAULT_PAINT_SEQUENCE.length];

        XYPlot plot = (XYPlot) chart.getPlot();
        // set dataset
        plot.setDataset(raIndex, new TimeSeriesCollection(series));
        // ** set axis
        NumberAxis axis = new NumberAxis();
        axis.setTickLabelFont(legendFont);
        axis.setAxisLinePaint(currPaint);
        axis.setTickLabelPaint(currPaint);
        axis.setTickMarkPaint(currPaint);
        // ** set axis in plot
        plot.setRangeAxis(raIndex, axis);
        plot.setRangeAxisLocation(raIndex,
                raIndex % 2 == 0 ? AxisLocation.TOP_OR_LEFT : AxisLocation.BOTTOM_OR_RIGHT);
        plot.mapDatasetToRangeAxis(raIndex, raIndex);
        // ** create renderer
        XYItemRenderer renderer = new XYLineAndShapeRenderer(true, false);
        renderer.setBaseToolTipGenerator(toolTipGen);
        renderer.setSeriesPaint(0, currPaint);
        // ** set renderer in plot
        plot.setRenderer(raIndex, renderer);

        raIndex++;
    }
    dataset.addSeries(series);
}

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

/**
 * Constructs a new demonstration application.
 *
 * @param title  the frame title./*from   w w w  . j av  a2  s  .  com*/
 */
public DynamicDataDemo2(final String title) {

    super(title);
    this.series1 = new TimeSeries("Random 1", Millisecond.class);
    this.series2 = new TimeSeries("Random 2", Millisecond.class);
    final TimeSeriesCollection dataset1 = new TimeSeriesCollection(this.series1);
    final TimeSeriesCollection dataset2 = new TimeSeriesCollection(this.series2);
    final JFreeChart chart = ChartFactory.createTimeSeriesChart("Dynamic Data Demo 2", "Time", "Value",
            dataset1, true, true, false);
    chart.setBackgroundPaint(Color.white);

    final XYPlot 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));
    final ValueAxis axis = plot.getDomainAxis();
    axis.setAutoRange(true);
    axis.setFixedAutoRange(60000.0); // 60 seconds

    plot.setDataset(1, dataset2);
    final NumberAxis rangeAxis2 = new NumberAxis("Range Axis 2");
    rangeAxis2.setAutoRangeIncludesZero(false);
    plot.setRenderer(1, new DefaultXYItemRenderer());
    plot.setRangeAxis(1, rangeAxis2);
    plot.mapDatasetToRangeAxis(1, 1);

    final JPanel content = new JPanel(new BorderLayout());

    final ChartPanel chartPanel = new ChartPanel(chart);
    content.add(chartPanel);

    final JButton button1 = new JButton("Add To Series 1");
    button1.setActionCommand("ADD_DATA_1");
    button1.addActionListener(this);

    final JButton button2 = new JButton("Add To Series 2");
    button2.setActionCommand("ADD_DATA_2");
    button2.addActionListener(this);

    final JButton button3 = new JButton("Add To Both");
    button3.setActionCommand("ADD_BOTH");
    button3.addActionListener(this);

    final JPanel buttonPanel = new JPanel(new FlowLayout());
    buttonPanel.add(button1);
    buttonPanel.add(button2);
    buttonPanel.add(button3);

    content.add(buttonPanel, BorderLayout.SOUTH);
    chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
    setContentPane(content);

}

From source file:be.nbb.demetra.dfm.output.simulation.RealTimePerspGraphView.java

private JFreeChart createChart() {
    XYPlot plot = new XYPlot();

    plot.setDataset(TRUE_DATA_INDEX, Charts.emptyXYDataset());
    plot.setRenderer(TRUE_DATA_INDEX, trueDataRenderer);
    plot.mapDatasetToDomainAxis(TRUE_DATA_INDEX, 0);
    plot.mapDatasetToRangeAxis(TRUE_DATA_INDEX, 0);

    plot.setDataset(FCTS_INDEX, Charts.emptyXYDataset());
    plot.setRenderer(FCTS_INDEX, forecastsRenderer);
    plot.mapDatasetToDomainAxis(FCTS_INDEX, 0);
    plot.mapDatasetToRangeAxis(FCTS_INDEX, 0);

    plot.setDataset(ARIMA_DATA_INDEX, Charts.emptyXYDataset());
    plot.setRenderer(ARIMA_DATA_INDEX, arimaRenderer);
    plot.mapDatasetToDomainAxis(ARIMA_DATA_INDEX, 0);
    plot.mapDatasetToRangeAxis(ARIMA_DATA_INDEX, 0);

    plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);

    JFreeChart result = new JFreeChart("", TsCharts.CHART_TITLE_FONT, plot, false);
    result.setPadding(TsCharts.CHART_PADDING);
    return result;
}

From source file:be.nbb.demetra.dfm.output.simulation.RMSEGraphView.java

private JFreeChart createChart() {
    JFreeChart result = ChartFactory.createXYBarChart("", "", false, "", Charts.emptyXYDataset(),
            PlotOrientation.VERTICAL, false, false, false);
    result.setPadding(TsCharts.CHART_PADDING);
    result.getTitle().setFont(TsCharts.CHART_TITLE_FONT);

    XYPlot plot = result.getXYPlot();

    plot.setDataset(DFM_INDEX, Charts.emptyXYDataset());
    plot.setRenderer(DFM_INDEX, dfmRenderer);
    plot.mapDatasetToDomainAxis(DFM_INDEX, 0);
    plot.mapDatasetToRangeAxis(DFM_INDEX, 0);

    plot.setDataset(ARIMA_INDEX, Charts.emptyXYDataset());
    plot.setRenderer(ARIMA_INDEX, arimaRenderer);
    plot.mapDatasetToDomainAxis(ARIMA_INDEX, 0);
    plot.mapDatasetToRangeAxis(ARIMA_INDEX, 0);

    plot.setDataset(STDEV_INDEX, Charts.emptyXYDataset());
    plot.setRenderer(STDEV_INDEX, stdevRenderer);
    plot.mapDatasetToDomainAxis(STDEV_INDEX, 0);
    plot.mapDatasetToRangeAxis(STDEV_INDEX, 0);

    plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);

    NumberAxis rangeAxis = new NumberAxis();
    rangeAxis.setAutoRangeIncludesZero(false);
    rangeAxis.setTickLabelPaint(TsCharts.CHART_TICK_LABEL_COLOR);
    plot.setRangeAxis(rangeAxis);//from   ww  w  . j av  a  2  s. co  m

    NumberAxis domainAxis = new NumberAxis();
    domainAxis.setAutoRangeIncludesZero(false);
    domainAxis.setTickLabelPaint(TsCharts.CHART_TICK_LABEL_COLOR);
    plot.setDomainAxis(domainAxis);

    return result;
}