List of usage examples for org.jfree.chart.plot PiePlot setSectionPaint
public void setSectionPaint(int section, Paint paint)
From source file:edu.uara.wrappers.customcharts.CustomPieChart.java
/** * Function to set change color of pie section * sectionName-- section to to change color * color-- color used to change section color *///from www . ja v a 2 s.c om @Override public void setSectionPaint(String sectionName, Color color) { Plot plot = chart.getPlot(); if (plot instanceof PiePlot) { PiePlot p = (PiePlot) chart.getPlot(); p.setSectionPaint(sectionName, color); } else if (plot instanceof MultiplePiePlot) { MultiplePiePlot p = (MultiplePiePlot) plot; JFreeChart pieCh = p.getPieChart(); PiePlot piePlot = (PiePlot) pieCh.getPlot(); piePlot.setSectionPaint(sectionName, color); } }
From source file:sentimentanalyzer.ChartController.java
public void createAndPopulatePieChart__TESTER(JPanel pnlPieChart) { DefaultPieDataset data = new DefaultPieDataset(); data.setValue(Pos, 0 /*count for 1 */); data.setValue(Neu, 0 /*count for 0 */); data.setValue(Neg, 0 /*count for -1 */); JFreeChart chart = ChartFactory.createPieChart("Sent. Distr. for Testing", data, false, // legend? false, // tooltips? false // URLs? );/*from ww w.j a v a 2s. c om*/ ChartPanel CP = new ChartPanel(chart); PiePlot plot = (PiePlot) chart.getPlot(); plot.setSectionPaint("Pie chart is not available", Color.LIGHT_GRAY); plot.setExplodePercent(Pos, 0.025); plot.setExplodePercent(Neg, 0.025); plot.setExplodePercent(Neu, 0.025); //Customize PieChart to show absolute values and percentages; PieSectionLabelGenerator gen = new StandardPieSectionLabelGenerator("{0}: {1} ({2})", new DecimalFormat("0"), new DecimalFormat("0.00%")); plot.setLabelGenerator(gen); TextTitle legendText = new TextTitle("The total number of tweets: "); legendText.setPosition(RectangleEdge.BOTTOM); chart.addSubtitle(legendText); pnlPieChart.setLayout(new java.awt.BorderLayout()); pnlPieChart.add(CP, BorderLayout.CENTER); }
From source file:sentimentanalyzer.ChartController.java
public void createAndPopulatePieChart(JPanel pnlPieChart, double positiveValue, double negativeValue, double neutralValue) { DefaultPieDataset data = new DefaultPieDataset(); data.setValue(Pos, positiveValue /*count for 1 */); data.setValue(Neu, neutralValue /*count for 0 */); data.setValue(Neg, negativeValue /*count for -1 */); JFreeChart chart = ChartFactory.createPieChart("Sent. Distr. for Testing", data, false, // legend? false, // tooltips? false // URLs? );/* w w w .j a va 2 s . co m*/ ChartPanel CP = new ChartPanel(chart); PiePlot plot = (PiePlot) chart.getPlot(); plot.setSectionPaint("Pie chart is not available", Color.LIGHT_GRAY); plot.setExplodePercent(Pos, 0.02); plot.setExplodePercent(Neg, 0.02); plot.setExplodePercent(Neu, 0.02); double sum = positiveValue + negativeValue + neutralValue; int z = (int) sum; //Customize PieChart to show absolute values and percentages; PieSectionLabelGenerator gen = new StandardPieSectionLabelGenerator("{0}: {1} ({2})", new DecimalFormat("0"), new DecimalFormat("0.00%")); plot.setLabelGenerator(gen); TextTitle legendText = new TextTitle("The total number of tweets: " + z); legendText.setPosition(RectangleEdge.BOTTOM); chart.addSubtitle(legendText); pnlPieChart.removeAll(); pnlPieChart.setLayout(new java.awt.BorderLayout()); pnlPieChart.add(CP, BorderLayout.CENTER); }
From source file:com.orange.atk.atkUI.coregui.StatisticTool.java
/** * Creates the chart./*ww w . j a va 2 s . com*/ * * @param piedataset * the data set * @return the created chart */ private JFreeChart createChart(PieDataset piedataset) { JFreeChart jfreechart = ChartFactory.createPieChart3D("", piedataset, true, true, false); jfreechart.setBackgroundPaint(Color.lightGray); PiePlot pie3dplot = (PiePlot) jfreechart.getPlot(); pie3dplot.setStartAngle(0); pie3dplot.setDirection(Rotation.CLOCKWISE); pie3dplot.setForegroundAlpha(0.5F); pie3dplot.setNoDataMessage("No data to display"); pie3dplot.setSectionPaint(0, Color.GREEN);// passed pie3dplot.setSectionPaint(1, Color.RED);// failed pie3dplot.setSectionPaint(2, Color.ORANGE);// skipped pie3dplot.setSectionPaint(3, Color.LIGHT_GRAY);// not analysed pie3dplot.setToolTipGenerator(new MyToolTipGenerator()); pie3dplot.setLabelGenerator(new MySectionLabelGenerator()); pie3dplot.setLegendLabelGenerator(new MySectionLabelGenerator()); return jfreechart; }
From source file:com.uttesh.pdfngreport.handler.PdfReportHandler.java
/** * Not Used for the current release/*from ww w . ja v a2 s.c o m*/ * * @param dataSet */ public void pieExplodeChart(DefaultPieDataset dataSet, String os) { try { JFreeChart chart = ChartFactory.createPieChart("", dataSet, true, true, false); ChartStyle.theme(chart); PiePlot plot = (PiePlot) chart.getPlot(); plot.setForegroundAlpha(0.6f); plot.setCircular(true); plot.setSectionPaint("Passed", Color.decode("#019244")); plot.setSectionPaint("Failed", Color.decode("#EE6044")); plot.setSectionPaint("Skipped", Color.decode("#F0AD4E")); Color transparent = new Color(0.0f, 0.0f, 0.0f, 0.0f); //plot.setLabelLinksVisible(Boolean.FALSE); plot.setLabelOutlinePaint(transparent); plot.setLabelBackgroundPaint(transparent); plot.setLabelShadowPaint(transparent); plot.setLabelLinkPaint(Color.GRAY); Font font = new Font("SansSerif", Font.PLAIN, 10); plot.setLabelFont(font); plot.setLabelPaint(Color.DARK_GRAY); plot.setExplodePercent("Passed", 0.10); //plot.setExplodePercent("Failed", 0.10); //plot.setExplodePercent("Skipped", 0.10); plot.setSimpleLabels(true); PieSectionLabelGenerator gen = new StandardPieSectionLabelGenerator("{1} ({2})", new DecimalFormat("0"), new DecimalFormat("0%")); plot.setLabelGenerator(gen); if (os != null && os.equalsIgnoreCase("w")) { ChartUtilities.saveChartAsPNG( new File(reportLocation + Constants.BACKWARD_SLASH + Constants.REPORT_CHART_FILE), chart, 560, 200); } else { ChartUtilities.saveChartAsPNG( new File(reportLocation + Constants.FORWARD_SLASH + Constants.REPORT_CHART_FILE), chart, 560, 200); } } catch (Exception e) { e.printStackTrace(System.err); if (os != null && os.equalsIgnoreCase("w")) { new File(reportLocation + Constants.BACKWARD_SLASH + Constants.REPORT_CHART_FILE).delete(); } else { new File(reportLocation + Constants.FORWARD_SLASH + Constants.REPORT_CHART_FILE).delete(); } System.exit(-1); } }
From source file:uom.research.thalassemia.util.PieChartCreator.java
/** * Creates a chart.//from w w w .j a v a2s .c o m * * @param dataset the dataset. * * @return A chart. */ private JFreeChart createChart(PieDataset dataset) { JFreeChart chart = ChartFactory.createPieChart(title, // chart title dataset, // data true, // no legend true, // tooltips false // no URL generation ); // 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 int itemIndex = 0; for (Object col : pieDataset.getKeys()) { plot.setSectionPaint(col.toString(), gradientPaints[itemIndex]); if (itemIndex == pieDataset.getItemCount() - 1) { itemIndex = 0; } itemIndex++; } 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:treegross.standsimulation.TgGrafik.java
public JFreeChart createChart(Stand st) { // create the dataset... DefaultPieDataset dataset = new DefaultPieDataset(); for (int j = 0; j < st.nspecies; j++) { dataset.setValue(st.sp[j].spDef.shortName, st.sp[j].percCSA); }//from w w w .j a va 2s . c o m // JFreeChart chart = ChartFactory.createPieChart(messages.getString("speciespercentage"), // chart title dataset, // data true, // include legend true, // tooltips? false // URLs? ); PiePlot piePlot = (PiePlot) chart.getPlot(); for (int i = 0; i < st.nspecies; i++) { piePlot.setSectionPaint(i, new Color(st.sp[i].spDef.colorRed, st.sp[i].spDef.colorGreen, st.sp[i].spDef.colorBlue)); } return chart; }
From source file:net.sourceforge.processdash.ui.web.reports.PieChart.java
private void configureConsistentColors(final PiePlot plot, PieDataset pieData) { DefaultDrawingSupplier s = new DefaultDrawingSupplier(); String skip = getParameter("consistentSkip"); if (skip != null) for (int i = Integer.parseInt(skip); i-- > 0;) s.getNextPaint();/*ww w . jav a2 s . c o m*/ for (Object key : pieData.getKeys()) { Paint paint = s.getNextPaint(); plot.setSectionPaint((Comparable) key, paint); } }
From source file:com.modeln.build.ctrl.charts.CMnChartFormatter.java
private void formatChart(PiePlot plot, Hashtable colormap, String label) { // Set the chart colors Enumeration keys = colormap.keys(); while (keys.hasMoreElements()) { String name = (String) keys.nextElement(); Color color = (Color) colormap.get(name); if (color == null) { color = DEFAULT_COLOR;// w w w. ja v a 2 s . c o m } plot.setSectionPaint(name, color); } // Set the chart label format plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{1} " + label + " ({2})")); }
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 ww w .j av a 2 s . co 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; }