Example usage for org.jfree.chart JFreeChart getPlot

List of usage examples for org.jfree.chart JFreeChart getPlot

Introduction

In this page you can find the example usage for org.jfree.chart JFreeChart getPlot.

Prototype

public Plot getPlot() 

Source Link

Document

Returns the plot for the chart.

Usage

From source file:cz.cuni.mff.ksi.jinfer.attrstats.JFCWrapper.java

private static JFreeChart createChart(final String title, final PieDataset dataset) {
    final JFreeChart chart = ChartFactory.createPieChart(title, dataset, false, true, false);

    final PiePlot plot = (PiePlot) chart.getPlot();
    plot.setLabelFont(new Font("SansSerif", Font.PLAIN, 12));
    plot.setNoDataMessage("No data available");
    plot.setCircular(true);//from www  .  j  av a 2  s  .  c o  m
    plot.setLabelGap(0.02);
    return chart;
}

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

private static JFreeChart createChart(TableXYDataset tablexydataset) {
    JFreeChart jfreechart = ChartFactory.createStackedXYAreaChart("Stacked XY Area Chart Demo 1", "X Value",
            "Y Value", tablexydataset, PlotOrientation.VERTICAL, true, true, false);
    XYPlot xyplot = (XYPlot) jfreechart.getPlot();
    StackedXYAreaRenderer stackedxyarearenderer = new StackedXYAreaRenderer();
    stackedxyarearenderer.setSeriesPaint(0, Color.lightGray);
    stackedxyarearenderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator());
    xyplot.setRenderer(0, stackedxyarearenderer);
    xyplot.setDomainCrosshairVisible(true);
    xyplot.setRangeCrosshairVisible(true);
    return jfreechart;
}

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

private static JFreeChart createChart(XYDataset xydataset) {
    JFreeChart jfreechart = ChartFactory.createXYAreaChart("XYAreaRenderer2Demo1", "Domain (X)", "Range (Y)",
            xydataset, PlotOrientation.VERTICAL, true, true, false);
    XYPlot xyplot = (XYPlot) jfreechart.getPlot();
    xyplot.setRenderer(new XYAreaRenderer2());
    xyplot.setForegroundAlpha(0.65F);/* w w w  .ja  va  2 s. c o m*/
    ValueAxis valueaxis = xyplot.getDomainAxis();
    valueaxis.setTickMarkPaint(Color.black);
    valueaxis.setLowerMargin(0.0D);
    valueaxis.setUpperMargin(0.0D);
    ValueAxis valueaxis1 = xyplot.getRangeAxis();
    valueaxis1.setTickMarkPaint(Color.black);
    return jfreechart;
}

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/*  w  w w  .j a  v  a2 s. co  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:umberto.WeightedClusterCoefficient.ChartUtils.java

public static void scaleLogChart(JFreeChart chart, XYSeries dSeries, boolean normalized) {
    XYPlot plot = (XYPlot) chart.getPlot();
    final LogAxis logyAxis = new LogAxis(plot.getRangeAxis().getLabel());
    final LogAxis logxAxis = new LogAxis(plot.getDomainAxis().getLabel());
    //Set y axis format.
    //        DecimalFormat formaty = (DecimalFormat) DecimalFormat.getNumberInstance(Locale.ENGLISH);
    //        formaty.applyPattern("#0.0000");

    //set y axis/*from w  ww .  j  av a  2  s .  c  om*/
    logyAxis.setBase(10);
    //        logyAxis.setNumberFormatOverride(formaty);
    logyAxis.setStandardTickUnits(LogAxis.createLogTickUnits(Locale.ENGLISH));
    //        logyAxis.setRange(0.01, 1.0);
    logyAxis.setAutoRange(true);
    plot.setRangeAxis(logyAxis);
    //set x axis
    logxAxis.setBase(10);
    logxAxis.setStandardTickUnits(LogAxis.createLogTickUnits(Locale.ENGLISH));
    logxAxis.setAutoRange(true);
    //logxAxis.setRange(0.00001, 1.0);//Se la voglio zoommare
    plot.setDomainAxis(logxAxis);
}

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   w ww.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:org.gbif.portal.web.util.ChartUtils.java

/**
 * Writes out the image using the supplied file name.
 * //ww w. ja va  2 s  . c  om
 * @param legend
 * @param fileName
 * @return
 */
public static String writePieChartImageToTempFile(Map<String, Double> legend, String fileName) {

    String filePath = System.getProperty(tmpDirSystemProperty) + File.separator + fileName + defaultExtension;
    File fileToCheck = new File(filePath);
    if (fileToCheck.exists()) {
        return fileName + defaultExtension;
    }

    final DefaultPieDataset data = new DefaultPieDataset();
    Set<String> keys = legend.keySet();
    for (String key : keys) {
        logger.info("Adding key : " + key);
        data.setValue(key, legend.get(key));
    }

    // create a pie chart...
    final boolean withLegend = true;
    final JFreeChart chart = ChartFactory.createPieChart(null, data, withLegend, false, false);

    PiePlot piePlot = (PiePlot) chart.getPlot();
    piePlot.setLabelFont(new Font("Arial", Font.PLAIN, 10));
    piePlot.setLabelBackgroundPaint(Color.WHITE);

    LegendTitle lt = chart.getLegend();
    lt.setBackgroundPaint(Color.WHITE);
    lt.setWidth(300);
    lt.setBorder(0, 0, 0, 0);
    lt.setItemFont(new Font("Arial", Font.PLAIN, 11));

    chart.setPadding(new RectangleInsets(0, 0, 0, 0));
    chart.setBorderVisible(false);
    chart.setBackgroundImageAlpha(0);
    chart.setBackgroundPaint(Color.WHITE);
    chart.setBorderPaint(Color.LIGHT_GRAY);

    final BufferedImage image = new BufferedImage(300, 250, BufferedImage.TYPE_INT_RGB);
    KeypointPNGEncoderAdapter adapter = new KeypointPNGEncoderAdapter();
    adapter.setQuality(1);
    try {
        adapter.encode(image);
    } catch (IOException e) {
        logger.error(e.getMessage(), e);
    }
    final Graphics2D g2 = image.createGraphics();
    g2.setFont(new Font("Arial", Font.PLAIN, 11));
    final Rectangle2D chartArea = new Rectangle2D.Double(0, 0, 300, 250);

    // draw
    chart.draw(g2, chartArea, null, null);

    try {
        FileOutputStream fOut = new FileOutputStream(fileToCheck);
        ChartUtilities.writeChartAsPNG(fOut, chart, 300, 250);
        return fileToCheck.getName();
    } catch (IOException e) {
        logger.error(e.getMessage(), e);
        return null;
    }
}

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

private static JFreeChart createChart(BoxAndWhiskerCategoryDataset boxandwhiskercategorydataset) {
    JFreeChart jfreechart = ChartFactory.createBoxAndWhiskerChart("Box and Whisker Chart Demo 1", "Category",
            "Value", boxandwhiskercategorydataset, true);
    CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot();
    jfreechart.setBackgroundPaint(Color.white);
    categoryplot.setBackgroundPaint(Color.lightGray);
    categoryplot.setDomainGridlinePaint(Color.white);
    categoryplot.setDomainGridlinesVisible(true);
    categoryplot.setRangeGridlinePaint(Color.white);
    NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis();
    numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    return jfreechart;
}

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

private static JFreeChart createChart(XYDataset xydataset) {
    JFreeChart chart = ChartFactory.createXYLineChart("DeviationRenderer - Demo 3", "X", "Y", xydataset,
            PlotOrientation.VERTICAL, false, true, false);
    XYPlot plot = (XYPlot) chart.getPlot();
    ////from   w w w  .  j  a v  a2 s  .  c om
    DeviationRenderer renderer = new DeviationRenderer(false, false);
    renderer.setSeriesStroke(0, new BasicStroke(3F, 1, 1));
    renderer.setSeriesStroke(0, new BasicStroke(3F, 1, 1));
    renderer.setSeriesStroke(1, new BasicStroke(3F, 1, 1));
    renderer.setSeriesFillPaint(0, Color.red);
    renderer.setSeriesFillPaint(1, Color.orange);
    renderer.setSeriesFillPaint(2, Color.green);
    plot.setRenderer(renderer);
    //
    DateAxis domainAxis = new DateAxis("Date");
    domainAxis.setLowerMargin(0.0D);
    domainAxis.setUpperMargin(0.0D);
    plot.setDomainAxis(domainAxis);
    NumberAxis valueAxis = (NumberAxis) plot.getRangeAxis();
    valueAxis.setRange(-40D, 40D);
    valueAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    ChartUtilities.applyCurrentTheme(chart);
    return chart;
}

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

private static JFreeChart createChart(TableXYDataset tablexydataset) {
    JFreeChart jfreechart = ChartFactory.createStackedXYAreaChart("Stacked XY Area Chart Demo 3", "X Value",
            "Y Value", tablexydataset, PlotOrientation.VERTICAL, true, true, false);
    XYPlot xyplot = (XYPlot) jfreechart.getPlot();
    DateAxis dateaxis = new DateAxis("Date");
    xyplot.setDomainAxis(dateaxis);/* ww w.  j a va2 s .  c  o  m*/
    dateaxis.setLowerMargin(0.0D);
    dateaxis.setUpperMargin(0.0D);
    StackedXYAreaRenderer2 stackedxyarearenderer2 = (StackedXYAreaRenderer2) xyplot.getRenderer();
    stackedxyarearenderer2.setRoundXCoordinates(true);
    return jfreechart;
}