List of usage examples for org.jfree.chart.labels StandardPieItemLabelGenerator StandardPieItemLabelGenerator
public StandardPieItemLabelGenerator(String labelFormat, NumberFormat numberFormat,
NumberFormat percentFormat)
From source file:org.jfree.chart.demo.XMLPieChartDemo.java
/** * Default constructor.//from ww w . j a v a2 s . co m * * @param title the frame title. */ public XMLPieChartDemo(final String title) { super(title); // create a dataset... PieDataset dataset = null; final URL url = getClass().getResource("/org/jfree/chart/demo/piedata.xml"); try { final InputStream in = url.openStream(); dataset = DatasetReader.readPieDatasetFromXML(in); } catch (IOException ioe) { System.out.println(ioe.getMessage()); } // create the chart... final JFreeChart chart = ChartFactory.createPieChart("Pie Chart Demo 1", // chart title dataset, // data true, // include legend true, false); // set the background color for the chart... chart.setBackgroundPaint(Color.yellow); final PiePlot plot = (PiePlot) chart.getPlot(); plot.setLabelGenerator(new StandardPieItemLabelGenerator("{0} = {2}", NumberFormat.getNumberInstance(), NumberFormat.getPercentInstance())); plot.setNoDataMessage("No data available"); // add the chart to a panel... final ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new java.awt.Dimension(500, 270)); setContentPane(chartPanel); }
From source file:org.jfree.chart.demo.PieChartDemo4.java
/** * Default constructor.//from w ww .j a v a2s . c o m * * @param title the frame title. */ public PieChartDemo4(final String title) { super(title); final PieDataset dataset = createDataset(14); // create the chart... final JFreeChart chart = ChartFactory.createPieChart("Pie Chart Demo 4", // chart title dataset, // dataset false, // include legend true, false); // set the background color for the chart... chart.setBackgroundPaint(new Color(222, 222, 255)); final PiePlot plot = (PiePlot) chart.getPlot(); plot.setBackgroundPaint(Color.white); plot.setCircular(true); plot.setLabelGenerator(new StandardPieItemLabelGenerator("{0} = {2}", NumberFormat.getNumberInstance(), NumberFormat.getPercentInstance())); plot.setNoDataMessage("No data available"); // add the chart to a panel... final ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new java.awt.Dimension(500, 270)); setContentPane(chartPanel); final Rotator rotator = new Rotator(plot); rotator.start(); }
From source file:cn.edu.thss.iise.bpmdemo.charts.PieChartDemo4.java
/** * Default constructor.//from w ww . jav a2 s .co m * * @param title * the frame title. */ public PieChartDemo4(final String title) { super(title); final PieDataset dataset = createDataset(14); // create the chart... final JFreeChart chart = ChartFactory.createPieChart("Pie Chart Demo 4", // chart title dataset, // dataset false, // include legend true, false); // set the background color for the chart... chart.setBackgroundPaint(new Color(222, 222, 255)); final PiePlot plot = (PiePlot) chart.getPlot(); plot.setBackgroundPaint(Color.white); plot.setCircular(true); plot.setLabelGenerator(new StandardPieItemLabelGenerator("{0} = {2}", NumberFormat.getNumberInstance(), NumberFormat.getPercentInstance())); plot.setNoDataMessage("No data available"); // add the chart to a panel... final ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new java.awt.Dimension(500, 270)); // add table Object[][] data = { { "Kathy0", new Integer(0) }, { "Kathy1", new Integer(2) }, { "Kathy2", new Integer(5) }, { "Kathy3", new Integer(5) }, { "Kathy4", new Integer(5) }, { "Kathy5", new Integer(5) }, { "Kathy6", new Integer(5) }, { "Kathy7", new Integer(5) }, { "Kathy8", new Integer(5) }, { "Kathy9", new Integer(5) } }; String[] columnNames = { "Model Name", "Reuse Number" }; JTable table = new JTable(data, columnNames); final JPanel panel = new JPanel(); panel.add(chartPanel); panel.add(table); setContentPane(panel); final Rotator rotator = new Rotator(plot); rotator.start(); }
From source file:com.pureinfo.srm.reports.impl.PieChartBuilder.java
/** * @throws PureException//w ww. ja va2s . c o m * @see com.pureinfo.srm.reports.IChartBuilder#draw(java.util.List, int) */ public JFreeChart buildChart() { Iterator result = m_datas.iterator(); DefaultPieDataset ds = getDataset(result); JFreeChart jfreechart = ChartFactory.createPieChart3D(null, ds, false, false, false); jfreechart.setBackgroundPaint(Color.WHITE); PiePlot3D pieplot3d = (PiePlot3D) jfreechart.getPlot(); pieplot3d.setOutlinePaint(Color.GRAY); pieplot3d.setOutlineStroke(new BasicStroke(1)); pieplot3d.setStartAngle(30D); pieplot3d.setDepthFactor(0.04); pieplot3d.setDrawingSupplier(new DefaultDrawingSupplier(MyPaintMgr.getPaints(), DefaultDrawingSupplier.DEFAULT_OUTLINE_PAINT_SEQUENCE, DefaultDrawingSupplier.DEFAULT_STROKE_SEQUENCE, DefaultDrawingSupplier.DEFAULT_OUTLINE_STROKE_SEQUENCE, DefaultDrawingSupplier.DEFAULT_SHAPE_SEQUENCE)); pieplot3d.setCircular(false); pieplot3d.setDirection(Rotation.CLOCKWISE); pieplot3d.setOutlinePaint(Color.WHITE); pieplot3d.setInteriorGap(.15); Color color = new Color(0xaa, 0xaa, 0xaa, 255); pieplot3d.setBaseSectionOutlinePaint(color); pieplot3d.setBaseSectionOutlineStroke(new BasicStroke(0)); pieplot3d.setForegroundAlpha(0.6f); pieplot3d.setLabelLinkStroke(new BasicStroke(1)); pieplot3d.setLabelOutlinePaint(new Color(0x777777)); pieplot3d.setLabelBackgroundPaint(new Color(0xf1f1f7)); pieplot3d.setLabelLinkPaint(new Color(0xaa, 0xaa, 0xaa, 60)); pieplot3d.setNoDataMessage("No data to display"); pieplot3d.setLabelShadowPaint(new Color(0xdddddd)); pieplot3d.setLabelFont(new Font("", Font.PLAIN, 10)); if (m_nType == TYPE_PERCENT) { pieplot3d.setLabelGenerator(new StandardPieItemLabelGenerator("{0} = {2}", NumberFormat.getNumberInstance(), PERCENT_NUMBER_FORMAT)); } fillChartInfo(ds); return jfreechart; }
From source file:cn.edu.thss.iise.bpmdemo.statistics.actions.ModelReusePanel.java
private JPanel createPanel() throws IOException { createDataSet();/*from ww w . j a v a 2s . c om*/ // create the chart... final JFreeChart chart = ChartFactory.createPieChart("Reused Times", // chart // title data1, // dataset false, // include legend true, false); // set the background color for the chart... chart.setBackgroundPaint(new Color(222, 222, 255)); final PiePlot plot = (PiePlot) chart.getPlot(); plot.setBackgroundPaint(Color.white); plot.setCircular(true); plot.setLabelGenerator(new StandardPieItemLabelGenerator("{0} = {2}", NumberFormat.getNumberInstance(), NumberFormat.getPercentInstance())); plot.setNoDataMessage("No data available"); // add the chart to a panel... final ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new java.awt.Dimension(500, 270)); String[] columnNames = { "Name", "Reuse Times" }; JTable table = new JTable(data2, columnNames); JPanel panel = new JPanel(); panel.add(chartPanel); panel.add(table); final Rotator rotator = new Rotator(plot); rotator.start(); return panel; }
From source file:org.jfree.chart.demo.MultiplePieChartDemo2.java
/** * Creates a sample chart with the given dataset. * // w w w . j av a 2 s . c om * @param dataset the dataset. * * @return A sample chart. */ private JFreeChart createChart(final CategoryDataset dataset) { final JFreeChart chart = ChartFactory.createMultiplePieChart("Multiple Pie Chart", // chart title dataset, // dataset TableOrder.BY_COLUMN, true, // include legend true, false); final MultiplePiePlot plot = (MultiplePiePlot) chart.getPlot(); plot.setBackgroundPaint(Color.white); plot.setOutlineStroke(new BasicStroke(1.0f)); final JFreeChart subchart = plot.getPieChart(); final PiePlot p = (PiePlot) subchart.getPlot(); p.setBackgroundPaint(null); p.setOutlineStroke(null); p.setLabelGenerator(new StandardPieItemLabelGenerator("{0} ({2})", NumberFormat.getNumberInstance(), NumberFormat.getPercentInstance())); p.setMaximumLabelWidth(0.35); p.setLabelFont(new Font("SansSerif", Font.PLAIN, 9)); p.setInteriorGap(0.30); return chart; }
From source file:org.jfree.chart.demo.JFreeChartDemoBase.java
/** * Creates and returns a sample pie chart. * * @return a sample pie chart.// w w w. j a va 2 s . c o m */ public JFreeChart createPieChartTwo() { // create a default chart based on some sample data... final String title = this.resources.getString("pie.pie2.title"); final CategoryDataset data = DemoDatasetFactory.createCategoryDataset(); final Comparable category = (Comparable) data.getColumnKeys().get(1); final PieDataset extracted = DatasetUtilities.createPieDatasetForColumn(data, category); final JFreeChart chart = ChartFactory.createPieChart(title, extracted, true, true, false); // then customise it a little... chart.setBackgroundPaint(Color.lightGray); final PiePlot pie = (PiePlot) chart.getPlot(); pie.setLabelGenerator(new StandardPieItemLabelGenerator("{0} = {2}", NumberFormat.getNumberInstance(), NumberFormat.getPercentInstance())); pie.setBackgroundImage(JFreeChart.INFO.getLogo()); pie.setBackgroundPaint(Color.white); pie.setBackgroundAlpha(0.6f); pie.setForegroundAlpha(0.75f); return chart; }
From source file:ca.myewb.frame.servlet.GraphServlet.java
private JFreeChart getProvincePie(Session s) { JFreeChart chart;/*from w ww . j a va 2 s. c om*/ String[] provinces = { "PE", "YT", "NT", "NU", "ON", "QC", "AB", "BC", "NL", "MB", "NB", "NS", "SK" }; DefaultPieDataset ds = new DefaultPieDataset(); String query = "select count(*) from UserModel as u where u.province=?"; int total = 0; for (String province : provinces) { Integer integer = ((Long) s.createQuery(query).setString(0, province).list().get(0)).intValue(); total += integer; ds.setValue(province, integer); } chart = ChartFactory.createPieChart("Province Breakdown (for " + total + " known addresses)", ds, false, false, false); PiePlot plot = ((PiePlot) chart.getPlot()); StandardPieItemLabelGenerator n = new StandardPieItemLabelGenerator("{0} = {1} ({2})", new DecimalFormat("0"), new DecimalFormat("0.0%")); plot.setLabelGenerator(n); return chart; }
From source file:ca.myewb.frame.servlet.GraphServlet.java
private JFreeChart getPostPie(Session s) { JFreeChart chart;// w ww . ja v a2 s .com DefaultPieDataset ds = new DefaultPieDataset(); int numPosts = 0; int numTypePosts = 0; String query; query = "select count(*) from PostModel as p where p.poster.gender='m' and p.emailed=true and p.date>?"; numTypePosts = ((Long) s.createQuery(query).setDate(0, GraphServlet.getStartDate()).list().get(0)) .intValue(); ; ds.setValue("Emails by Males", numTypePosts); numPosts += numTypePosts; query = "select count(*) from PostModel as p where p.poster.gender='m' and " + "p.parent is null and p.emailed=false and p.date>?"; numTypePosts = ((Long) s.createQuery(query).setDate(0, GraphServlet.getStartDate()).list().get(0)) .intValue(); ; ds.setValue("Posts by Males", numTypePosts); numPosts += numTypePosts; query = "select count(*) from PostModel as p where p.poster.gender='m' and " + "p.parent is not null and p.emailed=false and p.date>?"; numTypePosts = ((Long) s.createQuery(query).setDate(0, GraphServlet.getStartDate()).list().get(0)) .intValue(); ; ds.setValue("Replies by Males", numTypePosts); numPosts += numTypePosts; query = "select count(*) from PostModel as p where p.poster.gender!='f' and p.poster.gender!='m' and p.date>?"; numTypePosts = ((Long) s.createQuery(query).setDate(0, GraphServlet.getStartDate()).list().get(0)) .intValue(); ; ds.setValue("All Posts by Unknown Gender", numTypePosts); numPosts += numTypePosts; query = "select count(*) from PostModel as p where p.poster.gender='f' and " + "p.parent is not null and p.emailed=false and p.date>?"; numTypePosts = ((Long) s.createQuery(query).setDate(0, GraphServlet.getStartDate()).list().get(0)) .intValue(); ; ds.setValue("Replies by Females", numTypePosts); numPosts += numTypePosts; query = "select count(*) from PostModel as p where p.poster.gender='f' and " + "p.parent is null and p.emailed=false and p.date>?"; numTypePosts = ((Long) s.createQuery(query).setDate(0, GraphServlet.getStartDate()).list().get(0)) .intValue(); ; ds.setValue("Posts by Females", numTypePosts); numPosts += numTypePosts; query = "select count(*) from PostModel as p where p.poster.gender='f' and p.emailed=true and p.date>?"; numTypePosts = ((Long) s.createQuery(query).setDate(0, GraphServlet.getStartDate()).list().get(0)) .intValue(); ; ds.setValue("Emails by Females", numTypePosts); numPosts += numTypePosts; chart = ChartFactory.createPieChart("Post Type/Author Gender Breakdown (for " + numPosts + " posts)", ds, false, false, false); PiePlot plot = ((PiePlot) chart.getPlot()); StandardPieItemLabelGenerator n = new StandardPieItemLabelGenerator("{0} = {1} ({2})", new DecimalFormat("0"), new DecimalFormat("0.0%")); plot.setLabelGenerator(n); return chart; }
From source file:ca.myewb.frame.servlet.GraphServlet.java
private JFreeChart getPost2Pie(Session s) { JFreeChart chart;/*from ww w. j a v a 2 s. c om*/ DefaultPieDataset ds = new DefaultPieDataset(); int numPosts = 0; int numTypePosts = 0; String query = "select count(*) from PostModel as p where p.group.id=1 and p.date>?"; numTypePosts = ((Long) s.createQuery(query).setDate(0, GraphServlet.getStartDate()).list().get(0)) .intValue(); ds.setValue("Org List", numTypePosts); numPosts += numTypePosts; query = "select count(*) from PostModel as p where p.group.admin=false and p.group.postName not like 'anyone in the%' and " + "p.group.public=true and p.group.parent is null and p.date>?"; numTypePosts = ((Long) s.createQuery(query).setDate(0, GraphServlet.getStartDate()).list().get(0)) .intValue(); ds.setValue("General Public Lists", numTypePosts); numPosts += numTypePosts; query = "select count(*) from PostModel as p where p.group.admin=false and " + "p.group.public=false and p.group.parent is null and p.date>?"; numTypePosts = ((Long) s.createQuery(query).setDate(0, GraphServlet.getStartDate()).list().get(0)) .intValue(); ds.setValue("General Private Lists", numTypePosts); numPosts += numTypePosts; query = "select count(*) from PostModel as p where p.group.admin=true and p.group.visible=true" + " and p.group.id != 1 and p.date>?"; numTypePosts = ((Long) s.createQuery(query).setDate(0, GraphServlet.getStartDate()).list().get(0)) .intValue(); ds.setValue("All-exec Lists", numTypePosts); numPosts += numTypePosts; query = "select count(*) from PostModel as p where p.group.id = 14 and p.date>?"; numTypePosts = ((Long) s.createQuery(query).setDate(0, GraphServlet.getStartDate()).list().get(0)) .intValue(); ds.setValue("Deleted Posts", numTypePosts); numPosts += numTypePosts; query = "select count(*) from PostModel as p where p.group.postName like 'anyone in the%' and p.date>?"; numTypePosts = ((Long) s.createQuery(query).setDate(0, GraphServlet.getStartDate()).list().get(0)) .intValue(); ds.setValue("Chapter Lists", numTypePosts); numPosts += numTypePosts; query = "select count(*) from PostModel as p where p.group.parent!=null and " + "p.group.shortname='exec' and p.date>?"; numTypePosts = ((Long) s.createQuery(query).setDate(0, GraphServlet.getStartDate()).list().get(0)) .intValue(); ds.setValue("Chapter-exec Lists", numTypePosts); numPosts += numTypePosts; query = "select count(*) from PostModel as p where p.group.parent!=null and " + "p.group.shortname!='exec' and p.group.public=true and p.date>?"; numTypePosts = ((Long) s.createQuery(query).setDate(0, GraphServlet.getStartDate()).list().get(0)) .intValue(); ds.setValue("Chapter Public Lists", numTypePosts); numPosts += numTypePosts; query = "select count(*) from PostModel as p where p.group.parent!=null and " + "p.group.shortname!='exec' and p.group.public=false and p.date>?"; numTypePosts = ((Long) s.createQuery(query).setDate(0, GraphServlet.getStartDate()).list().get(0)) .intValue(); ds.setValue("Chapter Private Lists", numTypePosts); numPosts += numTypePosts; chart = ChartFactory.createPieChart("Post Group Breakdown (for " + numPosts + " posts)", ds, false, false, false); PiePlot plot = ((PiePlot) chart.getPlot()); StandardPieItemLabelGenerator n = new StandardPieItemLabelGenerator("{0} = {1} ({2})", new DecimalFormat("0"), new DecimalFormat("0.0%")); plot.setLabelGenerator(n); return chart; }