Example usage for org.jfree.chart JFreeChart setBackgroundPaint

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

Introduction

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

Prototype

public void setBackgroundPaint(Paint paint) 

Source Link

Document

Sets the paint used to fill the chart background and sends a ChartChangeEvent to all registered listeners.

Usage

From source file:utils.Graphs.java

public static File generate(File baseFolder, String titles[], int[] values, Color backgroundColor) {
    DefaultPieDataset dataset = new DefaultPieDataset();

    // add our data values
    int i = -1;//from  w w w.  j  a  v  a2 s .c  o m
    for (String title : titles) {
        i++;
        dataset.setValue(title, values[i]);
    }

    final JFreeChart chart =
            //                ChartFactory.createPieChart("", dataset, true, true, false);

            ChartFactory.createPieChart("", // chart title
                    dataset, // data
                    true, // include legend
                    true, false);

    PiePlot plot = (PiePlot) chart.getPlot();
    //PiePlot3D plot = (PiePlot3D) chart.getPlot();
    //plot.setStartAngle(290);
    plot.setStartAngle(45);
    plot.setDirection(Rotation.CLOCKWISE);
    plot.setForegroundAlpha(0.5f);

    //        final PiePlot plot = (PiePlot) chart.getPlot();
    plot.setBackgroundPaint(backgroundColor);

    //        plot.setLegendLabelGenerator(
    //        new StandardPieSectionLabelGenerator("{0} {2}"));

    chart.setBorderVisible(false);
    chart.getPlot().setOutlineVisible(false);
    chart.getLegend().setFrame(BlockBorder.NONE);

    // get the same background
    chart.setBackgroundPaint(backgroundColor);
    chart.getLegend().setBackgroundPaint(backgroundColor);

    // hide the shadow effects
    plot.setShadowXOffset(0);
    plot.setShadowYOffset(0);

    //chart.getLegend().setVisible(false);

    plot.setCircular(true);
    //plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0} {2}", NumberFormat.getNumberInstance(), NumberFormat
    plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{2}", NumberFormat.getNumberInstance(),
            NumberFormat.getPercentInstance()));
    plot.setNoDataMessage("No data found.");

    Color greenColor = new Color(0x8FBC0C);
    Color redColor = new Color(0xFF0000);
    //Color redColor = new Color(0xDA6022);

    plot.setSectionPaint(0, greenColor);
    plot.setSectionPaint(1, redColor);
    plot.setSectionOutlinesVisible(true);

    final ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());
    final File file = new File(baseFolder, "chart.png");
    try {
        ChartUtilities.saveChartAsPNG(file, chart, 200, 160, info);
    } catch (IOException ex) {
        Logger.getLogger(Graphs.class.getName()).log(Level.SEVERE, null, ex);
    }
    //        
    ////        final ChartPanel chartPanel = new ChartPanel(chart, true);
    //       final ChartPanel chartPanel = new ChartPanel(chart, true);
    //        chartPanel.setMinimumDrawWidth(0);
    //        chartPanel.setMaximumDrawWidth(Integer.MAX_VALUE);
    //        chartPanel.setMinimumDrawHeight(0);
    //        chartPanel.setMaximumDrawHeight(Integer.MAX_VALUE);
    //        JDialog dialog = new JDialog();
    //        dialog.add(chartPanel);
    //        dialog.setLayout(new GridLayout(1, 1));
    //        dialog.setSize(400, 200);
    //        dialog.setVisible(true);

    return file;
}

From source file:jenkins.plugins.livingdoc.chart.ProjectSummaryChart.java

private void customizeChart(JFreeChart chart) {

    chart.setBackgroundPaint(Color.white);

    CategoryPlot plot = (CategoryPlot) chart.getPlot();

    adjustBound(plot.getRangeAxis());/*from w  w  w.  ja va2s .  c o  m*/

    CategoryItemRenderer renderer = plot.getRenderer();
    renderer.setSeriesPaint(SUCCESS_SERIES, GREEN_COLOR);
    renderer.setSeriesPaint(FAILURES_SERIES, Color.red);

    LineAndShapeRenderer lineAndShapeRenderer = (LineAndShapeRenderer) renderer;
    lineAndShapeRenderer.setBaseItemLabelGenerator(new NumberLabelGenerator());
    lineAndShapeRenderer.setBaseItemLabelsVisible(true);
    lineAndShapeRenderer.setBaseShapesVisible(true);
    lineAndShapeRenderer.setDrawOutlines(true);
    lineAndShapeRenderer.setUseFillPaint(true);

    renderer.setBaseStroke(new BasicStroke(2.0f));
}

From source file:playground.dgrether.linkanalysis.DgCountPerIterationGraph.java

public JFreeChart createChart() {
    XYPlot plot = new XYPlot();
    ValueAxis xAxis = this.axisBuilder.createValueAxis("Iteration");
    xAxis.setRange(this.controllerConfig.getFirstIteration(), this.controllerConfig.getLastIteration() + 2);
    ValueAxis yAxis = this.axisBuilder.createValueAxis("Trips");
    //      yAxis.setRange(-0.05, 0.3);
    //      xAxis.setVisible(false);
    //      xAxis.setFixedAutoRange(1.0);
    plot.setDomainAxis(xAxis);//from  w  w w.j  av a 2 s . c o m
    plot.setRangeAxis(yAxis);

    plot.setDataset(0, this.dataset);

    DgColorScheme colorScheme = new DgColorScheme();
    XYItemRenderer renderer2;
    renderer2 = new XYLineAndShapeRenderer(true, true);
    for (int i = 0; i < this.dataset.getSeriesCount(); i++) {
        renderer2.setSeriesItemLabelsVisible(i, true);
        renderer2.setSeriesOutlineStroke(i, new BasicStroke(3.0f));
        renderer2.setSeriesStroke(i, new BasicStroke(2.0f));
        renderer2.setSeriesPaint(i, colorScheme.getColor(i + 1, "a"));
    }
    //      renderer2.setSeriesItemLabelGenerator(0, this.labelGenerator);
    //      renderer2.setSeriesStroke(1, new BasicStroke(2.0f));
    //      renderer2.setSeriesOutlineStroke(1, new BasicStroke(3.0f));
    //      renderer2.setSeriesPaint(1, colorScheme.getColor(2, "a"));

    plot.setRenderer(0, renderer2);

    JFreeChart chart = new JFreeChart("", plot);
    chart.setBackgroundPaint(ChartColor.WHITE);
    chart.getLegend().setItemFont(this.axisBuilder.getAxisFont());
    chart.setTextAntiAlias(true);
    //      chart.removeLegend();
    return chart;
}

From source file:net.relet.freimap.NodeInfo.java

private void sexupLayout(JFreeChart chart) {
    chart.setAntiAlias(true);/*from   ww  w.j ava2  s.  c o  m*/
    chart.setBackgroundPaint(VisorFrame.bgcolor);
    chart.setBorderVisible(false);
    TextTitle title = chart.getTitle();
    title.setFont(VisorFrame.smallerfont);
    title.setPaint(VisorFrame.fgcolor);
    XYPlot plot = chart.getXYPlot();
    plot.setBackgroundPaint(VisorFrame.bgcolor);
    plot.setDomainAxis(new DateAxis());
    sexupAxis(plot.getDomainAxis());
    sexupAxis(plot.getRangeAxis());
}

From source file:org.sonar.server.charts.deprecated.BaseChart.java

protected void configureChart(JFreeChart chart, RectangleEdge legendPosition) {
    chart.setBackgroundPaint(new Color(255, 255, 255, 0));
    chart.setBackgroundImageAlpha(0.0f);
    chart.setBorderVisible(false);//w  w  w.j a v  a 2s.co  m
    chart.setAntiAlias(true);
    chart.setTextAntiAlias(true);

    chart.removeLegend();
    if (legendPosition != null) {
        LegendTitle legend = new LegendTitle(chart.getPlot());
        legend.setPosition(legendPosition);
        legend.setItemPaint(BASE_COLOR);
        chart.addSubtitle(legend);
    }
}

From source file:weka.core.ChartUtils.java

/**
 * Create a pie chart from summary data (i.e. a list of values and their
 * corresponding frequencies).//from  w ww.  ja  va 2 s.  co  m
 * 
 * @param values a list of values for the chart
 * @param freqs a list of corresponding frequencies
 * @param showLabels true if the chart will show labels
 * @param showLegend true if the chart will show a legend
 * @param additionalArgs optional arguments to the renderer (may be null)
 * @return a pie chart
 * @throws Exception if a problem occurs
 */
protected static JFreeChart getPieChartFromSummaryData(List<String> values, List<Double> freqs,
        boolean showLabels, boolean showLegend, List<String> additionalArgs) throws Exception {

    if (values.size() != freqs.size()) {
        throw new Exception("Number of bins should be equal to number of frequencies!");
    }

    String plotTitle = "Pie Chart";
    String userTitle = getOption(additionalArgs, "-title");
    plotTitle = (userTitle != null) ? userTitle : plotTitle;
    String xLabel = getOption(additionalArgs, "-x-label");
    xLabel = xLabel == null ? "" : xLabel;
    String yLabel = getOption(additionalArgs, "-y-label");
    yLabel = yLabel == null ? "" : yLabel;

    DefaultPieDataset dataset = new DefaultPieDataset();

    for (int i = 0; i < values.size(); i++) {
        String binLabel = values.get(i);
        Number freq = freqs.get(i);

        dataset.setValue(binLabel, freq);
    }

    JFreeChart chart = ChartFactory.createPieChart(plotTitle, // chart title
            dataset, // data
            showLegend, // include legend
            false, false);

    PiePlot plot = (PiePlot) chart.getPlot();
    if (!showLabels) {
        plot.setLabelGenerator(null);
    } else {
        plot.setLabelFont(new Font("SansSerif", Font.PLAIN, 12));
        plot.setNoDataMessage("No data available");
        // plot.setCircular(false);
        plot.setLabelGap(0.02);
    }

    chart.setBackgroundPaint(java.awt.Color.white);
    chart.setTitle(new TextTitle(plotTitle, new Font("SansSerif", Font.BOLD, 12)));

    return chart;
}

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

public MemoryUsageDemo(int i) {
    super(new BorderLayout());
    total = new TimeSeries("Total Memory");
    total.setMaximumItemAge(i);//  w  w  w  .jav a  2 s  .c om
    free = new TimeSeries("Free Memory");
    free.setMaximumItemAge(i);
    TimeSeriesCollection timeseriescollection = new TimeSeriesCollection();
    timeseriescollection.addSeries(total);
    timeseriescollection.addSeries(free);
    DateAxis dateaxis = new DateAxis("Time");
    NumberAxis numberaxis = new NumberAxis("Memory");
    dateaxis.setTickLabelFont(new Font("SansSerif", 0, 12));
    numberaxis.setTickLabelFont(new Font("SansSerif", 0, 12));
    dateaxis.setLabelFont(new Font("SansSerif", 0, 14));
    numberaxis.setLabelFont(new Font("SansSerif", 0, 14));
    XYLineAndShapeRenderer xylineandshaperenderer = new XYLineAndShapeRenderer(true, false);
    xylineandshaperenderer.setSeriesPaint(0, Color.red);
    xylineandshaperenderer.setSeriesPaint(1, Color.green);
    xylineandshaperenderer.setSeriesStroke(0, new BasicStroke(3F, 0, 2));
    xylineandshaperenderer.setSeriesStroke(1, new BasicStroke(3F, 0, 2));
    XYPlot xyplot = new XYPlot(timeseriescollection, dateaxis, numberaxis, xylineandshaperenderer);
    xyplot.setBackgroundPaint(Color.lightGray);
    xyplot.setDomainGridlinePaint(Color.white);
    xyplot.setRangeGridlinePaint(Color.white);
    xyplot.setAxisOffset(new RectangleInsets(5D, 5D, 5D, 5D));
    dateaxis.setAutoRange(true);
    dateaxis.setLowerMargin(0.0D);
    dateaxis.setUpperMargin(0.0D);
    dateaxis.setTickLabelsVisible(true);
    numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    JFreeChart jfreechart = new JFreeChart("JVM Memory Usage", new Font("SansSerif", 1, 24), xyplot, true);
    jfreechart.setBackgroundPaint(Color.white);
    ChartPanel chartpanel = new ChartPanel(jfreechart, true);
    chartpanel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4),
            BorderFactory.createLineBorder(Color.black)));
    add(chartpanel);
}

From source file:be.ac.ua.comp.scarletnebula.gui.BareGraph.java

/**
 * @see Graph//from  w w  w  .j a  va2 s .c o  m
 */
@Override
public ChartPanel getChartPanel() {
    final XYPlot plot = new XYPlot(dataset, domain, range, renderer);
    plot.setBackgroundPaint(Color.darkGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);
    plot.setInsets(new RectangleInsets(0, 0, 0, 0));
    plot.setDomainGridlinesVisible(true);
    plot.setRangeGridlinesVisible(true);

    final JFreeChart chart = new JFreeChart(null, new Font("SansSerif", Font.BOLD, 24), plot, true);
    chart.setBackgroundPaint(Color.white);
    chart.removeLegend();
    final ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED));

    return chartPanel;
}

From source file:com.thalesgroup.hudson.plugins.klocwork.graph.KloPieChart.java

protected JFreeChart createGraph() {

    JFreeChart chart = ChartFactory.createPieChart(null, dataset, true, true, false);
    chart.setBackgroundPaint(Color.white);

    PiePlot plot = (PiePlot) chart.getPlot();
    plot.setDataset(dataset);//w w  w.ja v a  2 s  . c  o m
    plot.setOutlinePaint(null);
    plot.setLabelFont(new Font("SansSerif", Font.PLAIN, 12));
    plot.setNoDataMessage("No Klocwork data found.");
    plot.setCircular(false);
    plot.setLabelGap(0.02);
    plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{1}"));

    // Set colours
    //plot.setOutlinePaint("New", new Color(200, 0, 0));
    int i = 0;
    if (kloConfig.getBuildGraph().isNeww() && kloReport.getNeww() > 0) {
        plot.setSectionPaint(plot.getDataset().getKey(i), new Color(200, 0, 0));
        i++;
    }
    if (kloConfig.getBuildGraph().isExisting() && kloReport.getExisting() > 0) {
        plot.setSectionPaint(plot.getDataset().getKey(i), new Color(0, 0, 200));
        i++;
    }
    if (kloConfig.getBuildGraph().isFixed() && kloReport.getFixed() > 0) {
        plot.setSectionPaint(plot.getDataset().getKey(i), new Color(0, 200, 0));
    }

    //plot.setOutlinePaint("Existing", new Color(0, 0, 200));
    //plot.setOutlinePaint("Fixed", new Color(0, 200, 0));

    return chart;

}

From source file:gui.Plotter1D.java

private ChartPanel createChartPanel1(String grapheName) {

    XYSplineRenderer xysplinerenderer = new XYSplineRenderer();
    ValueAxis valueAxis = new NumberAxis("X");
    valueAxis.setRange(0.0, 1.0);//from ww w .j a  v a 2 s.  c  om
    ValueAxis valueAxisy = new NumberAxis("Y");
    valueAxis.setRange(0.0, 1.0);
    XYPlot xyplot;
    xyplot = new XYPlot(xyseriescollection, valueAxis, valueAxisy, xysplinerenderer);
    xyplot.setBackgroundPaint(Color.lightGray);
    xyplot.setDomainGridlinePaint(Color.white);
    xyplot.setRangeGridlinePaint(Color.white);
    xyplot.setAxisOffset(new RectangleInsets(4D, 4D, 4D, 4D));
    JFreeChart jfreechart = new JFreeChart(grapheName, JFreeChart.DEFAULT_TITLE_FONT, xyplot, true);
    jfreechart.setBackgroundPaint(Color.white);
    ChartPanel chartpanel = new ChartPanel(jfreechart, false);
    return chartpanel;
}