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:org.talend.dataprofiler.chart.ChartDecorator.java

public static void decorateStackedBarChart(JFreeChart chart, PlotOrientation orientation) {
    if (chart != null) {
        Plot plot = chart.getPlot();
        if (plot instanceof CategoryPlot) {
            decorateCategoryPlot(chart, orientation);
            int rowCount = chart.getCategoryPlot().getDataset().getRowCount();
            for (int i = 0; i < rowCount; i++) {
                if (i >= STACK_BAR_COLOR_LIST.size()) {
                    STACK_BAR_COLOR_LIST.add(generateRandomColor(STACK_BAR_COLOR_LIST));
                }/*w w w  .ja v  a  2  s .  com*/
                ((CategoryPlot) plot).getRenderer().setSeriesPaint(i, STACK_BAR_COLOR_LIST.get(i));
            }
        }
    }
}

From source file:org.dkpro.lab.reporting.ChartUtil.java

/**
 * Exports a JFreeChart to a scalable PDF file.
 *
 * @param chart JFreeChart to export// w  ww. ja  v  a  2  s . c  o m
 * @param aOS stream to write to.
 * @param aWidth width of the chart in pixels
 * @param aHeight height of the chart in pixels
 * @throws IOException if writing the svgFile fails.
 */
public static void writeChartAsPDF(OutputStream aOS, JFreeChart chart, int aWidth, int aHeight)
        throws IOException {
    // Create an instance of the SVG Generator
    PDFDocumentGraphics2D pdfGenerator = new PDFDocumentGraphics2D(true, aOS, aWidth, aHeight);
    pdfGenerator.setDeviceDPI(PDFDocumentGraphics2D.NORMAL_PDF_RESOLUTION);
    pdfGenerator.setGraphicContext(new GraphicContext());
    pdfGenerator.setSVGDimension(aWidth, aHeight);
    pdfGenerator.setClip(0, 0, aWidth, aHeight);
    pdfGenerator.setRenderingHint(KEY_ANTIALIASING, VALUE_ANTIALIAS_ON);
    pdfGenerator.setRenderingHint(KEY_INTERPOLATION, VALUE_INTERPOLATION_BILINEAR);
    chart.setBackgroundPaint(Color.white);
    chart.getPlot().setBackgroundPaint(Color.white);
    // draw the chart in the SVG generator
    chart.draw(pdfGenerator, new Rectangle(aWidth, aHeight));
    pdfGenerator.finish();
}

From source file:org.sipfoundry.sipxconfig.site.cdr.CdrReports.java

private static Image createTerminationCallsPieImage(List<CdrGraphBean> beans) {
    // Create a dataset
    DefaultPieDataset data = new DefaultPieDataset();

    // Fill dataset with beans data
    for (CdrGraphBean terminationCall : beans) {
        data.setValue(terminationCall.getKey(), terminationCall.getCount());
    }//ww  w. j  a v a  2s  . c o m

    // Create a chart with the dataset
    JFreeChart chart = ChartFactory.createPieChart(EMPTY_TITLE, data, true, true, true);
    chart.setBackgroundPaint(Color.lightGray);
    chart.getTitle().setPaint(Color.BLACK);

    PiePlot chartplot = (PiePlot) chart.getPlot();
    chartplot.setCircular(true);
    chartplot.setLabelGenerator(new StandardPieSectionLabelGenerator(PIECHART_SECTIONLABEL_FORMAT));
    // Create and return the image
    return chart.createBufferedImage(500, 220, BufferedImage.TYPE_INT_RGB, null);
}

From source file:com.controlj.addon.gwttree.server.GraphServlet.java

/**<!====== getChart ======================================================>
   Generates the chart.  Note that most of these options are not required
   for a simple chart, but we wanted to try to get a particular look that
   matched another charting package, so we went to some trouble to set
   a lot of non-standard options.  In particular, the OpaqueBarRenderer3D
   is a non-standard renderer that gives much better looking 3D bars.
<!=======================================================================>*/
private static JFreeChart getChart(DefaultCategoryDataset dataset) {
    JFreeChart chart = ChartFactory.createBarChart3D("Integration Over Time", "24 Hour Period", "", dataset,
            PlotOrientation.VERTICAL, true, true, false);
    chart.setBackgroundPaint(Color.black);
    chart.getTitle().setPaint(Color.white);
    chart.getTitle().setFont(new Font("Verdana", Font.BOLD, 20));
    chart.setAntiAlias(true);/*from w  w w .  j av a 2s.c o  m*/
    chart.setTextAntiAlias(true);
    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setForegroundAlpha(1);
    OpaqueBarRenderer3D renderer = new OpaqueBarRenderer3D();
    renderer.setItemMargin(0.1);
    plot.setRenderer(renderer);

    renderer.setSeriesPaint(0, new Color(116, 225, 118));
    renderer.setSeriesPaint(1, new Color(245, 107, 107));
    renderer.setSeriesPaint(2, new Color(250, 187, 107));
    renderer.setSeriesPaint(3, new Color(72, 72, 238));
    renderer.setSeriesPaint(4, new Color(184, 32, 157));
    renderer.setDrawBarOutline(false);

    Font small = new Font("Verdana", Font.PLAIN, 12);
    Font big = new Font("Verdana", Font.BOLD, 14);

    renderer.setItemLabelPaint(Color.white);
    plot.getDomainAxis().setTickLabelPaint(Color.white);
    plot.getDomainAxis().setTickLabelFont(small);
    plot.getDomainAxis().setLabelPaint(Color.white);
    plot.getDomainAxis().setLabelFont(big);
    plot.getDomainAxis().setCategoryMargin(0.2);

    plot.getRangeAxis().setTickLabelPaint(Color.white);
    plot.getRangeAxis().setTickLabelFont(small);
    plot.getRangeAxis().setLabelPaint(Color.white);
    plot.getRangeAxis().setLabelFont(big);
    plot.setBackgroundPaint(Color.black);

    chart.getLegend().setBackgroundPaint(Color.black);
    chart.getLegend().setItemPaint(Color.white);
    chart.getLegend().setItemFont(big);

    return chart;
}

From source file:org.jfree.graphics2d.demo.SVGPieChartDemo1.java

/**
 * Creates a chart.//  ww w  . j a  v  a2s  .  c  o m
 *
 * @param dataset  the dataset.
 *
 * @return A chart.
 */
private static JFreeChart createChart(PieDataset dataset) {

    JFreeChart chart = ChartFactory.createPieChart("Smart Phones Manufactured / Q3 2011", // chart title
            dataset);
    chart.removeLegend();

    // set a custom background for the chart
    chart.setBackgroundPainter(new GradientPainter(new Color(20, 20, 20), RectangleAnchor.TOP_LEFT,
            Color.DARK_GRAY, RectangleAnchor.BOTTOM_RIGHT));

    // customise the title position and font
    TextTitle t = chart.getTitle();
    t.setHorizontalAlignment(HorizontalAlignment.LEFT);
    t.setPaint(new Color(240, 240, 240));
    t.setFont(new Font("Arial", Font.BOLD, 26));

    PiePlot plot = (PiePlot) chart.getPlot();
    plot.setBackgroundPainter(null);
    plot.setInteriorGap(0.04);
    plot.setBorderPainter(null);

    // use gradients and white borders for the section colours
    plot.setSectionPaint("Others", createGradientPaint(new Color(200, 200, 255), Color.BLUE));
    plot.setSectionPaint("Samsung", createGradientPaint(new Color(255, 200, 200), Color.RED));
    plot.setSectionPaint("Apple", createGradientPaint(new Color(200, 255, 200), Color.GREEN));
    plot.setSectionPaint("Nokia", createGradientPaint(new Color(200, 255, 200), Color.YELLOW));
    plot.setBaseSectionOutlinePaint(Color.WHITE);
    plot.setSectionOutlinesVisible(true);
    plot.setBaseSectionOutlineStroke(new BasicStroke(2.0f));

    // customise the section label appearance
    plot.setLabelFont(new Font("Courier New", Font.BOLD, 20));
    plot.setLabelLinkPaint(Color.WHITE);
    plot.setLabelLinkStroke(new BasicStroke(2.0f));
    plot.setLabelOutlineStroke(null);
    plot.setLabelPaint(Color.WHITE);
    plot.setLabelBackgroundPaint(null);
    // add a subtitle giving the data source
    TextTitle source = new TextTitle("Source: http://www.bbc.co.uk/news/business-15489523",
            new Font("Courier New", Font.PLAIN, 12));
    source.setPaint(Color.WHITE);
    source.setPosition(RectangleEdge.BOTTOM);
    source.setHorizontalAlignment(HorizontalAlignment.RIGHT);
    chart.addSubtitle(source);
    return chart;

}

From source file:org.talend.dataprofiler.chart.ChartDecorator.java

/**
 * DOC xqliu Comment method "decorateColumnDependency".
 * /*from  w ww.j a v a2  s  .  c om*/
 * @param chart
 */
public static void decorateColumnDependency(JFreeChart chart) {
    decorate(chart, PlotOrientation.HORIZONTAL);
    CategoryItemRenderer renderer = ((CategoryPlot) chart.getPlot()).getRenderer();
    renderer.setSeriesPaint(0, COLOR_LIST.get(1));
    renderer.setSeriesPaint(1, COLOR_LIST.get(2));
}

From source file:org.talend.dataprofiler.chart.ChartDecorator.java

/**
 * /*from  w w  w . j av a  2  s.  co m*/
 * decorate concept chart on semantic Analysis wizard.
 * 
 * @param chart
 * @param orientation
 */
public static void decorateConceptChart(JFreeChart chart, PlotOrientation orientation) {
    if (chart == null) {
        return;
    }
    Plot plot = chart.getPlot();
    if (plot instanceof CategoryPlot) {
        decorateCategoryPlot(chart, orientation);

        int rowCount = chart.getCategoryPlot().getDataset().getRowCount();

        for (int i = 0; i < rowCount; i++) {
            ((CategoryPlot) plot).getRenderer().setSeriesPaint(i, PluginConstant.PRIMARY_BLUE_AWT);
        }

    }

}

From source file:unalcol.termites.boxplots.SucessfulRates.java

private static JFreeChart createChart(CategoryDataset categorydataset, ArrayList<Double> pf) {
    JFreeChart jfreechart = ChartFactory.createBarChart("Success Rates - " + getTitle(pf), "", "",
            categorydataset, PlotOrientation.VERTICAL, true, true, false);
    jfreechart.getTitle().setFont(new Font("Sans-Serif", Font.PLAIN, 18));
    jfreechart.setBackgroundPaint(new Color(221, 223, 238));
    CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot();
    categoryplot.setBackgroundPaint(Color.white);
    categoryplot.setDomainGridlinePaint(Color.white);
    categoryplot.setRangeGridlinePaint(Color.gray);
    categoryplot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);

    BarRenderer renderer = (BarRenderer) categoryplot.getRenderer();
    //categoryplot.setBackgroundPaint(new Color(221, 223, 238));

    renderer.setSeriesPaint(0, new Color(130, 165, 70));
    renderer.setSeriesPaint(1, new Color(220, 165, 70));
    renderer.setSeriesPaint(4, new Color(255, 165, 70));
    renderer.setDrawBarOutline(false);/*ww  w  .  j  a  v  a  2 s .c om*/
    renderer.setShadowVisible(false);
    // renderer.setMaximumBarWidth(1);
    renderer.setGradientPaintTransformer(null);
    renderer.setDefaultBarPainter(new StandardBarPainter());

    categoryplot.setRenderer(renderer);

    NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis();
    numberaxis.setUpperMargin(0.25D);
    CategoryItemRenderer categoryitemrenderer = categoryplot.getRenderer();
    categoryitemrenderer.setBaseItemLabelsVisible(true);
    categoryitemrenderer.setBaseItemLabelGenerator(new LabelGenerator(null));
    numberaxis.setRange(0, 100);
    //numberaxis.setNumberFormatOverride(NumberFormat.getPercentInstance());

    Font font = new Font("SansSerif", Font.ROMAN_BASELINE, 12);
    numberaxis.setTickLabelFont(font);
    CategoryAxis axisd = categoryplot.getDomainAxis();
    ValueAxis axisr = categoryplot.getRangeAxis();
    axisd.setTickLabelFont(font);
    axisr.setTickLabelFont(font);

    final ChartPanel chartPanel = new ChartPanel(jfreechart);
    chartPanel.setPreferredSize(new java.awt.Dimension(650, 370));

    FileOutputStream output;
    try {
        output = new FileOutputStream("sucessrates1" + pf + mazeMode + ".jpg");
        ChartUtilities.writeChartAsJPEG(output, 1.0f, jfreechart, 650, 370, null);
    } catch (FileNotFoundException ex) {
        Logger.getLogger(MessagesSent1.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(MessagesSent1.class.getName()).log(Level.SEVERE, null, ex);
    }
    return jfreechart;
}

From source file:gov.llnl.lc.infiniband.opensm.plugin.gui.bargraph.AnimatedBarGraph.java

private static JFreeChart createChart(BarGraphDataSeries dataSeries) {
    if (dataSeries == null)
        return null;

    BarGraphDataSeries ds = dataSeries;/*from   ww w  . j a va2s .c  om*/

    // create the chart...
    JFreeChart chart = ChartFactory.createBarChart(ds.getTitle(), // chart title
            ds.getDomainLabel(), // domain axis label
            ds.getRangeLabel(), // range axis label
            ds.getDataSet(0), // data
            PlotOrientation.VERTICAL, // orientation
            true, // include legend
            true, // tooltips?
            false // URLs?
    );

    // get a reference to the plot for further customization...
    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setDomainGridlinesVisible(true);

    // set the range axis to display integers only...
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    // disable bar outlines...
    BarRenderer renderer = (BarRenderer) plot.getRenderer();
    renderer.setDrawBarOutline(false);

    // set up gradient paints for series...
    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));
    GradientPaint gp3 = new GradientPaint(0.0f, 0.0f, Color.yellow, 0.0f, 0.0f, new Color(64, 0, 0));
    renderer.setSeriesPaint(0, gp0);
    renderer.setSeriesPaint(1, gp1);
    renderer.setSeriesPaint(2, gp2);
    renderer.setSeriesPaint(3, gp3);

    CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0));

    ValueRange vr = ds.getRangeValueRanges().get(0);
    if (vr != null) {
        Range range = new Range(vr.getMin() / vr.getScale(), vr.getMax() / vr.getScale());
        rangeAxis.setRange(range);
    }
    return chart;

}

From source file:com.voterData.graph.Graph.java

public static JFreeChart getGenderDistChart(Map<String, Double> dataMap) {
    DefaultCategoryDataset defaultcategorydataset = new DefaultCategoryDataset();
    for (String key : dataMap.keySet()) {
        if (key.equals("Male_Dem_2008")) {
            defaultcategorydataset.addValue(dataMap.get(key), "DEM", "Male_2008");
        } else if (key.equals("Male_Rep_2008")) {
            defaultcategorydataset.addValue(dataMap.get(key), "REP", "Male_2008");
        } else if (key.equals("Male_Una_2008")) {
            defaultcategorydataset.addValue(dataMap.get(key), "UNA", "Male_2008");
        } else if (key.equals("Female_Dem_2008")) {
            defaultcategorydataset.addValue(dataMap.get(key), "DEM", "Female_2008");
        } else if (key.equals("Female_Rep_2008")) {
            defaultcategorydataset.addValue(dataMap.get(key), "REP", "Female_2008");
        } else if (key.equals("Female_Una_2008")) {
            defaultcategorydataset.addValue(dataMap.get(key), "UNA", "Female_2008");
        } else if (key.equals("Male_Dem_2012")) {
            defaultcategorydataset.addValue(dataMap.get(key), "DEM", "Male_2012");
        } else if (key.equals("Male_Rep_2012")) {
            defaultcategorydataset.addValue(dataMap.get(key), "REP", "Male_2012");
        } else if (key.equals("Male_Una_2012")) {
            defaultcategorydataset.addValue(dataMap.get(key), "UNA", "Male_2012");
        } else if (key.equals("Female_Dem_2012")) {
            defaultcategorydataset.addValue(dataMap.get(key), "DEM", "Female_2012");
        } else if (key.equals("Female_Rep_2012")) {
            defaultcategorydataset.addValue(dataMap.get(key), "REP", "Female_2012");
        } else if (key.equals("Female_Una_2012")) {
            defaultcategorydataset.addValue(dataMap.get(key), "UNA", "Female_2012");
        }/* w w  w  . j a va2s  .com*/
    }
    JFreeChart jfreechart = ChartFactory.createStackedBarChart("Gender based Distribution", "Gender_Year",
            "% of Votes", defaultcategorydataset, PlotOrientation.VERTICAL, true, true, false);
    jfreechart.setBackgroundPaint(Color.white);
    CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot();
    categoryplot.setBackgroundPaint(Color.lightGray);
    categoryplot.setRangeGridlinePaint(Color.white);
    StackedBarRenderer stackedbarrenderer = (StackedBarRenderer) categoryplot.getRenderer();
    stackedbarrenderer.setDrawBarOutline(false);
    stackedbarrenderer.setItemLabelsVisible(true);
    stackedbarrenderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
    stackedbarrenderer.setSeriesItemLabelGenerator(0, new StandardCategoryItemLabelGenerator());
    stackedbarrenderer.setSeriesPaint(0, Color.blue);
    stackedbarrenderer.setSeriesPaint(1, Color.red);
    stackedbarrenderer.setSeriesPaint(2, Color.green);
    return jfreechart;

}