List of usage examples for org.jfree.chart.plot PiePlot setLabelLinkPaint
public void setLabelLinkPaint(Paint paint)
From source file:charts.PieChart3D.java
/** * Creates a chart./*w w w . j ava 2s.com*/ * * @param dataset * the dataset. * * @return A chart. */ private static JFreeChart createChart(PieDataset dataset, PieChartModel model) { JFreeChart chart = ChartFactory.createPieChart(model.getTitle(), // chart // title dataset, // data false, // 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 plot.setSectionPaint("FCA", createGradientPaint(new Color(200, 200, 255), Color.BLUE)); plot.setSectionPaint("FCH", createGradientPaint(new Color(255, 200, 200), Color.RED)); plot.setSectionPaint("FCS", createGradientPaint(new Color(200, 255, 200), Color.GREEN)); plot.setSectionPaint("FCG", createGradientPaint(new Color(200, 255, 200), Color.YELLOW)); plot.setSectionPaint("FCJ", createGradientPaint(new Color(200, 255, 200), Color.BLACK)); plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0} {1} ({2}) ")); 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(model.getSubTitle(), 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:graph.plotter.PieMenu.java
/** * This is the main working button for this class... It creates pie chart analyZing whole data set * // ww w.java 2 s . com * @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) { } }
From source file:msi.gama.outputs.layers.charts.ChartJFreeChartOutputPie.java
@Override public void initChart(final IScope scope, final String chartname) { super.initChart(scope, chartname); final PiePlot pp = (PiePlot) chart.getPlot(); pp.setShadowXOffset(0);/*from w ww.ja va 2 s .c o m*/ pp.setShadowYOffset(0); if (!this.series_label_position.equals("none")) { pp.setLabelGenerator(new StandardPieSectionLabelGenerator("{0} = {1} ({2})")); if (axesColor != null) { pp.setLabelLinkPaint(axesColor); } pp.setLabelFont(getTickFont()); } if (this.series_label_position.equals("none")) { pp.setLabelLinksVisible(false); pp.setLabelGenerator(null); } if (textColor != null) { // pp.setLabelPaint(textColor); // not for Pie since the label background is always yellow for // now... } }
From source file:com.uttesh.pdfngreport.handler.PdfReportHandler.java
/** * Not Used for the current release// w w w .j a v a 2 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:hr.restart.util.chart.ChartXY.java
/** * Creates a PIE CHART/*from www .j a va 2 s . com*/ * @param dataset The org.jfree.data.PieDataset * @param title The title * @return org.jfree.chart.JFreeChart */ private JFreeChart createPieChart(final PieDataset dataset, String title) { final JFreeChart chart = ChartFactory.createPieChart(title, // chart title dataset, // data false, // include legend true, false); chart.setBackgroundPaint(Color.white); Plot plot = chart.getPlot(); // the subtitle from the combobox if (jcb != null) chart.addSubtitle(new TextTitle(jcb.getSelectedItem().toString())); //subtitles setted by the user. if (getSubtitles() != null) for (int i = 0; i < getSubtitles().size(); i++) { chart.addSubtitle(new TextTitle(getSubtitles().get(i).toString())); } final PiePlot piePlot = (PiePlot) plot; piePlot.setLabelFont(new Font("SansSerif", Font.PLAIN, 12)); piePlot.setNoDataMessage("NO DATA!"); piePlot.setCircular(false); piePlot.setLabelLinkPaint(Color.red); piePlot.setLabelGap(0.02); return chart; }
From source file:uom.research.thalassemia.util.PieChartCreator.java
/** * Creates a chart.//from w ww.j a v a 2 s. c om * * @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:lucee.runtime.tag.Chart.java
private void chartPie() throws PageException, IOException { // do dataset DefaultPieDataset dataset = new DefaultPieDataset(); ChartSeriesBean csb = _series.get(0); ChartDataBean cdb;/*from w ww. j av a 2 s .c om*/ List datas = csb.getDatas(); if (sortxaxis) Collections.sort(datas); Iterator itt = datas.iterator(); while (itt.hasNext()) { cdb = (ChartDataBean) itt.next(); dataset.setValue(cdb.getItemAsString(), cdb.getValue()); } JFreeChart chart = show3d ? ChartFactory.createPieChart3D(title, dataset, false, true, true) : ChartFactory.createPieChart(title, dataset, false, true, true); Plot p = chart.getPlot(); PiePlot pp = (PiePlot) p; Font _font = getFont(); pp.setLegendLabelGenerator(new PieSectionLegendLabelGeneratorImpl(_font, chartwidth)); pp.setBaseSectionOutlinePaint(Color.GRAY); // border pp.setLegendItemShape(new Rectangle(7, 7)); pp.setLabelFont(new Font(font, 0, 11)); pp.setLabelLinkPaint(COLOR_333333); pp.setLabelLinkMargin(-0.05); pp.setInteriorGap(0.123); pp.setLabelGenerator(new PieSectionLabelGeneratorImpl(labelFormat)); databackgroundcolor = backgroundcolor; setBackground(chart, p); setBorder(chart, p); setLegend(chart, p, _font); set3d(p); setFont(chart, _font); setTooltip(chart); setScale(chart); // Slice Type and colors boolean doSclice = pieslicestyle == PIE_SLICE_STYLE_SLICED; Color[] colors = csb.getColorlist(); Iterator it = csb.getDatas().iterator(); int count = 0; while (it.hasNext()) { cdb = (ChartDataBean) it.next(); if (doSclice) pp.setExplodePercent(cdb.getItemAsString(), 0.13); if (count < colors.length) { pp.setSectionPaint(cdb.getItemAsString(), colors[count]); } count++; } writeOut(chart); }
From source file:semaforo.Semaforo.java
public static void SemaforoGrafico(JFreeChart chart) { // set a custom background for the chart chart.setBackgroundPaint(new GradientPaint(new Point(0, 0), Color.BLACK, new Point(400, 200), Color.BLACK)); // customise the title position and font TextTitle t = chart.getTitle();/* w ww. ja v a 2s . c om*/ t.setHorizontalAlignment(HorizontalAlignment.LEFT); t.setPaint(new Color(240, 240, 240)); t.setFont(new Font("Arial", Font.BOLD, 0)); PiePlot plot = null; plot = (PiePlot) chart.getPlot(); plot.setBackgroundPaint(null); plot.setInteriorGap(0.00); plot.setOutlineVisible(true); // use gradients and white borders for the section colours plot.setBaseSectionOutlinePaint(Color.BLACK); plot.setSectionOutlinesVisible(true); plot.setBaseSectionOutlineStroke(new BasicStroke(0.0f)); // customise the section label appearance plot.setLabelFont(new Font("Courier New", Font.BOLD, 0)); plot.setLabelLinkPaint(Color.BLACK); plot.setLabelLinkStroke(new BasicStroke(0.0f)); plot.setLabelOutlineStroke(null); plot.setLabelPaint(Color.BLACK); plot.setLabelBackgroundPaint(null); plot.setLabelBackgroundPaint(Color.BLACK); plot.setLabelShadowPaint(Color.BLACK); // add a subtitle giving the data source // Mostramos la grafica dentro del jPanel1 panel = new ChartPanel(chart); panel.setBackground(Color.BLACK); panel.repaint(); jPanel3.setLayout(null); jPanel3.setLayout(new java.awt.BorderLayout()); jPanel3.remove(panel); jPanel3.add(panel); jPanel3.repaint(); Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); jTabbedPane1.setPreferredSize(new Dimension(screenSize.width, screenSize.height)); }
From source file:semaforo.Semaforo.java
public static void editGrafico() { DecimalFormat df = new DecimalFormat(); df.setMaximumFractionDigits(2);/*from www . j a v a 2 s. co m*/ double cfd = 0.0; double bull = 0.0; double bear = 0.0; if (countCfd != 0) cfd = (countCfd * 100) / (countBear + countBull + countCfd); if (countBull != 0) bull = ((countBull * 100) / (countBear + countBull + countCfd)); if (countBear != 0) bear = ((countBear * 100) / (countBear + countBull + countCfd)); Semaforo.l1.setText("CFD (" + String.format("%.2f", cfd) + "%)"); Semaforo.l2.setText("BULL (" + String.format("%.2f", bull) + "%)"); Semaforo.l3.setText("BEAR (" + String.format("%.2f", bear) + "%)"); DefaultPieDataset pieDataset = new DefaultPieDataset(); pieDataset.setValue("CFD (" + cfd + "%)", new Integer((int) countCfd)); pieDataset.setValue("BULL (" + bull + "%)", new Integer((int) countBull)); pieDataset.setValue("BEAR (" + bear + "%)", new Integer((int) countBear)); JFreeChart chart = null; chart = ChartFactory.createPieChart("", // chart title pieDataset, // data false, // no legend false, // tooltips false // no URL generation ); // set a custom background for the chart chart.setBackgroundPaint(new GradientPaint(new Point(0, 0), Color.BLACK, new Point(400, 200), Color.BLACK)); // 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, 0)); PiePlot plot = null; plot = (PiePlot) chart.getPlot(); plot.setBackgroundPaint(null); plot.setInteriorGap(0.00); plot.setOutlineVisible(true); // use gradients and white borders for the section colours plot.setBaseSectionOutlinePaint(Color.BLACK); plot.setSectionOutlinesVisible(true); plot.setBaseSectionOutlineStroke(new BasicStroke(0.0f)); // customise the section label appearance plot.setLabelFont(new Font("Courier New", Font.BOLD, 0)); plot.setLabelLinkPaint(Color.BLACK); plot.setLabelLinkStroke(new BasicStroke(0.0f)); plot.setLabelOutlineStroke(null); plot.setLabelPaint(Color.BLACK); plot.setLabelBackgroundPaint(null); plot.setLabelBackgroundPaint(Color.BLACK); plot.setLabelShadowPaint(Color.BLACK); // add a subtitle giving the data source // Mostramos la grafica dentro del jPanel1 Semaforo.panel.setChart(chart); }