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

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

Introduction

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

Prototype

public void setSectionPaint(int section, Paint paint) 

Source Link

Document

Sets the paint used to fill a section of the pie and sends a PlotChangeEvent to all registered listeners.

Usage

From source file:UserInterface.PublisherRole.ViewUserHabitsJPanel.java

private static JFreeChart createChart(PieDataset dataset) {

    JFreeChart chart = ChartFactory.createPieChart("User Habits", // chart title
            dataset, // data
            false, // no legend
            true, // tooltips
            false // no URL generation
    );//from ww  w. j a v a  2  s  .c  o m

    // set a custom background for the chart
    chart.setBackgroundPaint(
            new GradientPaint(new Point(0, 0), new Color(20, 20, 20), new Point(400, 200), Color.DARK_GRAY));

    // 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.setBackgroundPaint(null);
    plot.setInteriorGap(0.04);
    plot.setOutlineVisible(false);

    // 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(" ", 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.gaixie.micrite.jfreechart.style.PieStyle.java

/**
 * ?1 ,? Familiar(30%) //from   w  w  w  .jav a  2  s . co m
 * @param chart
 */
public static void styleOne(JFreeChart chart) {
    PiePlot plot = (PiePlot) chart.getPlot();
    PieDataset pd = plot.getDataset();
    PieStyle.setBackground(chart);
    if (pd != null) {
        //?
        plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0} ({2})"));
        //??
        for (int i = 0; i < pd.getItemCount(); i++) {
            int color = i % colors.length;
            plot.setSectionPaint(pd.getKey(i), colors[color]);
        }
    } else {
        plot.setNoDataMessage("NO DATA");
    }

}

From source file:uk.ac.lkl.cram.ui.chart.TLALearningTypeChartFactory.java

private static JFreeChart createChart(PieDataset dataset) {
    //Create a pie chart from the chart factory with no title, a legend and no tooltips
    JFreeChart chart = ChartFactory.createPieChart(null, dataset, true, false, false);
    //Set the background colour of the chart
    Paint backgroundPaint = Color.white;
    chart.setBackgroundPaint(backgroundPaint);
    //Get the plot from the chart
    PiePlot plot = (PiePlot) chart.getPlot();
    //Set the background colour of the plot to be the same as the chart
    plot.setBackgroundPaint(backgroundPaint);
    //Remove shadows from the plot
    plot.setShadowXOffset(0);/*from ww w .j a v a  2  s. c o  m*/
    plot.setShadowYOffset(0);
    //Remove the outline from the plot
    plot.setOutlineVisible(false);
    //Remove the labels from the plot
    plot.setLabelGenerator(null);
    //Set the colours for the segments
    plot.setSectionPaint(LearningTypeChartMaker.ACQUISITION, LearningTypeChartMaker.ACQUISITION_COLOR);
    plot.setSectionPaint(LearningTypeChartMaker.COLLABORATION, LearningTypeChartMaker.COLLABORATION_COLOR);
    plot.setSectionPaint(LearningTypeChartMaker.DISCUSSION, LearningTypeChartMaker.DISCUSSION_COLOR);
    plot.setSectionPaint(LearningTypeChartMaker.INQUIRY, LearningTypeChartMaker.INQUIRY_COLOR);
    plot.setSectionPaint(LearningTypeChartMaker.PRACTICE, LearningTypeChartMaker.PRACTICE_COLOR);
    plot.setSectionPaint(LearningTypeChartMaker.PRODUCTION, LearningTypeChartMaker.PRODUCTION_COLOR);
    //Get the legend from the chart
    LegendTitle legend = chart.getLegend();
    //Set the font of the legend to be the same as the platform UI
    legend.setItemFont(UIManager.getFont("Label.font"));
    //Set the background colour of the legend to be the same as the chart
    legend.setBackgroundPaint(backgroundPaint);
    //Remove the border from the legend
    legend.setFrame(BlockBorder.NONE);
    //Locate the legend to the right of the plot
    legend.setPosition(RectangleEdge.RIGHT);
    return chart;
}

From source file:canreg.client.analysis.Tools.java

public static void setPiePlotColours(JFreeChart chart, int numberOfSections, Color baseColor) {
    Color color = baseColor;/*from   w  w  w  . ja  va  2s  . c o  m*/
    PiePlot plot = (PiePlot) chart.getPlot();
    for (int i = 0; i < numberOfSections; i++) {
        try {
            plot.setSectionOutlinePaint(plot.getDataset().getKey(i), baseColor.darker().darker().darker());
            color = darken(color);
            plot.setSectionPaint(plot.getDataset().getKey(i), color);
        } catch (java.lang.IndexOutOfBoundsException ex) {
            // not data for all the categories - that is fine
            Logger.getLogger(TopNChartTableBuilder.class.getName()).log(Level.INFO, null, ex);
        }
    }
}

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

private static JFreeChart createMultiplePieChart3D(CategoryDataset dataset) {

    JFreeChart chart = ChartFactory.createMultiplePieChart3D("MultiplePie Chart 3D Demo 1", // chart title
            dataset, // data
            TableOrder.BY_COLUMN, // orientation
            true, // include legend
            true, // tooltips?
            false // URLs?
    );//from www  .  j a  v a  2  s . c o  m

    chart.setBackgroundPaint(Color.white);

    MultiplePiePlot plot = (MultiplePiePlot) chart.getPlot();
    JFreeChart pieChart = plot.getPieChart();
    PiePlot piePlot = (PiePlot) pieChart.getPlot();

    // 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));
    piePlot.setSectionPaint("First", gp0);
    piePlot.setSectionPaint("Second", gp1);
    piePlot.setSectionPaint("Third", gp2);

    return chart;

}

From source file:org.exist.xquery.modules.jfreechart.JFreeChartFactory.java

private static void setSectionColors(JFreeChart chart, Configuration config) {
    String sectionColors = config.getSectionColors();
    String sectionColorsDelimiter = config.getSectionColorsDelimiter();

    if (sectionColors != null) {
        PiePlot plot = ((PiePlot) chart.getPlot());

        StringTokenizer st = new StringTokenizer(sectionColors, sectionColorsDelimiter);

        while (st.hasMoreTokens()) {
            String sectionName = st.nextToken().trim();
            String colorName = "";

            if (st.hasMoreTokens()) {
                colorName = st.nextToken().trim();
            }/*from w ww.  ja  va2  s . com*/

            Color color = null;

            try {
                color = Colour.getColor(colorName);
            } catch (XPathException e) {
            }

            if (color != null) {
                plot.setSectionPaint(sectionName, color);
            } else {
                logger.warn("Invalid colour name or hex value specified for SectionColors: " + colorName
                        + ", default colour will be used instead. Section Name: " + sectionName);
            }
        }
    }
}

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   ww  w . jav a2 s. com*/
    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:ch.zhaw.init.walj.projectmanagement.util.chart.PieChart.java

/**
 * creates the pie chart/*from   ww  w. ja v  a2 s .  c  om*/
 * @throws NumberFormatException
 * @throws IOException
 */
public void createChart() throws NumberFormatException, IOException {

    // create dataset with used and remaining budget
    DefaultPieDataset dataset = new DefaultPieDataset();
    dataset.setValue("spent", con.getUsedBudget(project));
    dataset.setValue("remaining", con.getRemainingBudget(project));

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

    // set color and style
    PiePlot plot = (PiePlot) chart.getPlot();
    plot.setSectionPaint("remaining", new Color(0, 101, 166));
    plot.setSectionPaint("spent", new Color(0, 62, 102));
    plot.setLabelGenerator(null);
    plot.setBackgroundPaint(Color.WHITE);
    plot.setShadowXOffset(0);
    plot.setShadowYOffset(0);
    plot.setOutlineVisible(false);
    plot.setInteriorGap(0);

    // set size and save it as JPEG
    int width = 350; /* Width of the image */
    int height = 350; /* Height of the image */
    File pieChart = new File(path + "/Charts/BudgetProject" + project.getID() + ".jpg");
    ChartUtilities.saveChartAsJPEG(pieChart, chart, width, height);
}

From source file:com.jtk.pengelolaanujian.view.dashboard.PiePanelVnv.java

private ChartPanel createChart(PieDataset data) {
    piechart = ChartFactory.createPieChart("Soal Vnv", data, true, true, false);
    PiePlot plot = (PiePlot) piechart.getPlot();
    plot.setSectionPaint("Belum Di VNV", new Color(135, 206, 250));
    plot.setSectionPaint("sudah Di VNV", new Color(205, 133, 63));
    plot.setNoDataMessage("Data Tidak Ada");
    plot.setExplodePercent("data", 0.1D);
    plot.setLabelBackgroundPaint(new Color(255, 228, 225));
    plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0} ({1})"));
    plot.setLegendLabelGenerator(new StandardPieSectionLabelGenerator());

    // Key = 0 ----> section as String (Windows, Linux, Lainnya)
    // Key = 1 ----> section as value (300,200,100)
    // KEy - 2 ----> section as percentage (50%,33%,17 %) Muncul jika aplikasi telah di running
    plot.setSimpleLabels(true);/*from   w  w  w  .j  a va  2  s . c o  m*/
    plot.setInteriorGap(0.0D);
    return new ChartPanel(piechart);
}

From source file:com.jtk.pengelolaanujian.view.dashboard.PiePanelUjian.java

private ChartPanel createChart(PieDataset data) {
    piechart = ChartFactory.createPieChart("Ujian Status", data, true, true, false);
    PiePlot plot = (PiePlot) piechart.getPlot();
    plot.setSectionPaint("Terlalui", new Color(60, 70, 5));
    plot.setSectionPaint("Belum", new Color(100, 20, 30));
    plot.setNoDataMessage("Data Tidak Ada");
    plot.setExplodePercent("data", 0.1D);
    plot.setLabelBackgroundPaint(new Color(255, 228, 225));
    plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0} ({1})"));
    plot.setLegendLabelGenerator(new StandardPieSectionLabelGenerator());

    // Key = 0 ----> section as String (Windows, Linux, Lainnya)
    // Key = 1 ----> section as value (300,200,100)
    // KEy - 2 ----> section as percentage (50%,33%,17 %) Muncul jika aplikasi telah di running

    plot.setSimpleLabels(true);//from   www .j  a va2s .com
    plot.setInteriorGap(0.0D);
    return new ChartPanel(piechart);
}