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:osh.comdriver.simulation.cruisecontrol.AbstractDrawer.java

/**
 * Creates a chart.//from  w w  w  .j a va2 s .  c  o m
 *
 * @param dataset1  a dataset.
 *
 * @return A chart.
 */
private JFreeChart createChart(XYDataset dataset, long lastentry) {

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

    chart.setBackgroundPaint(Color.white);

    XYPlot plot = (XYPlot) chart.getPlot();

    NumberAxis axis1 = new NumberAxis(getAxisName());
    axis1.setAutoRangeIncludesZero(isIncludeZero());
    plot.setRangeAxis(0, axis1);

    plot.setDataset(0, dataset);
    plot.mapDatasetToRangeAxis(1, 0);

    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);
    //TODO: SHADOWS OFF

    final StandardXYItemRenderer r1 = new StandardXYItemRenderer();
    plot.setRenderer(0, r1);
    r1.setSeriesPaint(0, Color.BLUE);
    r1.setSeriesPaint(1, Color.RED);
    r1.setSeriesPaint(2, Color.GREEN);

    //plot.setDomainAxis(new NumberAxis("time"));
    plot.setDomainAxis(new DateAxis());
    plot.getDomainAxis().setAutoRange(false);

    long begin = getRangeBegin(lastentry);
    long end = getRangeEnd(lastentry);

    plot.getDomainAxis().setRange(begin, end);

    return chart;
}

From source file:org.ow2.clif.jenkins.chart.MovingStatChart.java

private void attachThroughputDatasetToDedicatedAxis(XYSeriesCollection throughputDataset, XYPlot plot) {
    NumberAxis throughputAxis = new NumberAxis(Messages.MovingChart_Throughput());
    plot.setRangeAxis(1, throughputAxis);
    plot.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_RIGHT);
    plot.setDataset(1, throughputDataset);
    plot.mapDatasetToDomainAxis(1, 0);/* w  ww .j a  v a2 s .  c o m*/
    plot.mapDatasetToRangeAxis(1, 1);
}

From source file:com.philng.telemetrydisplay.GraphDisplay.java

/**
 * Create the chart itself with datasets
 * @param dataset/*from   www  . jav  a2s . c  om*/
 * @return
 */
private JFreeChart createChart(final XYDataset dataset) {
    final JFreeChart result = ChartFactory.createTimeSeriesChart("Telemetry Display", "Time", "Voltage",
            dataset, true, true, false);
    final XYPlot plot = result.getXYPlot();

    // Add in a new y axis for current
    ValueAxis currentAxis = new NumberAxis();
    currentAxis.setRange(0, 100);
    currentAxis.setLabel("Current");

    plot.setRangeAxis(1, currentAxis);
    plot.setDataset(1, createDatasetCurrent());
    plot.mapDatasetToRangeAxis(1, 1);

    // Set information for the x axis (time)
    ValueAxis axis = plot.getDomainAxis();
    axis.setAutoRange(true);

    // Set the information for the voltage axis
    axis = plot.getRangeAxis();
    axis.setAutoRange(false);
    axis.setRange(0.0, 12.0);

    final XYItemRenderer renderer = plot.getRenderer();
    renderer.setToolTipGenerator(StandardXYToolTipGenerator.getTimeSeriesInstance());
    if (renderer instanceof StandardXYItemRenderer) {
        final StandardXYItemRenderer rr = (StandardXYItemRenderer) renderer;
        rr.setShapesFilled(true);
    }

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

    return result;
}

From source file:org.sunzoft.sunstock.StockMain.java

protected void addIndexChart(XYPlot xyplot) {
    NumberAxis localNumberAxis1 = new NumberAxis("");
    //localNumberAxis1.setLabelPaint(Color.red);
    //localNumberAxis1.setTickLabelPaint(Color.red);        
    xyplot.setRangeAxis(1, localNumberAxis1);
    xyplot.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_RIGHT);
    xyplot.setDataset(1, initIndexData());
    xyplot.mapDatasetToRangeAxis(1, 1);
}

From source file:graph.MySensorPanel.java

/**
 * Creates a new self-contained demo panel.
 *///  w w  w  .  ja v  a  2 s .c o m
public MySensorPanel(String header_str) {
    //super(new BorderLayout());
    this.series1 = new TimeSeries("Temperature");
    this.series2 = new TimeSeries("Humidity");
    TimeSeriesCollection dataset1 = new TimeSeriesCollection(this.series1);
    TimeSeriesCollection dataset2 = new TimeSeriesCollection(this.series2);

    JFreeChart chart = ChartFactory.createTimeSeriesChart(header_str, "Time", "C", dataset1, true, true,
            false);

    /*this.addChart(chart);*/

    XYPlot plot = (XYPlot) chart.getPlot();
    ValueAxis axis = plot.getDomainAxis();
    axis.setAutoRange(true);
    axis.setFixedAutoRange(1000.0 * 60 * 60 /* 24*/); // 24 hrs

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

    ChartUtilities.applyCurrentTheme(chart);
    plot.setBackgroundPaint(Color.DARK_GRAY);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

    chartPanel = new ChartPanel(chart);
}

From source file:com.bt.aloha.sipstone.GenGraph.java

private JFreeChart createCombinedChart() {
    XYDataset xydatasetArray[] = createDataset_TotalCallCreated_CallsPerSecond();
    XYDataset xydataset = xydatasetArray[0];
    final XYDataset percXydataset = xydatasetArray[1];
    JFreeChart jfreechart = ChartFactory.createXYLineChart("SIPStone graph", "Calls", "Call rate", xydataset,
            PlotOrientation.VERTICAL, false, true, false);
    XYPlot xyplot = (XYPlot) jfreechart.getPlot();
    NumberAxis numberaxis = new NumberAxis("Avg. Response Time");
    numberaxis.setAutoRangeIncludesZero(false);
    xyplot.setRangeAxis(1, numberaxis);//w  w  w .  j  av  a2 s . co m
    xyplot.setDataset(1, createDataset_TotalCallCreated_AvgResponseTime());
    xyplot.mapDatasetToRangeAxis(1, 1);
    XYItemRenderer xyitemrenderer = xyplot.getRenderer();
    xyitemrenderer.setBaseToolTipGenerator(StandardXYToolTipGenerator.getTimeSeriesInstance());
    if (xyitemrenderer instanceof XYLineAndShapeRenderer) {
        XYLineAndShapeRenderer xylineandshaperenderer = (XYLineAndShapeRenderer) xyitemrenderer;
        xylineandshaperenderer.setBaseShapesVisible(true);
        xylineandshaperenderer.setShapesFilled(true);
    }
    XYLineAndShapeRenderer xylineandshaperenderer1 = new XYLineAndShapeRenderer();
    xylineandshaperenderer1.setSeriesPaint(0, Color.black);
    xylineandshaperenderer1.setBaseShapesVisible(true);
    xylineandshaperenderer1.setBaseToolTipGenerator(StandardXYToolTipGenerator.getTimeSeriesInstance());
    xyplot.setRenderer(1, xylineandshaperenderer1);
    NumberAxis timeaxis = (NumberAxis) xyplot.getDomainAxis();
    timeaxis.setAutoRange(true);
    timeaxis.setAxisLineVisible(true);
    LegendTitle legendtitle = new LegendTitle(xyitemrenderer);
    LegendTitle legendtitle1 = new LegendTitle(xylineandshaperenderer1);
    BlockContainer blockcontainer = new BlockContainer(new BorderArrangement());
    blockcontainer.add(legendtitle, RectangleEdge.LEFT);
    blockcontainer.add(legendtitle1, RectangleEdge.RIGHT);
    blockcontainer.add(new EmptyBlock(2000D, 0.0D));

    XYItemRenderer xyrenderer = (XYItemRenderer) xyplot.getRenderer();
    xyrenderer.setBaseItemLabelGenerator(new MyXYItemLabelGenerator(percXydataset));
    xyrenderer.setBaseItemLabelsVisible(true);

    CompositeTitle compositetitle = new CompositeTitle(blockcontainer);
    compositetitle.setPosition(RectangleEdge.BOTTOM);
    jfreechart.addSubtitle(compositetitle);
    return jfreechart;
}

From source file:org.signserver.client.cli.performance.PerformanceTestPDFServlet.java

License:asdf

/**
 * Create and write diagrams to disk./* w  w  w.ja va  2s  .  co m*/
 */
private void createDiagram(String statisticsDirectory, ArrayList<String> explanationRow,
        ArrayList<ArrayList<Double>> processedData, int xRow, int y1Row, int y2Row) {
    final XYSeries s1 = new XYSeries(explanationRow.get(y1Row));
    final XYSeries s2 = new XYSeries(explanationRow.get(y2Row));
    for (ArrayList<Double> currentRow : processedData) {
        s1.add(currentRow.get(xRow), currentRow.get(y1Row));
        s2.add(currentRow.get(xRow), currentRow.get(y2Row));
    }
    final XYSeriesCollection dataset1 = new XYSeriesCollection();
    dataset1.addSeries(s1);
    final XYSeriesCollection dataset2 = new XYSeriesCollection();
    dataset2.addSeries(s2);
    final JFreeChart chart = ChartFactory.createXYLineChart("Test result " + xRow + "" + y1Row + "" + y2Row,
            explanationRow.get(xRow), explanationRow.get(y1Row), dataset1, PlotOrientation.VERTICAL, true, true,
            false);
    final XYPlot plot = chart.getXYPlot();
    if (y1Row == COLUMN_INVOCATIONS_PER_SECOND) {
        final NumberAxis axis1 = new LogarithmicAxis(explanationRow.get(y1Row));
        plot.setRangeAxis(0, axis1);
    }
    final NumberAxis axis2 = new NumberAxis(explanationRow.get(y2Row));
    axis2.setAutoRangeIncludesZero(false);
    plot.setRangeAxis(1, axis2);
    plot.setDataset(1, dataset2);
    plot.mapDatasetToRangeAxis(1, 1);
    final StandardXYItemRenderer renderer2 = new StandardXYItemRenderer();
    renderer2.setSeriesPaint(0, Color.BLUE);
    plot.setRenderer(1, renderer2);
    final ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());
    final File file = new File(
            statisticsDirectory + "PDF Signatures" + "-" + xRow + "" + y1Row + "" + y2Row + ".png");
    int imageWidth = 800;
    int imageHeight = 600;
    try {
        System.out.println("Writing diagram to " + file.getName());
        System.out.flush();
        ChartUtilities.saveChartAsPNG(file, chart, imageWidth, imageHeight, info);
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:com.trivadis.loganalysis.ui.ChartPanel.java

private void add(final Serie serie) {
    if (!isDisposed()) {
        serie.setIndex(seriesSequence.get());
        final XYSeriesCollection dataset = new XYSeriesCollection(datasetProvider.getDataset(jvm, serie));
        final int index = serie.getIndex();
        final XYPlot plot = (XYPlot) jfreeChart.getPlot();
        final Color color = getColor(index);
        removeDataset(index, plot);/*from w  w  w . j a  va  2s .  c  om*/
        plot.setDataset(index, dataset);
        plot.setRangeAxis(index, axis(color, serie.getYaxis().getValueProvider().getUnit()));
        plot.setDomainAxis(index, axis(color, serie.getXaxis().getValueProvider().getUnit()));
        plot.mapDatasetToDomainAxis(index, index);
        plot.mapDatasetToRangeAxis(index, index);
        plot.setRenderer(index, getRenderer(color, serie.isDotted()));
        seriesSequence.incrementAndGet();
    }
}

From source file:ec.ui.view.StabilityView.java

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

    plot.setDataset(SMOOTH_INDEX, Charts.emptyXYDataset());
    plot.setRenderer(SMOOTH_INDEX, smoothRenderer);
    plot.mapDatasetToDomainAxis(SMOOTH_INDEX, 0);
    plot.mapDatasetToRangeAxis(SMOOTH_INDEX, 0);

    plot.setDataset(MEAN_INDEX, Charts.emptyXYDataset());
    plot.setRenderer(MEAN_INDEX, meanRenderer);
    plot.mapDatasetToDomainAxis(MEAN_INDEX, 0);
    plot.mapDatasetToRangeAxis(MEAN_INDEX, 0);

    plot.setDataset(POINTS_INDEX, Charts.emptyXYDataset());
    plot.setRenderer(POINTS_INDEX, pointsRenderer);
    plot.mapDatasetToDomainAxis(POINTS_INDEX, 0);
    plot.mapDatasetToRangeAxis(POINTS_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:org.jfree.chart.demo.CombinedXYPlotDemo4.java

/**
 * Creates a combined chart.//from   w  ww.ja  v  a2 s .c  o m
 *
 * @return The combined chart.
 */
private JFreeChart createCombinedChart() {

    // create subplot 1...
    final XYDataset data1 = createDataset1();
    final XYItemRenderer renderer1 = new StandardXYItemRenderer();
    final NumberAxis rangeAxis1 = new NumberAxis("Range 1");
    final XYPlot subplot1 = new XYPlot(data1, null, rangeAxis1, renderer1);
    subplot1.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);

    // add secondary axis
    subplot1.setDataset(1, createDataset2());
    final NumberAxis axis2 = new NumberAxis("Range Axis 2");
    axis2.setAutoRangeIncludesZero(false);
    subplot1.setRangeAxis(1, axis2);
    subplot1.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_RIGHT);
    subplot1.setRenderer(1, new StandardXYItemRenderer());
    subplot1.mapDatasetToRangeAxis(1, 1);

    final XYTextAnnotation annotation = new XYTextAnnotation("Hello!", 50.0, 10000.0);
    annotation.setFont(new Font("SansSerif", Font.PLAIN, 9));
    annotation.setRotationAngle(Math.PI / 4.0);
    subplot1.addAnnotation(annotation);

    // create subplot 2...
    final XYDataset data2 = createDataset2();
    final XYItemRenderer renderer2 = new StandardXYItemRenderer();
    final NumberAxis rangeAxis2 = new NumberAxis("Range 2");
    rangeAxis2.setAutoRangeIncludesZero(false);
    final XYPlot subplot2 = new XYPlot(data2, null, rangeAxis2, renderer2);
    subplot2.setRangeAxisLocation(AxisLocation.TOP_OR_LEFT);

    // parent plot...
    final CombinedDomainXYPlot plot = new CombinedDomainXYPlot(new NumberAxis("Domain"));
    plot.setGap(10.0);

    // add the subplots...
    plot.add(subplot1, 1);
    plot.add(subplot2, 1);
    plot.setOrientation(PlotOrientation.VERTICAL);

    // return a new chart containing the overlaid plot...
    return new JFreeChart("CombinedDomainXYPlot Demo", JFreeChart.DEFAULT_TITLE_FONT, plot, true);

}