Example usage for org.jfree.chart.renderer.xy XYBarRenderer setURLGenerator

List of usage examples for org.jfree.chart.renderer.xy XYBarRenderer setURLGenerator

Introduction

In this page you can find the example usage for org.jfree.chart.renderer.xy XYBarRenderer setURLGenerator.

Prototype

@Override
public void setURLGenerator(XYURLGenerator urlGenerator) 

Source Link

Document

Sets the URL generator for HTML image maps and sends a RendererChangeEvent to all registered listeners.

Usage

From source file:org.pentaho.plugin.jfreereport.reportcharts.XYBarChartExpression.java

protected static JFreeChart createTimeSeriesChart(final String title, final String timeAxisLabel,
        final String valueAxisLabel, final XYDataset dataset, final boolean legend, final boolean tooltips,
        final boolean urls, final boolean stacked) {
    final ValueAxis timeAxis = new DateAxis(timeAxisLabel);
    timeAxis.setLowerMargin(0.02); // reduce the default margins
    timeAxis.setUpperMargin(0.02);/*from  w  ww . j  a  v a2  s  .  c o m*/
    final NumberAxis valueAxis = new NumberAxis(valueAxisLabel);
    valueAxis.setAutoRangeIncludesZero(false); // override default
    final XYPlot plot = new XYPlot(dataset, timeAxis, valueAxis, null);

    XYToolTipGenerator toolTipGenerator = null;
    if (tooltips) {
        toolTipGenerator = StandardXYToolTipGenerator.getTimeSeriesInstance();
    }

    XYURLGenerator urlGenerator = null;
    if (urls) {
        urlGenerator = new StandardXYURLGenerator();
    }

    final XYBarRenderer renderer;
    if (stacked) {
        renderer = new StackedXYBarRenderer();
    } else {
        renderer = new XYBarRenderer();
    }
    renderer.setBaseToolTipGenerator(toolTipGenerator);
    renderer.setURLGenerator(urlGenerator);
    plot.setRenderer(renderer);

    return new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend);
}

From source file:org.pentaho.plugin.jfreereport.reportcharts.XYBarChartExpression.java

/**
 * Creates and returns a default instance of an XY bar chart.
 * <p/>//from   w  ww  . ja  v  a  2s  .  c  o  m
 * The chart object returned by this method uses an {@link XYPlot} instance as the plot, with a {@link
 * org.jfree.chart.axis.DateAxis} for the domain axis, a {@link org.jfree.chart.axis.NumberAxis} as the range axis,
 * and a {@link XYBarRenderer} as the renderer.
 *
 * @param title       the chart title (<code>null</code> permitted).
 * @param xAxisLabel  a label for the X-axis (<code>null</code> permitted).
 * @param dateAxis    make the domain axis display dates?
 * @param yAxisLabel  a label for the Y-axis (<code>null</code> permitted).
 * @param dataset     the dataset for the chart (<code>null</code> permitted).
 * @param orientation the orientation (horizontal or vertical) (<code>null</code> NOT permitted).
 * @param legend      a flag specifying whether or not a legend is required.
 * @param tooltips    configure chart to generate tool tips?
 * @param urls        configure chart to generate URLs?
 * @return An XY bar chart.
 */
public static JFreeChart createXYBarChart(final String title, final String xAxisLabel, final boolean dateAxis,
        final String yAxisLabel, final XYDataset dataset, final PlotOrientation orientation,
        final boolean legend, final boolean tooltips, final boolean urls) {

    if (orientation == null) {
        throw new IllegalArgumentException("Null 'orientation' argument.");
    }
    ValueAxis domainAxis = null;
    if (dateAxis) {
        domainAxis = new DateAxis(xAxisLabel);
    } else {
        final NumberAxis axis = new NumberAxis(xAxisLabel);
        axis.setAutoRangeIncludesZero(false);
        domainAxis = axis;
    }
    final ValueAxis valueAxis = new NumberAxis(yAxisLabel);

    final XYBarRenderer renderer = new XYBarRenderer();
    renderer.setUseYInterval(true);
    if (tooltips) {
        final XYToolTipGenerator tt;
        if (dateAxis) {
            tt = StandardXYToolTipGenerator.getTimeSeriesInstance();
        } else {
            tt = new StandardXYToolTipGenerator();
        }
        renderer.setBaseToolTipGenerator(tt);
    }
    if (urls) {
        renderer.setURLGenerator(new StandardXYURLGenerator());
    }

    final XYPlot plot = new XYPlot(dataset, domainAxis, valueAxis, renderer);
    plot.setOrientation(orientation);

    return new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend);
}

From source file:org.hxzon.demo.jfreechart.XYDatasetDemo2.java

private static JFreeChart createXYBarChart(XYDataset dataset) {
    boolean dateAxis = true;
    ValueAxis domainAxis = null;/*w  ww . j a  va2s  .c o  m*/
    if (dateAxis) {
        domainAxis = new DateAxis(xAxisLabel);
    } else {
        NumberAxis axis = new NumberAxis(xAxisLabel);
        axis.setAutoRangeIncludesZero(false);
        domainAxis = axis;
    }
    ValueAxis valueAxis = new NumberAxis(yAxisLabel);

    XYBarRenderer renderer = new XYBarRenderer();
    if (tooltips) {
        XYToolTipGenerator tt;
        if (dateAxis) {
            tt = StandardXYToolTipGenerator.getTimeSeriesInstance();
        } else {
            tt = new StandardXYToolTipGenerator();
        }
        renderer.setBaseToolTipGenerator(tt);
    }
    if (urls) {
        renderer.setURLGenerator(new StandardXYURLGenerator());
    }

    XYPlot plot = new XYPlot(dataset, domainAxis, valueAxis, renderer);
    plot.setOrientation(orientation);

    JFreeChart chart = new JFreeChart("XYBar Chart Demo", JFreeChart.DEFAULT_TITLE_FONT, plot, legend);
    chart.setBackgroundPaint(Color.white);

    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);

    return chart;
}

From source file:com.itemanalysis.jmetrik.graph.itemmap.ItemMapPanel.java

public void setGraph() {
    HistogramChartDataset personDataset = null;
    HistogramChartDataset itemData = null;

    try {/*  w  w  w.  ja va  2 s.  c om*/
        //get titles
        String chartTitle = command.getFreeOption("title").getString();
        String chartSubtitle = command.getFreeOption("subtitle").getString();
        PlotOrientation itemMapOrientation = PlotOrientation.HORIZONTAL;

        //create common x-axis
        NumberAxis domainAxis = new NumberAxis();
        domainAxis.setLabel("Logits");

        //create histogram
        personDataset = new HistogramChartDataset();
        ValueAxis rangeAxis = new NumberAxis("Person Density");
        if (itemMapOrientation == PlotOrientation.HORIZONTAL)
            rangeAxis.setInverted(true);
        XYBarRenderer renderer = new XYBarRenderer();
        renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator());
        renderer.setURLGenerator(new StandardXYURLGenerator());
        renderer.setDrawBarOutline(true);
        renderer.setShadowVisible(false);
        XYPlot personPlot = new XYPlot(personDataset, null, rangeAxis, renderer);
        personPlot.setOrientation(PlotOrientation.HORIZONTAL);

        //create scatterplot of item difficulty
        itemData = new HistogramChartDataset();
        NumberAxis itemRangeAxis = new NumberAxis("Item Frequency");
        if (itemMapOrientation == PlotOrientation.VERTICAL) {
            itemRangeAxis.setInverted(true);
        }

        XYBarRenderer itemRenderer = new XYBarRenderer();
        itemRenderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator());
        itemRenderer.setURLGenerator(new StandardXYURLGenerator());
        itemRenderer.setDrawBarOutline(true);
        itemRenderer.setShadowVisible(false);
        XYPlot itemPlot = new XYPlot(itemData, null, itemRangeAxis, itemRenderer);
        itemPlot.setOrientation(PlotOrientation.HORIZONTAL);

        //combine the two charts
        CombinedDomainXYPlot cplot = new CombinedDomainXYPlot(domainAxis);
        cplot.add(personPlot, 3);
        cplot.add(itemPlot, 2);
        cplot.setGap(8.0);
        cplot.setDomainGridlinePaint(Color.white);
        cplot.setDomainGridlinesVisible(true);
        cplot.setOrientation(itemMapOrientation);

        //            //next four lines are temp setting for book
        //            //these four lines will create a histogram with white bars so it appears as just the bar outline
        //            renderer.setBarPainter(new StandardXYBarPainter());
        //            renderer.setSeriesPaint(0, Color.white);
        //            itemRenderer.setBarPainter(new StandardXYBarPainter());
        //            itemRenderer.setSeriesPaint(0, Color.white);

        chart = new JFreeChart(chartTitle, JFreeChart.DEFAULT_TITLE_FONT, cplot, false);
        chart.setBackgroundPaint(Color.white);
        if (chartSubtitle != null && !"".equals(chartSubtitle)) {
            chart.addSubtitle(new TextTitle(chartSubtitle));
        }

        ChartPanel panel = new ChartPanel(chart);
        panel.getPopupMenu().addSeparator();
        this.addJpgMenuItem(this, panel.getPopupMenu());
        panel.setPreferredSize(new Dimension(width, height));

        //            //temp setting for book
        //            this.addLocalEPSMenuItem(this, panel.getPopupMenu(), chart);//remove this line for public release versions

        chart.setPadding(new RectangleInsets(20.0, 5.0, 20.0, 5.0));
        this.setBackground(Color.WHITE);
        this.add(panel);
    } catch (IllegalArgumentException ex) {
        logger.fatal(ex.getMessage(), ex);
        this.firePropertyChange("error", "", "Error - Check log for details.");
    }

}

From source file:edu.dlnu.liuwenpeng.ChartFactory.ChartFactory.java

/**    
 * Creates and returns a default instance of an XY bar chart.    
 * <P>    //from  w  w  w.j a  va 2s .  c  o  m
 * The chart object returned by this method uses an {@link XYPlot} instance    
 * as the plot, with a {@link DateAxis} for the domain axis, a     
 * {@link NumberAxis} as the range axis, and a {@link XYBarRenderer} as the     
 * renderer.    
 *    
 * @param title  the chart title (<code>null</code> permitted).    
 * @param xAxisLabel  a label for the X-axis (<code>null</code> permitted).    
 * @param dateAxis  make the domain axis display dates?    
 * @param yAxisLabel  a label for the Y-axis (<code>null</code> permitted).    
 * @param dataset  the dataset for the chart (<code>null</code> permitted).    
 * @param orientation  the orientation (horizontal or vertical)     
 *                     (<code>null</code> NOT permitted).    
 * @param legend  a flag specifying whether or not a legend is required.    
 * @param tooltips  configure chart to generate tool tips?    
 * @param urls  configure chart to generate URLs?    
 *    
 * @return An XY bar chart.    
 */
public static JFreeChart createXYBarChart(String title, String xAxisLabel, boolean dateAxis, String yAxisLabel,
        IntervalXYDataset dataset, PlotOrientation orientation, boolean legend, boolean tooltips,
        boolean urls) {

    if (orientation == null) {
        throw new IllegalArgumentException("Null 'orientation' argument.");
    }
    ValueAxis domainAxis = null;
    if (dateAxis) {
        domainAxis = new DateAxis(xAxisLabel);
    } else {
        NumberAxis axis = new NumberAxis(xAxisLabel);
        axis.setAutoRangeIncludesZero(false);
        domainAxis = axis;
    }
    ValueAxis valueAxis = new NumberAxis(yAxisLabel);

    XYBarRenderer renderer = new XYBarRenderer();
    if (tooltips) {
        XYToolTipGenerator tt;
        if (dateAxis) {
            tt = StandardXYToolTipGenerator.getTimeSeriesInstance();
        } else {
            tt = new StandardXYToolTipGenerator();
        }
        renderer.setBaseToolTipGenerator(tt);
    }
    if (urls) {
        renderer.setURLGenerator(new StandardXYURLGenerator());
    }

    XYPlot plot = new XYPlot(dataset, domainAxis, valueAxis, renderer);
    plot.setOrientation(orientation);

    JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend);

    return chart;

}

From source file:KIDLYFactory.java

/**
 * Creates and returns a default instance of an XY bar chart.
 * <P>/*from w ww.  j a  v  a 2s .  com*/
 * The chart object returned by this method uses an {@link XYPlot} instance
 * as the plot, with a {@link DateAxis} for the domain axis, a
 * {@link NumberAxis} as the range axis, and a {@link XYBarRenderer} as the
 * renderer.
 *
 * @param title  the chart title (<code>null</code> permitted).
 * @param xAxisLabel  a label for the X-axis (<code>null</code> permitted).
 * @param dateAxis  make the domain axis display dates?
 * @param yAxisLabel  a label for the Y-axis (<code>null</code> permitted).
 * @param dataset  the dataset for the chart (<code>null</code> permitted).
 * @param orientation  the orientation (horizontal or vertical)
 *                     (<code>null</code> NOT permitted).
 * @param legend  a flag specifying whether or not a legend is required.
 * @param tooltips  configure chart to generate tool tips?
 * @param urls  configure chart to generate URLs?
 *
 * @return An XY bar chart.
 */
public static JFreeChart createXYBarChart(String title, String xAxisLabel, boolean dateAxis, String yAxisLabel,
        IntervalXYDataset dataset, PlotOrientation orientation, boolean legend, boolean tooltips,
        boolean urls) {

    if (orientation == null) {
        throw new IllegalArgumentException("Null 'orientation' argument.");
    }
    ValueAxis domainAxis = null;
    if (dateAxis) {
        domainAxis = new DateAxis(xAxisLabel);
    } else {
        NumberAxis axis = new NumberAxis(xAxisLabel);
        axis.setAutoRangeIncludesZero(false);
        domainAxis = axis;
    }
    ValueAxis valueAxis = new NumberAxis(yAxisLabel);

    XYBarRenderer renderer = new XYBarRenderer();
    if (tooltips) {
        XYToolTipGenerator tt;
        if (dateAxis) {
            tt = StandardXYToolTipGenerator.getTimeSeriesInstance();
        } else {
            tt = new StandardXYToolTipGenerator();
        }
        renderer.setBaseToolTipGenerator(tt);
    }
    if (urls) {
        renderer.setURLGenerator(new StandardXYURLGenerator());
    }

    XYPlot plot = new XYPlot(dataset, domainAxis, valueAxis, renderer);
    plot.setOrientation(orientation);

    JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend);
    currentTheme.apply(chart);
    return chart;

}