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

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

Introduction

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

Prototype

public ValueAxis getRangeAxis(int index) 

Source Link

Document

Returns the range axis with the specified index, or null if there is no axis with that index.

Usage

From source file:ch.zhaw.parallelComputing.view.Plotter.java

/**
 * Generates a plot for comparing to datasets
 * @param title the name of the plot/*  ww w.  java2s .  c o  m*/
 * @param dataset1 the first data set for plotting
 * @param dataset2 the second data set for plotting
 * @return a chart object for displaying or saving as picture
 */
public static JFreeChart plot(String title, XYDataset dataset1, XYDataset dataset2) {

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

    XYPlot plot = chart.getXYPlot();

    Axis axis1 = plot.getRangeAxis(0);
    axis1.setLabelPaint(Color.red);

    NumberAxis axis2 = new NumberAxis("Twitter");
    axis2.setLabelPaint(Color.blue);
    plot.setRangeAxis(1, axis2);
    plot.setDataset(1, dataset2);
    plot.mapDatasetToRangeAxis(1, 1);

    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    renderer.setSeriesPaint(0, Color.blue);
    renderer.setBaseShapesVisible(false);
    plot.setRenderer(1, renderer);

    return chart;
}

From source file:org.xapagy.ui.tempdyn.GraphEvolution.java

/**
 * Returns a chart for the evolution of the shadowing of the component tdc with sh.
 * //from   w  w w  .  ja  v  a  2 s.c o  m
 * @param tdc
 * @param sh
 * @param database
 * @param agent
 * @param index
 * @param shadowRange
 * @param ged
 * @return
 */
public static JFreeChart chartShadowEvolution(tdComponent tdc, String sh, tdDataBase database, Agent agent,
        List<Double> index, double shadowRange, GraphEvolutionDescriptor ged) {
    List<String> shadowColors = null;
    if (tdc.getType() == tdComponentType.INSTANCE) {
        shadowColors = ged.shadowInstanceEnergyColors;
    } else {
        shadowColors = ged.shadowViEnergyColors;
    }
    // create a general purpose xy collection for jfreechart
    XYSeriesCollection xysc = new XYSeriesCollection();
    // shadow energy values (if needed)
    if (ged.graphShadowEnergy) {
        for (String ec : shadowColors) {
            xysc.addSeries(new XYSeries("ShadowEnergy_" + ec + "_" + sh));
        }
    }
    // shadow salience values (if needed)
    if (ged.graphShadowSalience) {
        for (String ec : shadowColors) {
            xysc.addSeries(new XYSeries("ShadowSalience_" + ec + "_" + sh));
        }
    }
    //
    // Fill in the values into the xysc
    //
    for (Double time : index) {
        double dtime = time;
        // shadow energy values (if needed)
        if (ged.graphShadowEnergy) {
            for (String ec : shadowColors) {
                double value = database.getEnergy(tdc.getIdentifier(), sh, ec, time);
                xysc.getSeries("ShadowEnergy_" + ec + "_" + sh).add(dtime, value);
            }
        }
        // shadow salience values (if needed)
        if (ged.graphShadowSalience) {
            for (String ec : shadowColors) {
                double value = database.getSalience(tdc.getIdentifier(), sh, ec, time);
                xysc.getSeries("ShadowSalience_" + ec + "_" + sh).add(dtime, value);
            }
        }
    }
    XYSeriesCollection xysSH = new XYSeriesCollection();
    // shadow energy (if needed)
    if (ged.graphShadowEnergy) {
        for (String ec : shadowColors) {
            xysSH.addSeries(xysc.getSeries("ShadowEnergy_" + ec + "_" + sh));
        }
    }
    // shadow salience (if needed)
    if (ged.graphShadowSalience) {
        for (String ec : shadowColors) {
            xysSH.addSeries(xysc.getSeries("ShadowSalience_" + ec + "_" + sh));
        }
    }
    // FIND a label
    String shadowLabel = "Shadow:" + sh;
    if (tdc.getType() == tdComponentType.INSTANCE) {
        Instance instance = agent.getAutobiographicalMemory().getInstance(sh);
        shadowLabel += " - " + SpInstance.spc(instance, agent);
    } else {
        VerbInstance vi = agent.getAutobiographicalMemory().getVerbInstance(sh);
        shadowLabel += " - " + XapiPrint.ppsViXapiForm(vi, agent);
    }
    JFreeChart chart = ChartFactory.createXYLineChart(shadowLabel, "Time", "Value", xysSH,
            PlotOrientation.VERTICAL, true, false, false);
    GraphEvolution.setChartProperties(chart, GraphEvolution.lineStylesConservative);
    XYPlot plot = chart.getXYPlot();
    plot.getRangeAxis(0).setRange(0, shadowRange);
    return chart;
}

From source file:org.yccheok.jstock.charting.Utils.java

/**
 * Applying chart theme based on given JFreeChart.
 *
 * @param chart the JFreeChart//from   ww  w  .  ja  v  a 2  s . c o  m
 */
public static void applyChartTheme(JFreeChart chart) {
    final StandardChartTheme chartTheme = (StandardChartTheme) org.jfree.chart.StandardChartTheme
            .createJFreeTheme();
    chartTheme.setXYBarPainter(barPainter);
    chartTheme.setShadowVisible(false);
    chartTheme.setPlotBackgroundPaint(Color.WHITE);
    chartTheme.setDomainGridlinePaint(Color.LIGHT_GRAY);
    chartTheme.setRangeGridlinePaint(Color.LIGHT_GRAY);
    chartTheme.setPlotOutlinePaint(Color.LIGHT_GRAY);

    // The default font used by JFreeChart unable to render Chinese properly.
    // We need to provide font which is able to support Chinese rendering.
    final Locale defaultLocale = Locale.getDefault();
    if (org.yccheok.jstock.gui.Utils.isSimplifiedChinese(defaultLocale)
            || org.yccheok.jstock.gui.Utils.isTraditionalChinese(defaultLocale)) {
        final Font oldExtraLargeFont = chartTheme.getExtraLargeFont();
        final Font oldLargeFont = chartTheme.getLargeFont();
        final Font oldRegularFont = chartTheme.getRegularFont();
        final Font oldSmallFont = chartTheme.getSmallFont();

        final Font extraLargeFont = new Font("Sans-serif", oldExtraLargeFont.getStyle(),
                oldExtraLargeFont.getSize());
        final Font largeFont = new Font("Sans-serif", oldLargeFont.getStyle(), oldLargeFont.getSize());
        final Font regularFont = new Font("Sans-serif", oldRegularFont.getStyle(), oldRegularFont.getSize());
        final Font smallFont = new Font("Sans-serif", oldSmallFont.getStyle(), oldSmallFont.getSize());

        chartTheme.setExtraLargeFont(extraLargeFont);
        chartTheme.setLargeFont(largeFont);
        chartTheme.setRegularFont(regularFont);
        chartTheme.setSmallFont(smallFont);
    }

    if (chart.getPlot() instanceof CombinedDomainXYPlot) {
        @SuppressWarnings("unchecked")
        List<Plot> plots = ((CombinedDomainXYPlot) chart.getPlot()).getSubplots();
        for (Plot plot : plots) {
            final int domainAxisCount = ((XYPlot) plot).getDomainAxisCount();
            final int rangeAxisCount = ((XYPlot) plot).getRangeAxisCount();
            for (int i = 0; i < domainAxisCount; i++) {
                ((XYPlot) plot).getDomainAxis(i).setAxisLinePaint(Color.LIGHT_GRAY);
                ((XYPlot) plot).getDomainAxis(i).setTickMarkPaint(Color.LIGHT_GRAY);
            }
            for (int i = 0; i < rangeAxisCount; i++) {
                ((XYPlot) plot).getRangeAxis(i).setAxisLinePaint(Color.LIGHT_GRAY);
                ((XYPlot) plot).getRangeAxis(i).setTickMarkPaint(Color.LIGHT_GRAY);
            }
        }
    } else {
        final Plot plot = chart.getPlot();
        if (plot instanceof XYPlot) {
            final org.jfree.chart.plot.XYPlot xyPlot = (org.jfree.chart.plot.XYPlot) plot;
            final int domainAxisCount = xyPlot.getDomainAxisCount();
            final int rangeAxisCount = xyPlot.getRangeAxisCount();
            for (int i = 0; i < domainAxisCount; i++) {
                xyPlot.getDomainAxis(i).setAxisLinePaint(Color.LIGHT_GRAY);
                xyPlot.getDomainAxis(i).setTickMarkPaint(Color.LIGHT_GRAY);
            }
            for (int i = 0; i < rangeAxisCount; i++) {
                xyPlot.getRangeAxis(i).setAxisLinePaint(Color.LIGHT_GRAY);
                xyPlot.getRangeAxis(i).setTickMarkPaint(Color.LIGHT_GRAY);
            }
        }
        //else if (plot instanceof org.jfree.chart.plot.PiePlot) {
        //    final org.jfree.chart.plot.PiePlot piePlot = (org.jfree.chart.plot.PiePlot)plot;
        //    
        //}
    }

    chartTheme.apply(chart);
}

From source file:com.hazelcast.monitor.server.MChartGenerator.java

@Override
protected void afterPlot(List<? super InstanceStatistics> list, JFreeChart chart, XYPlot plot) {
    NumberAxis sizeAxis = (NumberAxis) plot.getRangeAxis(0);
    Font labelFont = sizeAxis.getLabelFont();
    Paint labelPaint = sizeAxis.getLabelPaint();
    TimeSeries tm = new TimeSeries("memory");
    for (int i = 0; i < list.size(); i++) {
        double memory = 0;
        MapStatistics mapStatistics = (MapStatistics) list.get(i);
        for (MapStatistics.LocalMapStatistics localMapStatistics : mapStatistics.getListOfLocalStats()) {
            memory = memory + localMapStatistics.ownedEntryMemoryCost + localMapStatistics.backupEntryMemoryCost
                    + localMapStatistics.markedAsRemovedMemoryCost;
        }/*from w w  w . j  a va 2s  . co  m*/
        double mem = new Double(memory / (double) (1024 * 1024));
        tm.addOrUpdate(new Second(((MapStatistics) list.get(i)).getCreatedDate()), mem);
    }
    NumberAxis memoryAxis = new NumberAxis("memory (MB)");
    memoryAxis.setAutoRange(true);
    memoryAxis.setAutoRangeIncludesZero(false);
    plot.setDataset(1, new TimeSeriesCollection(tm));
    plot.setRangeAxis(1, memoryAxis);
    plot.mapDatasetToRangeAxis(1, 1);
    plot.setRenderer(1, new StandardXYItemRenderer());
    plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);
    increaseRange(memoryAxis);
    memoryAxis.setLabelFont(labelFont);
    memoryAxis.setLabelPaint(labelPaint);
}

From source file:com.hazelcast.monitor.server.InstanceChartGenerator.java

public JFreeChart generateOperationStatsChart(List<? super InstanceStatistics> list) {
    TimeSeries ts = new TimeSeries("operations per second");
    for (int i = 0; i < list.size(); i++) {
        InstanceStatistics instanceStatistics = (InstanceStatistics) list.get(i);
        ts.addOrUpdate(new Second(instanceStatistics.getCreatedDate()),
                (double) instanceStatistics.getTotalOPS() / 1000);
    }//  www  . j ava 2  s  .  c om
    TimeSeriesCollection timeDataset = new TimeSeriesCollection();
    timeDataset.addSeries(ts);
    JFreeChart chart = ChartFactory.createTimeSeriesChart(null, "time", "throughput (x1000)", timeDataset, true,
            true, true);
    XYPlot plot = (XYPlot) chart.getPlot();
    increaseRange((NumberAxis) plot.getRangeAxis(0));
    return chart;
}

From source file:com.hazelcast.monitor.server.InstanceChartGenerator.java

public JFreeChart generateSizeChart(List<? super InstanceStatistics> list) {
    TimeSeries ts = new TimeSeries("size");
    for (int i = 0; i < list.size(); i++) {
        InstanceStatistics instanceStatistics = (InstanceStatistics) list.get(i);
        ts.addOrUpdate(new Second(instanceStatistics.getCreatedDate()),
                new Double(instanceStatistics.getSize() / (double) 1000));
    }//from  ww  w  .  ja va2s  .  c  o m
    TimeSeriesCollection timeDataset = new TimeSeriesCollection();
    timeDataset.addSeries(ts);
    JFreeChart chart = ChartFactory.createTimeSeriesChart(null, "time", "size (x1000)", timeDataset, true, true,
            true);
    XYPlot plot = (XYPlot) chart.getPlot();
    NumberAxis sizeAxis = (NumberAxis) plot.getRangeAxis(0);
    increaseRange(sizeAxis);
    afterPlot(list, chart, plot);
    return chart;
}

From source file:de.atomfrede.tools.evalutation.tools.plot.TimePlot.java

@Override
protected JFreeChart createChart(XYDatasetWrapper... datasetWrappers) {
    XYDatasetWrapper mainDataset = datasetWrappers[0];

    JFreeChart chart = ChartFactory.createTimeSeriesChart(mainDataset.getSeriesName(), "Time",
            mainDataset.getSeriesName(), mainDataset.getDataset(), true, true, false);

    XYPlot plot = (XYPlot) chart.getPlot();
    // all adjustments for first/main dataset
    plot.getRangeAxis(0).setLowerBound(mainDataset.getMinimum());
    plot.getRangeAxis(0).setUpperBound(mainDataset.getMaximum());
    // some additional "design" stuff for the plot
    plot.getRenderer(0).setSeriesPaint(0, mainDataset.getSeriesColor());
    plot.getRenderer(0).setSeriesStroke(0, new BasicStroke(mainDataset.getStroke()));

    for (int i = 1; i < datasetWrappers.length; i++) {
        XYDatasetWrapper wrapper = datasetWrappers[i];
        plot.setDataset(i, wrapper.getDataset());
        chart.setTitle(chart.getTitle().getText() + "/" + wrapper.getSeriesName());

        NumberAxis axis = new NumberAxis(wrapper.getSeriesName());
        plot.setRangeAxis(i, axis);/*from w  w  w .jav  a  2 s .  com*/
        plot.setRangeAxisLocation(i, AxisLocation.BOTTOM_OR_RIGHT);

        plot.getRangeAxis(i).setLowerBound(wrapper.getMinimum() - 15.0);
        plot.getRangeAxis(i).setUpperBound(wrapper.getMaximum() + 15.0);
        // map the second dataset to the second axis
        plot.mapDatasetToRangeAxis(i, i);

        XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
        renderer.setBaseShapesVisible(false);
        renderer.setSeriesStroke(0, new BasicStroke(wrapper.getStroke()));
        plot.setRenderer(i, renderer);
        plot.getRenderer(i).setSeriesPaint(0, wrapper.getSeriesColor());
    }
    // change the background and gridline colors
    plot.setBackgroundPaint(Color.white);
    plot.setDomainMinorGridlinePaint(Color.LIGHT_GRAY);
    plot.setDomainGridlinePaint(Color.LIGHT_GRAY);
    plot.setRangeGridlinePaint(Color.LIGHT_GRAY);

    // format the date axis
    DateAxis axis = (DateAxis) plot.getDomainAxis();

    axis.setDateFormatOverride(new SimpleDateFormat("dd.MM HH:mm"));
    axis.setTickUnit(new DateTickUnit(DateTickUnitType.HOUR, 1));
    axis.setVerticalTickLabels(true);
    return chart;
}

From source file:de.atomfrede.tools.evalutation.tools.plot.custom.CustomSimplePlot.java

@Override
protected JFreeChart createChart(XYDatasetWrapper... datasetWrappers) {
    XYDatasetWrapper mainDataset = datasetWrappers[0];

    JFreeChart chart = ChartFactory.createXYLineChart(mainDataset.getSeriesName(), "Index",
            mainDataset.getSeriesName(), mainDataset.getDataset(), PlotOrientation.VERTICAL, true, false,
            false);// w w  w  . jav  a 2  s.  c om

    XYPlot plot = (XYPlot) chart.getPlot();
    // all adjustments for first/main dataset
    plot.getRangeAxis(0).setLowerBound(mainDataset.getMinimum());
    plot.getRangeAxis(0).setUpperBound(mainDataset.getMaximum());
    // some additional "design" stuff for the plot
    plot.getRenderer(0).setSeriesPaint(0, mainDataset.getSeriesColor());
    plot.getRenderer(0).setSeriesStroke(0, new BasicStroke(mainDataset.getStroke()));

    for (int i = 1; i < datasetWrappers.length; i++) {
        XYDatasetWrapper wrapper = datasetWrappers[i];
        plot.setDataset(i, wrapper.getDataset());
        chart.setTitle(chart.getTitle().getText() + "/" + wrapper.getSeriesName());

        NumberAxis axis = new NumberAxis(wrapper.getSeriesName());
        plot.setRangeAxis(i, axis);
        plot.setRangeAxisLocation(i, AxisLocation.BOTTOM_OR_RIGHT);

        plot.getRangeAxis(i).setLowerBound(wrapper.getMinimum() - 15.0);
        plot.getRangeAxis(i).setUpperBound(wrapper.getMaximum() + 15.0);
        // map the second dataset to the second axis
        plot.mapDatasetToRangeAxis(i, i);

        XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
        renderer.setBaseShapesVisible(false);
        renderer.setSeriesStroke(0, new BasicStroke(wrapper.getStroke()));
        plot.setRenderer(i, renderer);
        plot.getRenderer(i).setSeriesPaint(0, wrapper.getSeriesColor());
    }
    // change the background and gridline colors
    plot.setBackgroundPaint(Color.white);
    plot.setDomainMinorGridlinePaint(Color.LIGHT_GRAY);
    plot.setDomainGridlinePaint(Color.LIGHT_GRAY);
    plot.setRangeGridlinePaint(Color.LIGHT_GRAY);

    return chart;
}

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

public synchronized void updateChartAxisRange(double maxRangeForOps, double maxRangeForTrg) {
    XYPlot xyplot = (XYPlot) statChart.getPlot();
    xyplot.getRangeAxis(0).setRange(0, maxRangeForOps);
    xyplot.getRangeAxis(1).setRange(0, maxRangeForOps);
    xyplot.getRangeAxis(2).setRange(0, maxRangeForOps);
    xyplot.getRangeAxis(3).setRange(0, maxRangeForTrg);
    xyplot.getRangeAxis(4).setRange(0, maxRangeForTrg);
    xyplot.getRangeAxis(5).setRange(0, maxRangeForTrg);
}

From source file:controletanquesproj1.Grafico.java

/**
 * Creates a chart.//ww w  . j  a v a2 s .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;

}