Example usage for org.jfree.chart.plot PiePlot setURLGenerator

List of usage examples for org.jfree.chart.plot PiePlot setURLGenerator

Introduction

In this page you can find the example usage for org.jfree.chart.plot PiePlot setURLGenerator.

Prototype

public void setURLGenerator(PieURLGenerator generator) 

Source Link

Document

Sets the URL generator and sends a PlotChangeEvent to all registered listeners.

Usage

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

/**
 * The starting point for the demo.//from   www  .ja va  2s . co  m
 *
 * @param args  ignored.
 */
public static void main(final String[] args) {

    // create a chart
    final DefaultPieDataset data = new DefaultPieDataset();
    data.setValue("One", new Double(43.2));
    data.setValue("Two", new Double(10.0));
    data.setValue("Three", new Double(27.5));
    data.setValue("Four", new Double(17.5));
    data.setValue("Five", new Double(11.0));
    data.setValue("Six", new Double(19.4));

    JFreeChart chart = null;
    final boolean drilldown = true;

    // create the chart...
    if (drilldown) {
        final PiePlot plot = new PiePlot(data);
        //          plot.setInsets(new Insets(0, 5, 5, 5));
        plot.setToolTipGenerator(new StandardPieItemLabelGenerator());
        plot.setURLGenerator(new StandardPieURLGenerator("pie_chart_detail.jsp"));
        chart = new JFreeChart("Pie Chart Demo 1", JFreeChart.DEFAULT_TITLE_FONT, plot, true);
    } else {
        chart = ChartFactory.createPieChart("Pie Chart Demo 1", // chart title
                data, // data
                true, // include legend
                true, false);
    }
    chart.setBackgroundPaint(java.awt.Color.white);

    // ****************************************************************************
    // * JFREECHART DEVELOPER GUIDE                                               *
    // * The JFreeChart Developer Guide, written by David Gilbert, is available   *
    // * to purchase from Object Refinery Limited:                                *
    // *                                                                          *
    // * http://www.object-refinery.com/jfreechart/guide.html                     *
    // *                                                                          *
    // * Sales are used to provide funding for the JFreeChart project - please    * 
    // * support us so that we can continue developing free software.             *
    // ****************************************************************************

    // save it to an image
    try {
        final ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());
        final File file1 = new File("piechart100.png");
        ChartUtilities.saveChartAsPNG(file1, chart, 600, 400, info);

        // write an HTML page incorporating the image with an image map
        final File file2 = new File("piechart100.html");
        final OutputStream out = new BufferedOutputStream(new FileOutputStream(file2));
        final PrintWriter writer = new PrintWriter(out);
        writer.println("<HTML>");
        writer.println("<HEAD><TITLE>JFreeChart Image Map Demo 2</TITLE></HEAD>");
        writer.println("<BODY>");
        //            ChartUtilities.writeImageMap(writer, "chart", info);
        writer.println("<IMG SRC=\"piechart100.png\" "
                + "WIDTH=\"600\" HEIGHT=\"400\" BORDER=\"0\" USEMAP=\"#chart\">");
        writer.println("</BODY>");
        writer.println("</HTML>");
        writer.close();

    } catch (IOException e) {
        System.out.println(e.toString());
    }

}

From source file:nl.wur.plantbreeding.www.marker2seq.GoDistribution.java

/**
 * Generate the Pie chart for a set of given Go terms.
 * @param distrib a HashMap of GO name and GO frequency
 * @param title the title of the GO graph
 * @param url the url used for the tooltips
 * @param session the HttpSession used to save the file
 * @param legend Print the legend or not
 * @param tooltips Add tooltip or not//from ww w. j  a  v  a  2  s .c o  m
 * @param urls Add urls or not (link in the graph)
 * @param max Maximum number of item to display
 * @return a list containing the filename and the map for the figure
 * @throws IOException when something happens while writting the image
 */
public static String[] generateDistribution(final HashMap<String, Integer> distrib, final String title,
        final String url, final HttpSession session, final boolean legend, final boolean tooltips,
        final boolean urls, final int max) throws IOException {

    final PieChart piec = new PieChart();
    final PieDataset piedata = piec.createDataset(distrib);

    final JFreeChart chart = piec.createChart(piedata, title, legend, tooltips, urls);
    final PiePlot plot = (PiePlot) chart.getPlot();
    if (distrib.size() >= max) {
        plot.setLabelGenerator(null);
    }
    plot.setURLGenerator(new StandardPieURLGenerator(url, "section"));

    final ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());

    final String filename = ServletUtilities.saveChartAsPNG(chart, 500, 400, info, session);

    final String map = ChartUtilities.getImageMap(filename, info);

    final String[] output = { filename, map };
    return output;
}

From source file:nl.wur.plantbreeding.www.marker2seq.GoDistribution.java

/**
 * Generate the Pie chart for a set of given Go terms.
 * @param gotermlist of String (here GO names)
 * @param title the title of the GO graph
 * @param url the url used for the tooltips
 * @param session the HttpSession used to save the file
 * @param legend Print the legend or not
 * @param tooltips Add tooltip or not//  ww  w. j  a  v a  2  s.c  o m
 * @param urls Add urls or not (link in the graph)
 * @param max Maximum number of item to display
 * @return a list containing the filename and the map for the figure
 * @throws IOException when something happens while writting the image
 */
public static String[] generateDistribution(final List<String> gotermlist, final String title, final String url,
        final HttpSession session, final boolean legend, final boolean tooltips, final boolean urls,
        final int max) throws IOException {
    final PieChart piec = new PieChart();
    final PieDataset dataset = piec.createDataset(gotermlist);
    final JFreeChart chart = piec.createChart(dataset, title, legend, tooltips, urls);
    final PiePlot plot = (PiePlot) chart.getPlot();
    if (gotermlist.size() >= max) {
        plot.setLabelGenerator(null);
    }
    plot.setURLGenerator(new StandardPieURLGenerator(url, "section"));

    final ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());

    final String filename = ServletUtilities.saveChartAsPNG(chart, 500, 400, info, session);

    final String map = ChartUtilities.getImageMap(filename, info);

    final String[] output = { filename, map };
    return output;

}

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

private static JFreeChart createPieChart(PieDataset dataset) {

    PiePlot plot = new PiePlot(dataset);
    plot.setLabelGenerator(new StandardPieSectionLabelGenerator());
    plot.setInsets(new RectangleInsets(0.0, 5.0, 5.0, 5.0));
    if (tooltips) {
        plot.setToolTipGenerator(new StandardPieToolTipGenerator());
    }//from  w  w  w .  java  2  s. c om
    if (urls) {
        plot.setURLGenerator(new StandardPieURLGenerator());
    }
    JFreeChart chart = new JFreeChart("Pie Chart Demo 1", JFreeChart.DEFAULT_TITLE_FONT, plot, legend);
    plot.setSectionOutlinesVisible(false);
    plot.setNoDataMessage("No data available");

    return chart;

}

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

private static JFreeChart createPieChart(PieDataset dataset, PieDataset previousDataset) {
    final boolean greenForIncrease = true;
    final boolean subTitle = true;
    final boolean showDifference = true;
    int percentDiffForMaxScale = 20;
    PiePlot plot = new PiePlot(dataset);
    plot.setLabelGenerator(new StandardPieSectionLabelGenerator());
    plot.setInsets(new RectangleInsets(0.0, 5.0, 5.0, 5.0));

    if (tooltips) {
        plot.setToolTipGenerator(new StandardPieToolTipGenerator());
    }/*  ww  w . j  a  v a 2s .com*/
    if (urls) {
        plot.setURLGenerator(new StandardPieURLGenerator());
    }

    @SuppressWarnings({ "rawtypes", "unchecked" })
    List<Comparable> keys = dataset.getKeys();
    DefaultPieDataset series = null;
    if (showDifference) {
        series = new DefaultPieDataset();
    }

    double colorPerPercent = 255.0 / percentDiffForMaxScale;
    for (@SuppressWarnings("rawtypes")
    Comparable key : keys) {
        Number newValue = dataset.getValue(key);
        Number oldValue = previousDataset.getValue(key);

        if (oldValue == null) {
            if (greenForIncrease) {
                plot.setSectionPaint(key, Color.green);
            } else {
                plot.setSectionPaint(key, Color.red);
            }
            if (showDifference) {
                series.setValue(key + " (+100%)", newValue);
            }
        } else {
            double percentChange = (newValue.doubleValue() / oldValue.doubleValue() - 1.0) * 100.0;
            double shade = (Math.abs(percentChange) >= percentDiffForMaxScale ? 255
                    : Math.abs(percentChange) * colorPerPercent);
            if (greenForIncrease && newValue.doubleValue() > oldValue.doubleValue()
                    || !greenForIncrease && newValue.doubleValue() < oldValue.doubleValue()) {
                plot.setSectionPaint(key, new Color(0, (int) shade, 0));
            } else {
                plot.setSectionPaint(key, new Color((int) shade, 0, 0));
            }
            if (showDifference) {
                series.setValue(
                        key + " (" + (percentChange >= 0 ? "+" : "")
                                + NumberFormat.getPercentInstance().format(percentChange / 100.0) + ")",
                        newValue);
            }
        }
    }

    if (showDifference) {
        plot.setDataset(series);
    }

    JFreeChart chart = new JFreeChart("Pie Chart Demo 2", JFreeChart.DEFAULT_TITLE_FONT, plot, legend);

    if (subTitle) {
        TextTitle subtitle = null;
        subtitle = new TextTitle("Bright " + (greenForIncrease ? "red" : "green") + "=change >=-"
                + percentDiffForMaxScale + "%, Bright " + (!greenForIncrease ? "red" : "green") + "=change >=+"
                + percentDiffForMaxScale + "%", new Font("SansSerif", Font.PLAIN, 10));
        chart.addSubtitle(subtitle);
    }
    plot.setNoDataMessage("No data available");

    return chart;

}

From source file:ca.sqlpower.wabit.swingui.chart.ChartSwingUtil.java

/**
 * Creates a chart that displays multiple 3D pie plots that have a GradientPaintTransformer.  
 * The chart object returned by this method uses a {@link MultiplePiePlot} instance as the plot.
 *
 * @param title  the chart title (<code>null</code> permitted).
 * @param dataset  the dataset (<code>null</code> permitted).
 * @param order  the order that the data is extracted (by row or by column)
 *               (<code>null</code> not permitted).
 * @param legend  include a legend?//from w w w  .j  a v  a  2 s  . c om
 * @param tooltips  generate tooltips?
 * @param urls  generate URLs?
 *
 * @return A chart.
 */
private static JFreeChart createPieChart(String title, CategoryDataset dataset, TableOrder order,
        boolean legend, boolean tooltips, boolean urls) {

    if (order == null) {
        throw new IllegalArgumentException("Null 'order' argument.");
    }
    MultiplePiePlot plot = new MultiplePiePlot(dataset);
    plot.setDataExtractOrder(order);
    plot.setBackgroundPaint(null);
    plot.setOutlineStroke(null);

    JFreeChart pieChart = new JFreeChart(new PiePlot3DGradient(null));
    TextTitle seriesTitle = new TextTitle("Series Title", new Font("SansSerif", Font.BOLD, 10));
    seriesTitle.setPosition(RectangleEdge.BOTTOM);
    pieChart.setTitle(seriesTitle);
    pieChart.getTitle().setPadding(0, 0, 0, 0);
    pieChart.removeLegend();
    pieChart.setBackgroundPaint(null);
    pieChart.setPadding(new RectangleInsets(0, 0, 0, 0));
    pieChart.getPlot().setInsets(new RectangleInsets(0, 0, 0, 0));
    plot.setPieChart(pieChart);

    if (tooltips) {
        PieToolTipGenerator tooltipGenerator = new StandardPieToolTipGenerator();
        PiePlot pp = (PiePlot) plot.getPieChart().getPlot();
        pp.setToolTipGenerator(tooltipGenerator);
    }

    if (urls) {
        PieURLGenerator urlGenerator = new StandardPieURLGenerator();
        PiePlot pp = (PiePlot) plot.getPieChart().getPlot();
        pp.setURLGenerator(urlGenerator);
    }

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

}

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

private static JFreeChart createMultiplePieChart3D_2(CategoryDataset dataset) {

    MultiplePiePlot plot = new MultiplePiePlot(dataset);
    plot.setDataExtractOrder(TableOrder.BY_ROW);
    plot.setBackgroundPaint(null);/*from ww  w .  j  a v a  2s  .  c  om*/
    plot.setOutlineStroke(null);

    JFreeChart pieChart = new JFreeChart(new PiePlot3D(null));
    TextTitle seriesTitle = new TextTitle("Series Title", new Font("SansSerif", Font.BOLD, 12));
    seriesTitle.setPosition(RectangleEdge.BOTTOM);
    pieChart.setTitle(seriesTitle);
    pieChart.removeLegend();
    pieChart.setBackgroundPaint(null);
    plot.setPieChart(pieChart);

    if (tooltips) {
        PieToolTipGenerator tooltipGenerator = new StandardPieToolTipGenerator();
        PiePlot pp = (PiePlot) plot.getPieChart().getPlot();
        pp.setToolTipGenerator(tooltipGenerator);
    }

    if (urls) {
        PieURLGenerator urlGenerator = new StandardPieURLGenerator();
        PiePlot pp = (PiePlot) plot.getPieChart().getPlot();
        pp.setURLGenerator(urlGenerator);
    }

    JFreeChart chart = new JFreeChart("MultiplePie Chart 3D Demo 2", JFreeChart.DEFAULT_TITLE_FONT, plot,
            legend);
    chart.setBackgroundPaint(Color.white);

    return chart;

}

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

private static JFreeChart createMultiplePieChart3D(CategoryDataset dataset) {

    MultiplePiePlot plot = new MultiplePiePlot(dataset);
    plot.setDataExtractOrder(TableOrder.BY_COLUMN);
    plot.setBackgroundPaint(null);/*from   w  w  w . j  av  a  2  s  .co  m*/
    plot.setOutlineStroke(null);

    JFreeChart pieChart = new JFreeChart(new PiePlot3D(null));
    TextTitle seriesTitle = new TextTitle("Series Title", new Font("SansSerif", Font.BOLD, 12));
    seriesTitle.setPosition(RectangleEdge.BOTTOM);
    pieChart.setTitle(seriesTitle);
    pieChart.removeLegend();
    pieChart.setBackgroundPaint(null);
    plot.setPieChart(pieChart);

    if (tooltips) {
        PieToolTipGenerator tooltipGenerator = new StandardPieToolTipGenerator();
        PiePlot pp = (PiePlot) plot.getPieChart().getPlot();
        pp.setToolTipGenerator(tooltipGenerator);
    }

    if (urls) {
        PieURLGenerator urlGenerator = new StandardPieURLGenerator();
        PiePlot pp = (PiePlot) plot.getPieChart().getPlot();
        pp.setURLGenerator(urlGenerator);
    }

    JFreeChart chart = new JFreeChart("MultiplePie Chart 3D Demo 1", JFreeChart.DEFAULT_TITLE_FONT, plot,
            legend);
    chart.setBackgroundPaint(Color.white);

    PiePlot piePlot = (PiePlot) pieChart.getPlot();

    GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, Color.blue, 0.0f, 0.0f, new Color(0, 0, 64));
    GradientPaint gp1 = new GradientPaint(0.0f, 0.0f, Color.green, 0.0f, 0.0f, new Color(0, 64, 0));
    GradientPaint gp2 = new GradientPaint(0.0f, 0.0f, Color.red, 0.0f, 0.0f, new Color(64, 0, 0));
    piePlot.setSectionPaint("First", gp0);
    piePlot.setSectionPaint("Second", gp1);
    piePlot.setSectionPaint("Third", gp2);

    return chart;

}

From source file:com.ewcms.plugin.report.generate.service.chart.ChartGenerationService.java

/**
 * /*from   w  w  w  .j a va  2s  .  co m*/
 *
 * @param title 
 * @param titleFont 
 * @param data ??
 * @param order
 * @param legend 
 * @param tooltips ????
 * @param urls ??URL
 * @param urlGenerator
 *
 * @return 
 */
public static JFreeChart createPieChart(String title, java.awt.Font titleFont, CategoryDataset data,
        TableOrder order, boolean legend, boolean tooltips, boolean urls, PieURLGenerator urlGenerator) {
    MultiplePiePlot plot = new MultiplePiePlot(data);
    plot.setDataExtractOrder(order);

    PiePlot pp = (PiePlot) plot.getPieChart().getPlot();
    // pp.setInsets(new Insets(0, 5, 5, 5));
    pp.setBackgroundPaint(null);
    pp.setOutlineStroke(null);
    // plot.setOutlineStroke(null);
    PieToolTipGenerator tooltipGenerator = null;
    if (tooltips) {
        tooltipGenerator = new StandardPieToolTipGenerator();
    }

    // PieURLGenerator urlGenerator = null;
    if (!urls) {
        urlGenerator = null;
    }

    pp.setToolTipGenerator(tooltipGenerator);
    pp.setLabelGenerator(null);
    pp.setURLGenerator(urlGenerator);

    JFreeChart chart = new JFreeChart(title, titleFont, plot, legend);

    return chart;

}

From source file:com.tonbeller.jpivot.chart.ChartFactory.java

/**
 * Creates a chart containing multiple pie charts, from a TableDataset.
 *
 * @param title  the chart title./* ww w. j av  a2 s.co m*/
 * @param data  the dataset for the chart.
 * @param extractType  <code>PER_ROW</code> or <code>PER_COLUMN</code> (defined in 
 *                     {@link PiePlot}).
 * @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 a pie chart.
 */
public static JFreeChart createPieChart(String title, java.awt.Font titleFont, CategoryDataset data,
        TableOrder order, boolean legend, boolean tooltips, boolean urls, PieURLGenerator urlGenerator) {

    MultiplePiePlot plot = new MultiplePiePlot(data);
    plot.setDataExtractOrder(order);

    PiePlot pp = (PiePlot) plot.getPieChart().getPlot();
    //pp.setInsets(new Insets(0, 5, 5, 5));
    pp.setBackgroundPaint(null);
    // no outline around each piechart
    pp.setOutlineStroke(null);
    //plot.setOutlineStroke(null);
    PieToolTipGenerator tooltipGenerator = null;
    if (tooltips) {
        tooltipGenerator = new StandardPieToolTipGenerator();
    }

    //PieURLGenerator urlGenerator = null;
    if (!urls) {
        urlGenerator = null;
    }

    pp.setToolTipGenerator(tooltipGenerator);
    pp.setLabelGenerator(null);
    pp.setURLGenerator(urlGenerator);

    JFreeChart chart = new JFreeChart(title, titleFont, plot, legend);

    return chart;

}