List of usage examples for org.jfree.chart ChartFactory createPieChart
public static JFreeChart createPieChart(String title, PieDataset dataset, boolean legend, boolean tooltips, boolean urls)
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 w w. j ava2s . com*/ 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.mxgraph.examples.swing.chart.PieChartDemo1.java
/** * Creates a chart./*from w ww .ja v a 2 s . c om*/ * * @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:fr.paris.lutece.plugins.form.business.GraphTypePieChart.java
/** * return the PieChartGraph JFreeChart graph * @param listStatistic listStatistic//from www . j a v a 2 s . c o m * @param strGraphTitle graph title * @param nGraphThreeDimension true if the graph must be in three dimension * @param nGraphLabelValue true if the labels must appear in the graph * @return the JFreeChart graph associate to the graph type */ public static JFreeChart createPieChartGraph(List<StatisticEntrySubmit> listStatistic, String strGraphTitle, boolean nGraphThreeDimension, boolean nGraphLabelValue) { PieDataset pieDataset = createPieDataset(listStatistic); JFreeChart chart; if (nGraphThreeDimension) { chart = ChartFactory.createPieChart3D(strGraphTitle, pieDataset, true, true, false); } else { chart = ChartFactory.createPieChart(strGraphTitle, pieDataset, true, true, false); } PiePlot plot = (PiePlot) chart.getPlot(); if (nGraphLabelValue) { plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{2}")); } else { plot.setLabelGenerator(null); } return chart; }
From source file:org.gephi.desktop.context.ContextPieChart.java
public ContextPieChart() { data = new DefaultPieDataset(); final JFreeChart chart = ChartFactory.createPieChart("Employee Survey", data, false, false, false); chart.setTitle(new TextTitle()); chart.setBackgroundPaint(null);//from w ww. ja v a 2 s . c o m chart.setPadding(new RectangleInsets(0, 0, 0, 0)); PiePlot plot = (PiePlot) chart.getPlot(); plot.setShadowPaint(null); plot.setSimpleLabels(true); plot.setLabelBackgroundPaint(null); plot.setLabelOutlineStroke(null); plot.setLabelShadowPaint(null); plot.setOutlineVisible(false); plot.setLabelFont(new java.awt.Font("Tahoma", 0, 10)); plot.setLabelPaint(Color.WHITE); plot.setLabelGap(0.5); plot.setCircular(true); plot.setInteriorGap(0); plot.setBackgroundPaint(null); plot.setBackgroundAlpha(1f); plot.setSectionPaint(NbBundle.getMessage(getClass(), "ContextPieChart.visible"), new Color(0x222222)); plot.setSectionPaint(NbBundle.getMessage(getClass(), "ContextPieChart.notVisible"), new Color(0xDDDDDD)); chartPanel = new ChartPanel(chart, 100, 100, 10, 10, 300, 300, true, false, false, false, false, false); ((FlowLayout) chartPanel.getLayout()).setHgap(0); ((FlowLayout) chartPanel.getLayout()).setVgap(0); chartPanel.setOpaque(false); chartPanel.setPopupMenu(null); }
From source file:tr.gov.ptt.gr1tahsilatuyg.bean.TahsilatChartBean.java
public StreamedContent getJfreeChart() { StreamedContent content = null;//from w w w . j a v a 2 s.co m try { chartListe = tahsilatBorcService.chartVerisiGetir(); for (Object[] chartElement : chartListe) { dataset.setValue(String.valueOf(chartElement[0]), Double.valueOf(chartElement[1].toString())); } boolean legend = true, tooltip = true, urls = false; JFreeChart chart = ChartFactory.createPieChart("JFreeChart", dataset, legend, tooltip, urls); File chartFile = new File("jfreechart"); int width = 375, height = 300; ChartUtilities.saveChartAsPNG(chartFile, chart, width, height); content = new DefaultStreamedContent(new FileInputStream(chartFile), "image/png"); } catch (Exception e) { e.printStackTrace(); throw new RuntimeException(e); } return content; }
From source file:org.jfree.chart.demo.PieChartDemo7.java
/** * Creates a new demo instance./*from w w w . j a va 2 s. c o m*/ * * @param title the frame title. */ public PieChartDemo7(String title) { super(title); JPanel panel = new JPanel(new GridLayout(2, 2)); DefaultPieDataset dataset = new DefaultPieDataset(); dataset.setValue("Section 1", 23.3); dataset.setValue("Section 2", 56.5); dataset.setValue("Section 3", 43.3); dataset.setValue("Section 4", 11.1); JFreeChart chart1 = ChartFactory.createPieChart("Chart 1", dataset, false, false, false); JFreeChart chart2 = ChartFactory.createPieChart("Chart 2", dataset, false, false, false); PiePlot plot2 = (PiePlot) chart2.getPlot(); plot2.setCircular(false); JFreeChart chart3 = ChartFactory.createPieChart3D("Chart 3", dataset, false, false, false); PiePlot3D plot3 = (PiePlot3D) chart3.getPlot(); plot3.setForegroundAlpha(0.6f); plot3.setCircular(true); JFreeChart chart4 = ChartFactory.createPieChart3D("Chart 4", dataset, false, false, false); PiePlot3D plot4 = (PiePlot3D) chart4.getPlot(); plot4.setForegroundAlpha(0.6f); panel.add(new ChartPanel(chart1)); panel.add(new ChartPanel(chart2)); panel.add(new ChartPanel(chart3)); panel.add(new ChartPanel(chart4)); panel.setPreferredSize(new Dimension(800, 600)); setContentPane(panel); }
From source file:edu.ucla.stat.SOCR.chart.demo.PieChartDemo3.java
/** * Creates a demo chart.// w w w . jav a 2s .c o m * * @param dataset the dataset. * * @return A chart. */ protected JFreeChart createChart(PieDataset dataset) { dataset = null; JFreeChart chart = ChartFactory.createPieChart(chartTitle, // chart title dataset, // data !legendPanelOn, // include legend true, false); PiePlot plot = (PiePlot) chart.getPlot(); plot.setNoDataMessage("No data available so we go into this really " + "long spiel about what that means and it runs off the end of the " + "line but what can you do about that!"); plot.setNoDataMessageFont(new Font("Serif", Font.ITALIC, 10)); plot.setNoDataMessagePaint(Color.red); 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); } } if (rotateOn) { Rotator rotator = new Rotator(plot); rotator.start(); } setCategorySummary(dataset); return chart; }
From source file:it.marcoberri.mbmeteo.action.chart.GetLastUPie.java
/** * Processes requests for both HTTP//from w w w . ja va 2 s .c om * <code>GET</code> and * <code>POST</code> methods. * * @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 { log.debug("start : " + this.getClass().getName()); final HashMap<String, String> params = getParams(request.getParameterMap()); final Integer dimy = Default.toInteger(params.get("dimy"), 600); final Integer dimx = Default.toInteger(params.get("dimx"), 800); Meteolog meteolog = ds.find(Meteolog.class).order("-time").limit(1).get(); final DefaultPieDataset dataset = new DefaultPieDataset(); dataset.setValue(ChartEnumMinMaxHelper.outdoorHumidityMin.getUm(), meteolog.getOutdoorHumidity()); dataset.setValue("", 100 - meteolog.getOutdoorHumidity()); JFreeChart chart = ChartFactory.createPieChart("Humidity %", // chart title dataset, // data true, // include legend true, false); PiePlot plot = (PiePlot) chart.getPlot(); plot.setLabelFont(new Font("SansSerif", Font.PLAIN, 12)); plot.setNoDataMessage("No data available"); plot.setCircular(false); plot.setLabelGap(0.02); final File f = File.createTempFile("mbmeteo", ".jpg"); ChartUtilities.saveChartAsJPEG(f, chart, dimx, dimy); response.setContentType("image/jpeg"); response.setHeader("Content-Length", "" + f.length()); response.setHeader("Content-Disposition", "inline; filename=\"" + f.getName() + "\""); final OutputStream out = response.getOutputStream(); final FileInputStream in = new FileInputStream(f.toString()); final int size = in.available(); final byte[] content = new byte[size]; in.read(content); out.write(content); in.close(); out.close(); }
From source file:tr.gov.ptt.gr1tahsilatuyg.managedbean.ChartBean.java
public StreamedContent getJfreeChart() { StreamedContent content = null;/*from w ww. j a v a 2 s. c o m*/ try { chartListe = tahsilatBorcService.chartVerisiGetir(); for (Object[] chartElement : chartListe) { dataset.setValue(String.valueOf(chartElement[0]), Double.valueOf(chartElement[1].toString())); } boolean legend = true, tooltip = true, urls = false; JFreeChart chart = ChartFactory.createPieChart("JFreeChart", dataset, legend, tooltip, urls); File chartFile = new File("jfreechart"); int width = 375, height = 300; ChartUtilities.saveChartAsPNG(chartFile, chart, width, height); content = new DefaultStreamedContent(new FileInputStream(chartFile), "image/png"); } catch (Exception e) { e.printStackTrace(); throw new RuntimeException(e); } return content; }
From source file:Servidor.java
public String graficarPastel(ArrayList<String> candidatos) { for (int i = 0; i < candidatos.size(); i++) { //recordar que el arrayList Est en mltiplos de 3: if (esMultiploDeTres(i + 1)) { datosPastel.setValue(candidatos.get(i - 1), Integer.parseInt(candidatos.get(i))); }//from w w w. j a v a 2 s. c o m } //creando el grfico. chart = ChartFactory.createPieChart("Grfica de pastel.", datosPastel, true, true, false); return "Terminar; Solicitud para Graficar Pastel ha sido procesada con xito."; }