List of usage examples for org.jfree.chart.labels StandardPieSectionLabelGenerator StandardPieSectionLabelGenerator
public StandardPieSectionLabelGenerator(String labelFormat, NumberFormat numberFormat,
NumberFormat percentFormat)
From source file:com.globalsight.util.JfreeCharUtil.java
public static void drawPieChart2D(String title, Map<String, Double> datas, File OutFile) { PieDataset dataset = buildDatas(datas); JFreeChart chart = ChartFactory.createPieChart(title, dataset, true, true, false); PiePlot plot = (PiePlot) chart.getPlot(); plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0}={1}({2})", NumberFormat.getNumberInstance(), new DecimalFormat("0.00%"))); plot.setLegendLabelGenerator(new StandardPieSectionLabelGenerator("{0}={1}({2})")); chart.setBackgroundPaint(Color.white); plot.setCircular(true);// w w w . j a v a 2s. co m TextTitle textTitle = new TextTitle(title); Font font = new Font(textTitle.getFont().getName(), Font.CENTER_BASELINE, 20); textTitle.setFont(font); chart.setTitle(textTitle); FileOutputStream fos_jpg = null; try { fos_jpg = new FileOutputStream(OutFile); ChartUtilities.writeChartAsJPEG(fos_jpg, 1, chart, 640, 480, null); fos_jpg.close(); } catch (Exception e) { s_logger.error(e.getMessage(), e); } }
From source file:systeminformation.Chart.java
public JFreeChart create3DPieChart(PieDataset dataset) { JFreeChart chart = ChartFactory.createPieChart3D("", dataset, true, true, true); PiePlot3D p = (PiePlot3D) chart.getPlot(); PieSectionLabelGenerator gen = new StandardPieSectionLabelGenerator("{0}: {1} ({2})", new DecimalFormat("0"), new DecimalFormat("0%")); p.setLabelGenerator(gen);//from w ww. ja v a2 s .co m // p.setSimpleLabels(true); p.setForegroundAlpha(0.5f); p.setBackgroundAlpha(0.2f); chart.setBackgroundPaint(Color.white); chart.setAntiAlias(true); chart.setBorderVisible(true); return chart; }
From source file:esprit.rt.gui.StatistiquesRestaurateur.java
/** * Creates new form StatistiquesRestaurateur */// ww w .j a v a2 s. c o m public StatistiquesRestaurateur() { initComponents(); setLocationRelativeTo(null); dataset = new DefaultPieDataset(); //Statique PieSectionLabelGenerator gen = new StandardPieSectionLabelGenerator("{0}: {1} places rservs ({2})", new DecimalFormat("0"), new DecimalFormat("0%")); PieSectionLabelGenerator gen2 = new StandardPieSectionLabelGenerator("{0}: {1} DT de revenue ({2})", new DecimalFormat("0"), new DecimalFormat("0%")); for (Entry e : new StatistiqueDAO().mostBooked().entrySet()) { if (Float.parseFloat((String) e.getValue()) > max1) { i1 = j; max1 = Float.parseFloat((String) e.getValue()); } dataset.setValue((Comparable) e.getKey(), Float.parseFloat((String) e.getValue())); j++; } graphe = ChartFactory.createPieChart3D("Les restaurant les plus rserv", dataset, true, true, false); PiePlot plot = (PiePlot) graphe.getPlot(); plot.setLabelGenerator(gen); cp = new ChartPanel(graphe); cp.setBounds(new Rectangle(490, 400)); PieChart.getContentPane().add(cp); cp.setVisible(true); PieChart.setVisible(true); title.setHorizontalAlignment(JLabel.CENTER); try { title.setFont(new FontsPartieRestaurateur().getFont(FontsPartieRestaurateur.TITLE, 70)); } catch (FontFormatException ex) { Logger.getLogger(ConsultRestaurant.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(ConsultRestaurant.class.getName()).log(Level.SEVERE, null, ex); } dataset2 = new DefaultPieDataset(); //Statique for (Entry e : new StatistiqueDAO().mostPayed().entrySet()) { if (Float.parseFloat((String) e.getValue()) > max2) { i2 = k; max2 = Float.parseFloat((String) e.getValue()); } dataset2.setValue((Comparable) e.getKey(), Float.parseFloat((String) e.getValue())); k++; } graphe2 = ChartFactory.createPieChart3D("Restaurant avec le meilleur revenue", dataset2, true, true, false); PiePlot plot2 = (PiePlot) graphe2.getPlot(); plot2.setLabelGenerator(gen2); cp2 = new ChartPanel(graphe2); cp2.setBounds(new Rectangle(490, 400)); Pie2.add(cp2); cp2.setVisible(true); Pie2.setVisible(true); try { if (i1 == i2) { conseil.setForeground(Color.green); conseil.setText( "Vos statistiques sont parfaites! Votre restaurant le plus rserv est celui avec le plus de revenue!"); } else { conseil.setForeground(Color.red); conseil.setText( "Le restaurant le plus rserv n'est pas celui avec le plus revenue! Verifier votre stratgie de prix!"); } } catch (Exception e) { conseil.setVisible(false); } }
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 a v a 2s . c om 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:com.globalsight.util.JfreeCharUtil.java
public static void drawPieChart3D(String title, Map<String, Double> datas, File OutFile) { PieDataset dataset = buildDatas(datas); JFreeChart chart = ChartFactory.createPieChart3D(title, dataset, true, true, false); PiePlot3D plot = (PiePlot3D) chart.getPlot(); plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0}={1}({2})", NumberFormat.getNumberInstance(), new DecimalFormat("0.00%"))); plot.setLegendLabelGenerator(new StandardPieSectionLabelGenerator("{0}={1}({2})")); chart.setBackgroundPaint(Color.white); plot.setForegroundAlpha(0.7f);/*w w w . jav a 2 s . c o m*/ plot.setCircular(true); TextTitle textTitle = new TextTitle(title); Font font = new Font(textTitle.getFont().getName(), Font.CENTER_BASELINE, 20); textTitle.setFont(font); chart.setTitle(textTitle); FileOutputStream fos_jpg = null; try { fos_jpg = new FileOutputStream(OutFile); ChartUtilities.writeChartAsJPEG(fos_jpg, 1, chart, 640, 480, null); fos_jpg.close(); } catch (Exception e) { s_logger.error(e.getMessage(), e); } }
From source file:net.sf.dynamicreports.design.transformation.chartcustomizer.PieChartLabelFormatCustomizer.java
@Override public void customize(JFreeChart chart, ReportParameters reportParameters) { PiePlot plot = (PiePlot) chart.getPlot(); if (labelFormat == null) { plot.setLabelGenerator(null);/* www . j a v a 2 s . c om*/ } else { plot.setLabelGenerator(new StandardPieSectionLabelGenerator(labelFormat, new DecimalFormat(valuePattern), new DecimalFormat(percentValuePattern + "%"))); } }
From source file:servlet.SalesReportPieChart.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./*from w w 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:com.mxgraph.examples.swing.chart.PieChartDemo1.java
/** * Creates a chart./*from w w w. ja va 2s . c o m*/ * * @param dataset the dataset. * * @return A chart. */ public static JFreeChart createChart(PieDataset dataset) { JFreeChart chart = ChartFactory.createPieChart("", // chart title dataset, // data true, // include legend true, false); PiePlot plot = (PiePlot) chart.getPlot(); plot.setSectionOutlinesVisible(false); plot.setNoDataMessage("No data available"); plot.setCircular(true); plot.setLabelGap(0.01D);// plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0}:\r\n{1}({2})", NumberFormat.getNumberInstance(), new DecimalFormat("0.00%"))); // // plot.setLegendLabelGenerator(new StandardPieSectionLabelGenerator("{0}={1}({2})")); chart.getTitle().setFont(new Font("", Font.PLAIN, 20));// PiePlot piePlot = (PiePlot) chart.getPlot();// piePlot.setLabelFont(new Font("", Font.PLAIN, 10)); chart.getLegend().setItemFont(new Font("", Font.PLAIN, 10)); return chart; }
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? );//from w ww . j a v a 2 s. c o 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:de.main.sessioncreator.ReportingHelper.java
/** * Creates a chart/* ww w . j ava 2 s. co m*/ */ private JFreeChart createChart(PieDataset dataset, String title) { // JFreeChart chart = ChartFactory.createPieChart3D( JFreeChart chart = ChartFactory.createPieChart(title, // chart title dataset, // data false, // include legend true, false); // PiePlot3D plot = (PiePlot3D) chart.getPlot(); PiePlot plot = (PiePlot) chart.getPlot(); plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0} = {2}", NumberFormat.getNumberInstance(), NumberFormat.getPercentInstance())); plot.setStartAngle(90); plot.setDirection(Rotation.CLOCKWISE); plot.setForegroundAlpha(0.5f); return chart; }