List of usage examples for org.jfree.chart ChartFactory createPieChart
public static JFreeChart createPieChart(String title, PieDataset dataset)
From source file:business.management.system.TeamStatistics.java
/** * Creates new form TeamStatistics/*from w w w. j a v a 2s .c o m*/ */ public TeamStatistics() throws SQLException { initComponents(); JFreeChart pieChart = ChartFactory.createPieChart("Completed projects", createPieDataset()); ChartPanel chartPanel1 = new ChartPanel(pieChart); chartPanel1.setPreferredSize(new java.awt.Dimension(560, 367)); add(chartPanel1); JPanel panel = new JPanel(); panel.add(chartPanel1); setContentPane(panel); }
From source file:org.jfree.graphics2d.demo.CanvasPieChartDemo1.java
/** * Creates a chart./* w w w .j a va 2s. c om*/ * * @param dataset the dataset. * * @return A chart. */ private static JFreeChart createChart(PieDataset dataset) { JFreeChart chart = ChartFactory.createPieChart("Pie Chart Demo 1", dataset); PiePlot plot = (PiePlot) chart.getPlot(); plot.setSectionOutlinesVisible(false); plot.setNoDataMessage("No data available"); return chart; }
From source file:org.jfree.graphics2d.demo.SVGPieChartDemo1.java
/** * Creates a chart.//from w w w . j a v a2 s.co m * * @param dataset the dataset. * * @return A chart. */ private static JFreeChart createChart(PieDataset dataset) { JFreeChart chart = ChartFactory.createPieChart("Smart Phones Manufactured / Q3 2011", // chart title dataset); chart.removeLegend(); // set a custom background for the chart chart.setBackgroundPainter(new GradientPainter(new Color(20, 20, 20), RectangleAnchor.TOP_LEFT, Color.DARK_GRAY, RectangleAnchor.BOTTOM_RIGHT)); // 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.setBackgroundPainter(null); plot.setInteriorGap(0.04); plot.setBorderPainter(null); // 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("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:org.jfree.chart.demo.selection.SelectionDemo6Pie.java
private static JFreeChart createChart(final PieDataset dataset, DatasetSelectionExtension<PieCursor<String>> ext) { JFreeChart chart = ChartFactory.createPieChart("Pie Chart Demo 2", dataset); final PiePlot plot = (PiePlot) chart.getPlot(); plot.setSectionPaint("One", new Color(160, 160, 255)); plot.setSectionPaint("Two", new Color(128, 128, 255 - 32)); plot.setSectionPaint("Three", new Color(96, 96, 255 - 64)); plot.setSectionPaint("Four", new Color(64, 64, 255 - 96)); plot.setSectionPaint("Five", new Color(32, 32, 255 - 128)); plot.setSectionPaint("Six", new Color(0, 0, 255 - 144)); plot.setNoDataMessage("No data available"); plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0} ({2} percent)")); plot.setLabelBackgroundPaint(new Color(220, 220, 220)); plot.setLegendLabelToolTipGenerator(new StandardPieSectionLabelGenerator("Tooltip for legend item {0}")); plot.setSimpleLabels(true);/*w ww. j a v a 2 s. c om*/ plot.setInteriorGap(0.1); //pie plots done use abstract renderers need to react to selection on our own final PieCursor<String> cursor = new PieCursor<String>(); ext.addChangeListener(new SelectionChangeListener<PieCursor<String>>() { public void selectionChanged(SelectionChangeEvent<PieCursor<String>> event) { for (int i = 0; i < dataset.getItemCount(); i++) { cursor.setPosition((String) dataset.getKey(i)); if (event.getSelectionExtension().isSelected(cursor)) { plot.setExplodePercent(cursor.key, 0.15); } else { plot.setExplodePercent(cursor.key, 0.0); } } } }); return chart; }
From source file:com.leonarduk.finance.chart.PieChartFactory.java
public JFreeChart buildChart() { final JFreeChart chart = ChartFactory.createPieChart(this.title, this.dataset); final PiePlot p = (PiePlot) chart.getPlot(); p.setLabelFont(new Font("SansSerif", Font.PLAIN, 8)); p.setInteriorGap(0.01);/*from ww w. j a v a2 s . co m*/ return chart; }
From source file:com.geometrycloud.happydonut.ui.ChartFilterPanel.java
/** * Crea un nuevo grafico con la informacion del top de ventas. * * @return grafico.//from www. j a v a 2s. co m */ private JFreeChart createChart() { LocalDate from = build(fromPicker), to = build(toPicker); return ChartFactory.createPieChart(message("TOP"), chartDataset(from, to)); }
From source file:tn.mariages.gui.Statistiques.java
private void formWindowOpened(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowOpened ///////*from ww w . java 2s . co m*/ DefaultPieDataset dataset;//Dataset qui va contenir les Donnes JFreeChart graphe; //Graphe ChartPanel cp; //Panel dataset = new DefaultPieDataset(); panierProduitDAO ppDAO = new panierProduitDAO(); PanierProduit pp = new PanierProduit(); HashMap<Integer, Integer> top10BestSeller = ppDAO.getTop10BestSeller(); ProduitDAO pDAO = new ProduitDAO(); Iterator<Integer> i = top10BestSeller.keySet().iterator(); while (i.hasNext()) { Integer key = i.next(); System.out.println("key: " + key + " value: " + top10BestSeller.get(key)); Produit DisplayProdByID = pDAO.DisplayProdByID(key); dataset.setValue("" + DisplayProdByID.getNomProd(), new Double(top10BestSeller.get(key))); } graphe = ChartFactory.createPieChart("Top Ventes Produits", dataset); ChartPanel CP = new ChartPanel(graphe); JOptionPane.showMessageDialog(this, "id " + id + " Type : " + typeDeComptes); ///// }
From source file:roaded.MainGUI.java
public void loadGraphInfo() { if (busyStatus) { infoBox("Please load 311 data first on the data tab.", "Message"); return;//from w w w . j a v a2s . c o m } pieDataset.clear(); // Store coordinates of each related ticket incident Coordinates coordinateData = new Coordinates(); coords.clear(); for (int i = 0; i < 12; i++) { int counter = 0; if (wardsSelected[i] == true) { for (TicketData entry : ticketObj.getData()) { if (i < 10) { if (entry.getWard() != null && entry.getWard().compareTo("WARD 0" + (i + 1)) == 0) { counter++; coordinateData = new Coordinates(); coordinateData.setCoordinates(entry.getLoc_lat(), entry.getLoc_long()); coords.add(coordinateData); } } else { if (entry.getWard() != null && entry.getWard().compareTo("WARD 1" + (i - 9)) == 0) { counter++; coordinateData = new Coordinates(); coordinateData.setCoordinates(entry.getLoc_lat(), entry.getLoc_long()); coords.add(coordinateData); } } } pieDataset.setValue("Ward " + (i + 1), counter); counter = 0; } } // Export to file so that pin mapper can retrieve it try { PrintStream out = new PrintStream(new FileOutputStream("plotData.txt")); for (Coordinates coord : coords) { out.println(coord); } } catch (FileNotFoundException ex) { Logger.getLogger(MainGUI.class.getName()).log(Level.SEVERE, null, ex); } // Loads the pie chart for all wards selected JFreeChart chart = ChartFactory.createPieChart(wardNumber, pieDataset); chart.removeLegend(); PieChart.setLayout(new java.awt.BorderLayout()); ChartPanel CP = new ChartPanel(chart); CP.addChartMouseListener(CML); CP.setPreferredSize(new Dimension(785, 440)); //size according to my window CP.setMouseWheelEnabled(true); PieChart.add(CP); //bargraph dataset.clear(); //resets bargraph when new wards are elected CategoryDataset dataset1 = createDataset1(); //uses dataset to create the bargraph JFreeChart chart1 = ChartFactory.createBarChart( // bargraph labels and orientation "Ward Incidents", "Wards", "Incidents", dataset1, PlotOrientation.VERTICAL, true, true, false); //bargraph settings DualAxis.setLayout(new java.awt.BorderLayout()); chart1.setBackgroundPaint(Color.white); final CategoryPlot plot = chart1.getCategoryPlot(); plot.setBackgroundPaint(new Color(0xEE, 0xEE, 0xFF)); plot.setDomainAxisLocation(AxisLocation.BOTTOM_OR_RIGHT); final LineAndShapeRenderer renderer2 = new LineAndShapeRenderer(); renderer2.setToolTipGenerator(new StandardCategoryToolTipGenerator()); plot.setRenderer(1, renderer2); plot.setDatasetRenderingOrder(DatasetRenderingOrder.REVERSE); //bar graph chart panel creation final ChartPanel chartPanel = new ChartPanel(chart1); chartPanel.setDomainZoomable(true); chartPanel.setRangeZoomable(true); chartPanel.setMouseZoomable(true); chartPanel.setMouseWheelEnabled(true); DualAxis.add(chartPanel); }
From source file:tn.mariages.gui.Accueil.java
public StatVentesProd() { dataset = new DefaultPieDataset(); panierProduitDAO ppDAO = new panierProduitDAO(); PanierProduit pp = new PanierProduit(); HashMap<Integer, Integer> top10BestSeller = ppDAO.getTop10BestSeller(); ProduitDAO pDAO = new ProduitDAO(); Iterator<Integer> i = top10BestSeller.keySet().iterator(); while (i.hasNext()) { Integer key = i.next();/*w ww. j a v a2 s . c o m*/ System.out.println("key: " + key + " value: " + top10BestSeller.get(key)); Produit DisplayProdByID = pDAO.DisplayProdByID(key); dataset.setValue("" + DisplayProdByID.getNomProd(), new Double(top10BestSeller.get(key))); } graphe = ChartFactory.createPieChart("Top Ventes Produits", dataset); cp = new ChartPanel(graphe); this.add(cp); }
From source file:tn.mariages.gui.Accueil.java
public PieChartComs() { dataset = new DefaultPieDataset(); CommentaireDAO cDAO = new CommentaireDAO(); HashMap<Integer, Integer> top10Coms = cDAO.getTop10Coms(); Produit p = new Produit(); ProduitDAO pDAO = new ProduitDAO(); Iterator<Integer> i = top10Coms.keySet().iterator(); while (i.hasNext()) { Integer key = i.next();//from w ww . ja v a2 s . com System.out.println("key: " + key + " value: " + top10Coms.get(key)); Produit DisplayProdByID = pDAO.DisplayProdByID(key); dataset.setValue("" + DisplayProdByID.getNomProd(), new Double(top10Coms.get(key))); System.out.println("1"); } graphe = ChartFactory.createPieChart("Top Commentaires", dataset); cp = new ChartPanel(graphe); this.add(cp); }