List of usage examples for org.jfree.chart.plot PiePlot setBackgroundPaint
public void setBackgroundPaint(Paint paint)
From source file:edu.ucla.stat.SOCR.chart.demo.PieChartDemo4.java
protected JFreeChart createChart(PieDataset dataset) { // create the chart... JFreeChart chart = ChartFactory.createPieChart(chartTitle, // chart title dataset, // dataset !legendPanelOn, // include legend true, false);/* w w w . j a v a2s . c o m*/ // set the background color for the chart... chart.setBackgroundPaint(new Color(222, 222, 255)); PiePlot plot = (PiePlot) chart.getPlot(); plot.setBackgroundPaint(Color.white); plot.setCircular(true); for (int i = 0; i < pulloutFlag.length; i++) { //System.out.println("\""+pulloutFlag[i]+"\""); if (isPullout(i)) { Comparable key = dataset.getKey(i); plot.setExplodePercent(key, 0.30); } } plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0} = {2}", NumberFormat.getNumberInstance(), NumberFormat.getPercentInstance())); plot.setNoDataMessage("No data available"); if (rotateOn) { Rotator rotator = new Rotator(plot); rotator.start(); } setCategorySummary(dataset); return chart; }
From source file:ch.zhaw.init.walj.projectmanagement.util.chart.PieChart.java
/** * creates the pie chart//from w ww . ja v a 2 s . c o m * @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:org.pathvisio.cytoscape.superpathways.PieGenerator.java
public void generatePie(int number) { // Defining the dataset DefaultPieDataset dataset = new DefaultPieDataset(); for (int i = 0; i < number; i++) { String temp = String.valueOf(i); dataset.setValue(temp, 10);/*from ww w. j a va2 s. co m*/ } // Defining the chart JFreeChart chart = ChartFactory.createPieChart("", dataset, false, false, false); // Defining the chartPanel //final ChartPanel chartPanel = new ChartPanel(chart); //chartPanel.setPreferredSize(new java.awt.Dimension(350, 350)); //setContentPane(chartPanel); // Defining the plot PiePlot plot = (PiePlot) chart.getPlot(); plot.setLabelGenerator(null); plot.setInteriorGap(0.0); //add the following two lines to make the background transparent chart.setBackgroundPaint(new Color(255, 255, 255, 0)); plot.setBackgroundPaint(new Color(255, 255, 255, 0)); //plot.setBackgroundAlpha(0.0f); // Specify the colors here PieRenderer renderer = new PieRenderer(colors); renderer.setColor(plot, dataset); try { // This will create a PNG image ChartUtilities.saveChartAsPNG(new File(imageLocation + "chart.png"), chart, 280, 280, null, true, // encodeAlpha 0); } catch (Exception e) { System.out.println("Exception while creating the chart"); } }
From source file:edu.jhuapl.graphs.jfreechart.JFreeChartPieGraphSource.java
@SuppressWarnings("unchecked") @Override/*w w w.j a v a 2 s .c om*/ public void initialize() throws GraphException { String title = getParam(GraphSource.GRAPH_TITLE, String.class, DEFAULT_TITLE); boolean legend = getParam(GraphSource.GRAPH_LEGEND, Boolean.class, DEFAULT_GRAPH_LEGEND); boolean graphToolTip = getParam(GraphSource.GRAPH_TOOL_TIP, Boolean.class, DEFAULT_GRAPH_TOOL_TIP); boolean graphDisplayLabel = getParam(GraphSource.GRAPH_DISPLAY_LABEL, Boolean.class, false); boolean legendBorder = getParam(GraphSource.LEGEND_BORDER, Boolean.class, DEFAULT_LEGEND_BORDER); boolean graphBorder = getParam(GraphSource.GRAPH_BORDER, Boolean.class, DEFAULT_GRAPH_BORDER); Font titleFont = getParam(GraphSource.GRAPH_FONT, Font.class, DEFAULT_GRAPH_TITLE_FONT); String noDataMessage = getParam(GraphSource.GRAPH_NO_DATA_MESSAGE, String.class, DEFAULT_GRAPH_NO_DATA_MESSAGE); PieGraphData pieGraphData = makeDataSet(); Map<Comparable, Paint> colors = pieGraphData.colors; this.chart = ChartFactory.createPieChart(title, pieGraphData.data, false, graphToolTip, false); Paint backgroundColor = getParam(GraphSource.BACKGROUND_COLOR, Paint.class, DEFAULT_BACKGROUND_COLOR); Paint plotColor = getParam(JFreeChartTimeSeriesGraphSource.PLOT_COLOR, Paint.class, backgroundColor); Paint labelColor = getParam(JFreeChartTimeSeriesGraphSource.GRAPH_LABEL_BACKGROUND_COLOR, Paint.class, DEFAULT_BACKGROUND_COLOR); this.chart.setBackgroundPaint(backgroundColor); PiePlot plot = (PiePlot) chart.getPlot(); plot.setBackgroundPaint(plotColor); plot.setNoDataMessage(noDataMessage); if (!graphDisplayLabel) { plot.setLabelGenerator(null); } else { plot.setInteriorGap(0.001); plot.setMaximumLabelWidth(.3); // plot.setIgnoreNullValues(true); plot.setIgnoreZeroValues(true); plot.setShadowPaint(null); // plot.setOutlineVisible(false); //TODO use title font? Font font = plot.getLabelFont(); plot.setLabelLinkStyle(PieLabelLinkStyle.CUBIC_CURVE); plot.setLabelFont(font.deriveFont(font.getSize2D() * .75f)); plot.setLabelBackgroundPaint(labelColor); plot.setLabelShadowPaint(null); plot.setLabelOutlinePaint(null); plot.setLabelGap(0.001); plot.setLabelLinkMargin(0.0); plot.setLabelLinksVisible(true); // plot.setSimpleLabels(true); // plot.setCircular(true); } if (!graphBorder) { plot.setOutlineVisible(false); } if (title != null && !"".equals(title)) { TextTitle title1 = new TextTitle(); title1.setText(title); title1.setFont(titleFont); title1.setPadding(3, 2, 5, 2); chart.setTitle(title1); } else { chart.setTitle((TextTitle) null); } plot.setLabelPadding(new RectangleInsets(1, 1, 1, 1)); //Makes a wrapper for the legend to remove the border around it if (legend) { LegendTitle legend1 = new LegendTitle(chart.getPlot()); BlockContainer wrapper = new BlockContainer(new BorderArrangement()); if (legendBorder) { wrapper.setFrame(new BlockBorder(1, 1, 1, 1)); } else { wrapper.setFrame(new BlockBorder(0, 0, 0, 0)); } BlockContainer items = legend1.getItemContainer(); items.setPadding(2, 10, 5, 2); wrapper.add(items); legend1.setWrapper(wrapper); legend1.setPosition(RectangleEdge.BOTTOM); legend1.setHorizontalAlignment(HorizontalAlignment.CENTER); if (params.get(GraphSource.LEGEND_FONT) instanceof Font) { legend1.setItemFont(((Font) params.get(GraphSource.LEGEND_FONT))); } chart.addSubtitle(legend1); plot.setLegendLabelGenerator(new PieGraphLabelGenerator()); } for (Comparable category : colors.keySet()) { plot.setSectionPaint(category, colors.get(category)); } plot.setToolTipGenerator(new PieGraphToolTipGenerator(pieGraphData)); plot.setURLGenerator(new PieGraphURLGenerator(pieGraphData)); initialized = true; }
From source file:servlet.SalesReportPieChart.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods.// ww w . j a v a 2s .c om * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { DefaultPieDataset dataset = new DefaultPieDataset(); int totalTickets = Integer.valueOf(request.getParameter("totalTickets")); int totalSoldTickets = Integer.valueOf(request.getParameter("totalSoldTickets")); dataset.setValue("Unsold Tickets", new Double(totalTickets - totalSoldTickets)); dataset.setValue("Sold Tickets", new Double(totalSoldTickets)); JFreeChart chart = ChartFactory.createPieChart("Ticket Sales", // chart title dataset, // data true, // include legend true, false); PiePlot plot = (PiePlot) chart.getPlot(); plot.setSectionPaint("Unsold Tickets", Color.DARK_GRAY); plot.setSectionPaint("Sold Tickets", Color.CYAN); plot.setExplodePercent("Unsold Tickets", 0.10); plot.setSimpleLabels(true); plot.setBackgroundPaint(Color.WHITE); PieSectionLabelGenerator gen = new StandardPieSectionLabelGenerator("{0}: {1} ({2})", new DecimalFormat("0"), new DecimalFormat("0%")); plot.setLabelGenerator(gen); final ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection()); int width = 500; /* Width of the image */ int height = 400; /* Height of the image */ response.setContentType("image/png"); OutputStream out = response.getOutputStream(); ChartUtilities.writeChartAsPNG(out, chart, 400, 300, info); }
From source file:edu.ku.brc.specify.plugins.ipadexporter.ChartHelper.java
/** * @param list/*w w w . j av a 2s. co m*/ * @param title * @param xAxisTitle * @param yAxisTitle * @param isVertical * @param width * @param height */ public JFreeChart createPieChart(final List<Object> list, final String title, final int width, final int height, final boolean do3D) { DefaultPieDataset dataset = new DefaultPieDataset(); for (int i = 0; i < list.size(); i++) { Object descObj = list.get(i++); Object valObj = list.get(i); dataset.setValue(getString(descObj), getInt(valObj)); } String adjTitle = title; JFreeChart chart = do3D ? ChartFactory.createPieChart3D(adjTitle, dataset, false, false, false) : ChartFactory.createPieChart(adjTitle, dataset, false, false, false); chart.setBackgroundPaint(new Color(0, 0, 0, 0)); // transparent black PiePlot plot = (PiePlot) chart.getPlot(); plot.setLabelFont(new Font("SansSerif", Font.PLAIN, 11)); //$NON-NLS-1$ plot.setBackgroundPaint(new Color(0, 0, 0, 0)); // transparent black plot.setOutlinePaint(null); setColors(plot, dataset); return chart; }
From source file:com.opensourcestrategies.activities.reports.ActivitiesChartsService.java
private String createPieChart(DefaultPieDataset dataset, String title) throws InfrastructureException, IOException { Debug.logInfo("Charting dashboard [" + title + "]", MODULE); // set up the chart JFreeChart chart = ChartFactory.createPieChart(title, dataset, true, // include legend true, // tooltips false // urls );/*w ww.ja v a 2 s. co m*/ chart.setBackgroundPaint(Color.white); chart.setBorderVisible(true); chart.setPadding(new RectangleInsets(5.0, 5.0, 5.0, 5.0)); // get a reference to the plot for further customization... final PiePlot plot = (PiePlot) chart.getPlot(); plot.setBackgroundPaint(Color.white); plot.setCircular(true); plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0}: {1} / {2}", NumberFormat.getNumberInstance(), NumberFormat.getPercentInstance())); plot.setNoDataMessage("No data available"); Color[] colors = { Color.decode("#" + infrastructure.getConfigurationValue( OpentapsConfigurationTypeConstants.ACTIVITIES_DASHBOARD_LEADS_NEW_COLOR)), Color.decode("#" + infrastructure.getConfigurationValue( OpentapsConfigurationTypeConstants.ACTIVITIES_DASHBOARD_LEADS_OLD_COLOR)), Color.decode("#" + infrastructure.getConfigurationValue( OpentapsConfigurationTypeConstants.ACTIVITIES_DASHBOARD_LEADS_NO_ACTIVITY_COLOR)) }; for (int i = 0; i < dataset.getItemCount(); i++) { Comparable<?> key = dataset.getKey(i); plot.setSectionPaint(key, colors[i]); } // save as a png and return the file name return ServletUtilities.saveChartAsPNG(chart, chartWidth, chartHeight, null); }
From source file:com.intel.stl.ui.common.view.ComponentFactory.java
/** * Create a simple pie chart without title, legend, label etc. * /*from w w w. j a va 2 s .c o m*/ * @param dataset * the dataset to be renderer * @param colors * an color array specify each item's color. The order of the * array correspond to the item order in dataset * @return a pie chart */ public static JFreeChart createPlainPieChart(PieDataset dataset, Color[] colors) { if (dataset == null) { throw new IllegalArgumentException("No dataset."); } if (colors != null && colors.length != dataset.getItemCount()) { throw new IllegalArgumentException("Data have " + dataset.getItemCount() + " values, while we have " + colors.length + " colors for them."); } JFreeChart jfreechart = ChartFactory.createPieChart(null, dataset, false, true, false); PiePlot pieplot = (PiePlot) jfreechart.getPlot(); if (colors != null) { for (int i = 0; i < colors.length; i++) { pieplot.setSectionPaint(dataset.getKey(i), colors[i]); } } pieplot.setBackgroundPaint(null); pieplot.setOutlineStroke(null); pieplot.setLabelGenerator(null); pieplot.setNoDataMessage(UILabels.STL40001_ERROR_No_DATA.getDescription()); pieplot.setCircular(true); pieplot.setInteriorGap(0.000001); return jfreechart; }
From source file:com.rapidminer.template.gui.RoleRequirementSelector.java
private JFreeChart makeChart(ExampleSet exampleSet, Attribute att) { DefaultPieDataset pieDataset = new DefaultPieDataset(); if (att.isNominal()) { for (String val : att.getMapping().getValues()) { pieDataset.setValue(val, exampleSet.getStatistics(att, Statistics.COUNT, val)); }/*from www. j a va2 s . c o m*/ } JFreeChart chart = ChartFactory.createPieChart(null, pieDataset, true, false, false); chart.setBackgroundPaint(Color.WHITE); chart.getLegend().setFrame(BlockBorder.NONE); chart.setBackgroundImageAlpha(0.0f); chart.setBorderVisible(false); PiePlot plot = (PiePlot) chart.getPlot(); plot.setLabelGenerator(null); plot.setShadowPaint(null); plot.setOutlineVisible(false); plot.setBackgroundPaint(new Color(255, 255, 255, 0)); plot.setBackgroundImageAlpha(0.0f); plot.setCircular(true); return chart; }
From source file:graph.plotter.PieMenu.java
/** * This is the main working button for this class... It creates pie chart analyZing whole data set * //from ww w. java2 s . c o m * @param evt */ private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed try { DefaultPieDataset pieDataset = new DefaultPieDataset(); /** Initializing pie dataset*/ int i; i = 0; String genre = "a"; if (Button == 1) { /** For User Input*/ while (i < cnt) { double aa = Double.parseDouble(Table.getModel().getValueAt(i, 1).toString()); String str = Table.getModel().getValueAt(i, 0).toString(); pieDataset.setValue(str, new Double(aa)); i++; genre += "a"; } } else { try { BufferedReader br = new BufferedReader(new FileReader(jTextField3.getText())); String Line; while ((Line = br.readLine()) != null) { String[] value = Line.split(","); double val = Double.parseDouble(value[1]); pieDataset.setValue(value[0], new Double(val)); // dataset.setValue(new Double(val),genre,value[0]); // genre+="a"; // (value[0]); } } catch (FileNotFoundException ex) { Logger.getLogger(PieMenu.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(PieMenu.class.getName()).log(Level.SEVERE, null, ex); } } JFreeChart chart = ChartFactory.createPieChart("Pie Chart", pieDataset, true, true, true); PiePlot P = (PiePlot) chart.getPlot(); P.setLabelLinkPaint(Color.BLACK); P.setBackgroundPaint(Color.white); ChartFrame frame = new ChartFrame("PieChart", chart); jButto1 = new JButton("Save"); frame.setLayout(new BorderLayout()); JPanel panel = new JPanel(); panel.setLayout(new GridBagLayout()); GridBagConstraints gc = new GridBagConstraints(); gc.gridx = 1; gc.gridy = 0; panel.add(jButto1, gc); frame.add(panel, BorderLayout.SOUTH); jButto1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { try { final ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection()); final File file1 = new File("Pie_Chart.png"); ChartUtilities.saveChartAsPNG(file1, chart, 600, 400, info); } catch (Exception ex) { } } }); frame.setVisible(true); frame.setSize(858, 512); try { final ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection()); final File file1 = new File("Pie_Chart.png"); ChartUtilities.saveChartAsPNG(file1, chart, 600, 400, info); } catch (Exception e) { } } catch (Exception ex) { } }