Example usage for org.jfree.chart.axis AxisLocation BOTTOM_OR_RIGHT

List of usage examples for org.jfree.chart.axis AxisLocation BOTTOM_OR_RIGHT

Introduction

In this page you can find the example usage for org.jfree.chart.axis AxisLocation BOTTOM_OR_RIGHT.

Prototype

AxisLocation BOTTOM_OR_RIGHT

To view the source code for org.jfree.chart.axis AxisLocation BOTTOM_OR_RIGHT.

Click Source Link

Document

Axis at the bottom or right.

Usage

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);//  w ww. j a  v  a  2  s  .c o  m
        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:com.orange.atk.graphAnalyser.PerformanceGraph.java

public PerformanceGraph(int graphNumber, String fileName, String serieName, Color color, String axisName,
        XYPlot xyplot, String unit, int scale) {
    this.graphNumber = graphNumber + 1;
    this.serieName = serieName;
    this.fileName = fileName;
    this.color = color;
    this.location = AxisLocation.BOTTOM_OR_RIGHT; // Default
    this.xyplot = xyplot;
    this.unit = unit;
    this.scale = scale;
    standardxyitemrenderer = new StandardXYItemRenderer();
    numberaxis = new NumberAxis(axisName);
    numberaxis.setLabelPaint(color);/*from  w w  w  .j a  v  a 2s.  co  m*/
    numberaxis.setTickLabelPaint(color);
    numberaxis.setFixedDimension(10D);
    numberaxis.setNumberFormatOverride(new DecimalFormat("###,###,##0.###"));
    numberaxis.setAutoRange(true);
    numberaxis.setAutoRangeIncludesZero(false);
    numberaxis.setLabel(serieName);
}

From source file:openqcm.ChartDynamicData.java

public ChartDynamicData() {

    // add primary axis frequency
    TimeSeries seriesFrequency = new TimeSeries("Frequency (Hz)");
    datasetFrequency = new TimeSeriesCollection(seriesFrequency);
    rangeAxisF = new NumberAxis("Frequency (Hz)");
    XYItemRenderer renderer = new StandardXYItemRenderer();
    renderer.setSeriesPaint(0, new Color(0, 142, 192));
    rangeAxisF.setAutoRangeIncludesZero(false);
    rangeAxisF.setAutoRange(true);/*from  w ww  .j a v  a  2  s.  c  o m*/
    rangeAxisF.setAutoRangeMinimumSize(50);

    plot.setDataset(0, datasetFrequency);
    plot.setRangeAxis(0, rangeAxisF);
    plot.setRangeAxisLocation(0, AxisLocation.BOTTOM_OR_LEFT);
    plot.setRenderer(0, renderer);
    plot.mapDatasetToRangeAxis(0, 0);

    // add secondary axis temperature
    TimeSeries seriesTemperature = new TimeSeries("Temperature (C)");
    datasetTemperature = new TimeSeriesCollection(seriesTemperature);
    plot.setDataset(1, datasetTemperature);
    NumberAxis rangeAxisT = new NumberAxis("Temperature (C)");
    rangeAxisT.setAutoRangeIncludesZero(false);
    rangeAxisT.setAutoRange(true);
    rangeAxisT.setAutoRangeMinimumSize(5);
    plot.setRangeAxis(1, rangeAxisT);
    plot.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_RIGHT);
    // custom renderer for dinamically changing temperaure
    rendererT.setSeriesPaint(0, new Color(255, 128, 0));
    plot.setRenderer(1, rendererT);

    plot.mapDatasetToRangeAxis(1, 1);
    plotComb.add(plot);
    plotComb.setBackgroundPaint(Color.white);
    plotComb.setDomainGridlinePaint(Color.white);
    plotComb.setRangeGridlinePaint(Color.white);
    // enable panning for both axis
    plotComb.setRangePannable(true);
    plotComb.setDomainPannable(true);

    // set time axis properties
    // format time axis as hh:mm:ss
    SimpleDateFormat format = new SimpleDateFormat("HH:mm:ss");
    DateAxis axis = (DateAxis) plotComb.getDomainAxis();
    axis.setDateFormatOverride(format);
    // default auto range
    domainAxis.setAutoRange(true);

    // init the JFreeChart
    JFreeChart chart = new JFreeChart(plotComb);
    chart.setBorderPaint(Color.lightGray);
    chart.setBorderVisible(true);
    chart.setBackgroundPaint(Color.white);

    // set legend properties
    LegendTitle legend = chart.getLegend();
    legend.setPosition(RectangleEdge.TOP);
    legend.setItemFont(new Font("Dialog", Font.PLAIN, 9));

    // constructor for org.jfree.chart.ChartPanel
    // ChartPanel(JFreeChart chart, boolean properties, boolean save, boolean print, boolean zoom, boolean tooltips)
    ChartPanel chartPanel = new ChartPanel(chart, false, true, true, true, true);
    // enable mouse wheel support for the chart panel
    chartPanel.setMouseWheelEnabled(true);

    this.setLayout(new BorderLayout());
    // add real time chart to the frame
    this.add(chartPanel);
    this.validate();
}

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

/**
 * Creates a new demo instance.//from   w  w w.  j av  a  2s.  c  om
 *
 * @param title  the frame title.
 */
public DualAxisDemo3(final String title) {

    super(title);

    final CategoryDataset dataset1 = createDataset1();

    // create the chart...
    final JFreeChart chart = ChartFactory.createBarChart("Dual Axis Chart", // chart title
            "Category", // domain axis label
            "Value", // range axis label
            dataset1, // dataset
            PlotOrientation.HORIZONTAL, // orientation
            true, // include legend
            true, false);

    // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...

    // set the background color for the chart...
    chart.setBackgroundPaint(new Color(0xCC, 0xFF, 0xCC));
    //      chart.getLegend().setAnchor(Legend.WEST);

    // get a reference to the plot for further customisation...
    final CategoryPlot plot = chart.getCategoryPlot();
    plot.setDomainAxisLocation(AxisLocation.BOTTOM_OR_RIGHT);
    //    plot.getDomainAxis().setMaxCategoryLabelWidthRatio(10.0f);
    final CategoryDataset dataset2 = createDataset2();
    final ValueAxis axis2 = new NumberAxis("Secondary");
    plot.setRangeAxis(1, axis2);
    plot.setDataset(1, dataset2);
    plot.mapDatasetToRangeAxis(1, 1);
    plot.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_RIGHT);
    final CategoryItemRenderer renderer2 = new LineAndShapeRenderer();
    plot.setRenderer(1, renderer2);

    // OPTIONAL CUSTOMISATION COMPLETED.

    // add the chart to a panel...
    final ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
    setContentPane(chartPanel);

}

From source file:org.matsim.counts.algorithms.graphs.BiasErrorGraph.java

@Override
public JFreeChart createChart(final int nbr) {
    DefaultCategoryDataset dataset0 = new DefaultCategoryDataset();
    DefaultCategoryDataset dataset1 = new DefaultCategoryDataset();

    this.errorStats = new ComparisonErrorStatsCalculator(this.ccl_);

    double[] meanRelError = errorStats.getMeanRelError();
    //      double[] meanAbsError = errorStats.getMeanAbsError();
    double[] meanAbsBias = errorStats.getMeanAbsBias();

    for (int h = 0; h < 24; h++) {
        dataset0.addValue(meanRelError[h], "Mean rel error", Integer.toString(h + 1));
        //         dataset1.addValue(meanAbsError[h], "Mean abs error", Integer.toString(h + 1));
        dataset1.addValue(meanAbsBias[h], "Mean abs bias", Integer.toString(h + 1));
    }/*from   w ww .java 2s. c  o  m*/

    this.chart_ = ChartFactory.createLineChart("", "Hour", "Mean rel error [%]", dataset0,
            PlotOrientation.VERTICAL, true, // legend?
            true, // tooltips?
            false // URLs?
    );
    CategoryPlot plot = this.chart_.getCategoryPlot();
    plot.setDomainAxisLocation(AxisLocation.BOTTOM_OR_RIGHT);
    plot.setDataset(1, dataset1);
    plot.mapDatasetToRangeAxis(1, 1);

    final LineAndShapeRenderer renderer = new LineAndShapeRenderer();
    renderer.setSeriesToolTipGenerator(0, new StandardCategoryToolTipGenerator());
    plot.setRenderer(0, renderer);

    final CategoryAxis axis1 = new CategoryAxis("Hour");
    axis1.setTickLabelFont(new Font("SansSerif", Font.PLAIN, 7));
    plot.setDomainAxis(axis1);

    //      final ValueAxis axis2 = new NumberAxis("Mean abs {bias, error} [veh/h]");
    final ValueAxis axis2 = new NumberAxis("Mean abs bias [veh/h]");
    plot.setRangeAxis(1, axis2);

    final ValueAxis axis3 = plot.getRangeAxis(0);
    axis3.setRange(0.0, 100.0);

    final LineAndShapeRenderer renderer2 = new LineAndShapeRenderer();
    renderer2.setSeriesToolTipGenerator(0, new StandardCategoryToolTipGenerator());
    renderer2.setSeriesToolTipGenerator(1, new StandardCategoryToolTipGenerator());
    //      renderer2.setSeriesPaint(0, Color.black);
    plot.setRenderer(1, renderer2);
    plot.setDatasetRenderingOrder(DatasetRenderingOrder.REVERSE);

    return this.chart_;
}

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

private static JFreeChart createChart(CategoryDataset categorydataset, CategoryDataset categorydataset1) {
    CategoryAxis categoryaxis = new CategoryAxis("Category");
    NumberAxis numberaxis = new NumberAxis("Value");
    GroupedStackedBarRenderer groupedstackedbarrenderer = new GroupedStackedBarRenderer();
    KeyToGroupMap keytogroupmap = new KeyToGroupMap("G1");
    keytogroupmap.mapKeyToGroup("Series 1A", "G1");
    keytogroupmap.mapKeyToGroup("Series 1B", "G1");
    keytogroupmap.mapKeyToGroup("NOTHING", "G2");
    groupedstackedbarrenderer.setSeriesToGroupMap(keytogroupmap);
    CategoryPlot categoryplot = new CategoryPlot(categorydataset, categoryaxis, numberaxis,
            groupedstackedbarrenderer) {

        private static final long serialVersionUID = 1L;

        public LegendItemCollection getLegendItems() {
            LegendItemCollection legenditemcollection = new LegendItemCollection();
            legenditemcollection.addAll(getRenderer().getLegendItems());
            CategoryDataset categorydataset2 = getDataset(1);
            if (categorydataset2 != null) {
                CategoryItemRenderer categoryitemrenderer = getRenderer(1);
                if (categoryitemrenderer != null) {
                    org.jfree.chart.LegendItem legenditem = categoryitemrenderer.getLegendItem(1, 1);
                    legenditemcollection.add(legenditem);
                }/* w  ww  .j  av a 2  s . com*/
            }
            return legenditemcollection;
        }

    };
    JFreeChart jfreechart = new JFreeChart("Dual Axis Bar Chart", categoryplot);
    categoryplot.setDomainAxisLocation(AxisLocation.BOTTOM_OR_RIGHT);
    categoryplot.setDataset(1, categorydataset1);
    categoryplot.mapDatasetToRangeAxis(1, 1);
    NumberAxis numberaxis1 = new NumberAxis("Secondary");
    categoryplot.setRangeAxis(1, numberaxis1);
    categoryplot.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_RIGHT);
    BarRenderer barrenderer = new BarRenderer();
    categoryplot.setRenderer(1, barrenderer);
    ChartUtilities.applyCurrentTheme(jfreechart);
    return jfreechart;
}

From source file:org.matsim.counts.algorithms.graphs.BiasNormalizedErrorGraph.java

@Override
public JFreeChart createChart(final int nbr) {
    DefaultCategoryDataset dataset0 = new DefaultCategoryDataset();
    DefaultCategoryDataset dataset1 = new DefaultCategoryDataset();

    this.errorStats = new ComparisonErrorStatsCalculator(this.ccl_);

    double[] meanNormRelError = this.errorStats.getMeanNormRelError();
    //      double[] meanAbsError = this.errorStats.getMeanAbsError();
    double[] meanBias = this.errorStats.getMeanBias();

    for (int h = 0; h < 24; h++) {
        meanNormRelError[h] *= 100;/*from  w ww . j  a v a2 s.c  o m*/
        dataset0.addValue(meanNormRelError[h], "Mean norm rel error", Integer.toString(h + 1));
        //         dataset1.addValue(meanAbsError[h], "Mean abs error", Integer.toString(h + 1));
        dataset1.addValue(meanBias[h], "Mean bias", Integer.toString(h + 1));
    }

    this.chart_ = ChartFactory.createLineChart("", "Hour", "Mean norm rel error [%]", dataset0,
            PlotOrientation.VERTICAL, true, // legend?
            true, // tooltips?
            false // URLs?
    );
    CategoryPlot plot = this.chart_.getCategoryPlot();
    plot.setDomainAxisLocation(AxisLocation.BOTTOM_OR_RIGHT);
    plot.setDataset(1, dataset1);
    plot.mapDatasetToRangeAxis(1, 1);

    final LineAndShapeRenderer renderer = new LineAndShapeRenderer();
    renderer.setSeriesToolTipGenerator(0, new StandardCategoryToolTipGenerator());
    plot.setRenderer(0, renderer);

    final CategoryAxis axis1 = new CategoryAxis("Hour");
    axis1.setTickLabelFont(new Font("SansSerif", Font.PLAIN, 7));
    plot.setDomainAxis(axis1);

    //      final ValueAxis axis2 = new NumberAxis("Mean abs {bias, error} [veh/h]");
    final ValueAxis axis2 = new NumberAxis("Mean bias [veh/h]");
    plot.setRangeAxis(1, axis2);

    final ValueAxis axis3 = plot.getRangeAxis(0);
    axis3.setRange(0.0, 100.0);

    final LineAndShapeRenderer renderer2 = new LineAndShapeRenderer();
    renderer2.setSeriesToolTipGenerator(0, new StandardCategoryToolTipGenerator());
    renderer2.setSeriesToolTipGenerator(1, new StandardCategoryToolTipGenerator());
    //      renderer2.setSeriesPaint(0, Color.black);
    plot.setRenderer(1, renderer2);
    plot.setDatasetRenderingOrder(DatasetRenderingOrder.REVERSE);

    return this.chart_;
}

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

/**
 * Creates a combined chart.// ww  w. j  a  va2s  .  com
 *
 * @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);

}

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

private static JFreeChart createChart() {
    JFreeChart jfreechart = ChartFactory.createBarChart("Dual Axis Chart", "Category", "Value",
            createDataset1(), PlotOrientation.VERTICAL, false, true, false);
    jfreechart.setBackgroundPaint(Color.white);
    CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot();
    categoryplot.setBackgroundPaint(new Color(238, 238, 255));
    categoryplot.setDomainAxisLocation(AxisLocation.BOTTOM_OR_RIGHT);
    CategoryDataset categorydataset = createDataset2();
    categoryplot.setDataset(1, categorydataset);
    categoryplot.mapDatasetToRangeAxis(1, 1);
    CategoryAxis categoryaxis = categoryplot.getDomainAxis();
    categoryaxis.setCategoryLabelPositions(CategoryLabelPositions.DOWN_45);
    NumberAxis numberaxis = new NumberAxis("Secondary");
    categoryplot.setRangeAxis(1, numberaxis);
    LineAndShapeRenderer lineandshaperenderer = new LineAndShapeRenderer();
    lineandshaperenderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator());
    categoryplot.setRenderer(1, lineandshaperenderer);
    categoryplot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);
    LegendTitle legendtitle = new LegendTitle(categoryplot.getRenderer(0));
    legendtitle.setMargin(new RectangleInsets(2D, 2D, 2D, 2D));
    legendtitle.setFrame(new BlockBorder());
    LegendTitle legendtitle1 = new LegendTitle(categoryplot.getRenderer(1));
    legendtitle1.setMargin(new RectangleInsets(2D, 2D, 2D, 2D));
    legendtitle1.setFrame(new BlockBorder());
    BlockContainer blockcontainer = new BlockContainer(new BorderArrangement());
    blockcontainer.add(legendtitle, RectangleEdge.LEFT);
    blockcontainer.add(legendtitle1, RectangleEdge.RIGHT);
    blockcontainer.add(new EmptyBlock(2000D, 0.0D));
    CompositeTitle compositetitle = new CompositeTitle(blockcontainer);
    compositetitle.setPosition(RectangleEdge.BOTTOM);
    jfreechart.addSubtitle(compositetitle);
    return jfreechart;
}

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

/**
 * Creates a new demo instance./*  ww w  .ja v a  2s  . c o m*/
 *
 * @param title  the frame title.
 */
public DualAxisDemo(final String title) {

    super(title);

    final CategoryDataset dataset1 = createDataset1();

    // create the chart...
    final JFreeChart chart = ChartFactory.createBarChart("Dual Axis Chart", // chart title
            "Category", // domain axis label
            "Value", // range axis label
            dataset1, // data
            PlotOrientation.VERTICAL, true, // include legend
            true, // tooltips?
            false // URL generator?  Not required...
    );

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

    // get a reference to the plot for further customisation...
    final CategoryPlot plot = chart.getCategoryPlot();
    plot.setBackgroundPaint(new Color(0xEE, 0xEE, 0xFF));
    plot.setDomainAxisLocation(AxisLocation.BOTTOM_OR_RIGHT);

    final CategoryDataset dataset2 = createDataset2();
    plot.setDataset(1, dataset2);
    plot.mapDatasetToRangeAxis(1, 1);

    final CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.DOWN_45);
    final ValueAxis axis2 = new NumberAxis("Secondary");
    plot.setRangeAxis(1, axis2);

    final LineAndShapeRenderer renderer2 = new LineAndShapeRenderer();
    renderer2.setToolTipGenerator(new StandardCategoryToolTipGenerator());
    plot.setRenderer(1, renderer2);
    plot.setDatasetRenderingOrder(DatasetRenderingOrder.REVERSE);
    // OPTIONAL CUSTOMISATION COMPLETED.

    // add the chart to a panel...
    final ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
    setContentPane(chartPanel);

}