List of usage examples for org.jfree.data.general DefaultPieDataset getItemCount
@Override public int getItemCount()
From source file:com.pureinfo.srm.reports.impl.PieChartBuilder.java
private void fillChartInfo(DefaultPieDataset _dataset) { int n = _dataset.getItemCount(); m_ChartInfo = new ChartInfo(); m_ChartInfo.setChartTitle(m_sTitle); NumberFormat format = NumberFormat.getNumberInstance(); String[] labels = new String[n]; for (int i = 0; i < n; i++) { labels[i] = "" + _dataset.getKey(i); labels[i] += " = "; labels[i] += format.format(_dataset.getValue(i)); double totalValue = DatasetUtilities.calculatePieDatasetTotal(_dataset); if (totalValue != 0) { labels[i] += " "; labels[i] += PERCENT_NUMBER_FORMAT.format(_dataset.getValue(i).doubleValue() / totalValue); }//from w w w . j a v a 2 s . c om } m_ChartInfo.setLabels(labels); m_ChartInfo.setShowBoder(true); m_ChartInfo.setChartSize(ChartInfo.SIZE_WIDE_AND_THIN); m_ChartInfo.setLengedPosition(ChartInfo.LENGEND_POSITION_BUTTOM); }
From source file:org.jfree.data.general.DefaultPieDatasetTest.java
/** * Some tests for the clear() method./*from ww w . j a v a2s . com*/ */ @Test public void testClear() { DefaultPieDataset d = new DefaultPieDataset(); d.addChangeListener(this); // no event is generated if the dataset is already empty d.clear(); assertNull(this.lastEvent); d.setValue("A", 1.0); assertEquals(1, d.getItemCount()); this.lastEvent = null; d.clear(); assertNotNull(this.lastEvent); assertEquals(0, d.getItemCount()); }
From source file:fr.gouv.diplomatie.applitutoriel.utility.Graphique.java
/** * Creer camember3 d.//from ww w.java2 s. com * * @param title * the title * @param dataset * the dataset * @param legend * the legend * @param tooltips * the tooltips * @param urls * the urls * @return the j free chart * @throws FontFormatException * the font format exception * @throws IOException * Signals that an I/O exception has occurred. */ public static JFreeChart creerCamember3D(final String title, final DefaultPieDataset dataset, final boolean legend, final boolean tooltips, final boolean urls) throws FontFormatException, IOException { dataset.sortByValues(SortOrder.DESCENDING); final JFreeChart jfreeChart = ChartFactory.createPieChart3D(title, dataset, legend, tooltips, urls); jfreeChart.setBackgroundPaint(Color.white); jfreeChart.setBorderVisible(true); jfreeChart.getLegend().setPosition(RectangleEdge.LEFT); final GraphicsEnvironment graph = GraphicsEnvironment.getLocalGraphicsEnvironment(); final InputStream inputStream = Thread.currentThread().getContextClassLoader() .getResourceAsStream("hornet/framework/font/LiberationSans-Bold.ttf"); final Font font = Font.createFont(Font.TRUETYPE_FONT, inputStream); graph.registerFont(font); jfreeChart.getLegend().setItemFont(new Font("Liberation Sans", Font.BOLD, 11)); jfreeChart.getLegend().setHeight(400); jfreeChart.getLegend().setBorder(0, 0, 0, 0); jfreeChart.setTitle(new TextTitle(title, new Font("Liberation Sans", Font.BOLD, 16))); final PiePlot piePlot = (PiePlot) jfreeChart.getPlot(); final int nbData = dataset.getItemCount(); int cptColor = 0; for (int x = 0; x < nbData; x++) { if (cptColor >= listColor.size()) { cptColor = 0; } piePlot.setSectionPaint(dataset.getKey(x), listColor.get(cptColor)); cptColor++; } piePlot.setForegroundAlpha(0.5f); piePlot.setLabelFont(new Font("Liberation Sans", Font.BOLD, 12)); piePlot.setLabelOutlineStroke(null); piePlot.setLabelLinkStroke(new BasicStroke(0.4f)); piePlot.setLabelBackgroundPaint(Color.WHITE); piePlot.setLabelLinkStyle(PieLabelLinkStyle.STANDARD); piePlot.setBackgroundAlpha(0); piePlot.setOutlineVisible(false); piePlot.setForegroundAlpha(1); // transparence piePlot.setInteriorGap(0); // le camembert occupe plus de place piePlot.setLabelGenerator(new StandardPieSectionLabelGenerator("{1}")); piePlot.setStartAngle(70); piePlot.setCircular(true); // force pour avoir un cercle et pas un oval piePlot.setMaximumLabelWidth(0.20); piePlot.setBaseSectionOutlinePaint(Color.BLACK); // bordure du camembert return jfreeChart; }
From source file:com.ikon.servlet.admin.StatsGraphServlet.java
/** * Convert a piechartdata to xml//from ww w . ja v a2 s .com * * @author puspendu.banerjee@gmail.com */ public String repoStatsXML(final String title, final DefaultPieDataset dataset) throws IOException, ServletException { Document document = DocumentHelper.createDocument(); Element root = document.addElement("RepoStats"); root.addElement("Title").addCDATA(title); Element dataSetElement = root.addElement("DataSet"); for (int i = 0; i < dataset.getItemCount(); i++) { Element itemElement = dataSetElement.addElement("Item"); itemElement.addElement("name").addCDATA(dataset.getKey(i).toString()); itemElement.addAttribute("percent", dataset.getValue(i).toString()); dataSetElement.add(itemElement); } return document.asXML(); }
From source file:org.gridchem.client.gui.charts.UsageChart.java
/** * Returns a dataset representing the relative usage of the given * projects against the given collaborator. * /*ww w . j a va 2 s . c om*/ * @param projectCollabTable * @return */ private DefaultPieDataset createProjectDataset( Hashtable<ProjectBean, List<CollaboratorBean>> projectCollabTable, CollaboratorBean collab) { DefaultPieDataset pds = new DefaultPieDataset(); // add project summary info for (ProjectBean project : projectCollabTable.keySet()) { CollaboratorBean collabBean = projectCollabTable.get(project) .get(projectCollabTable.get(project).indexOf(collab)); if (collabBean != null) { pds.setValue(project.getName() + " Used", new Double(collabBean.getTotalUsage().getUsed())); pds.setValue(project.getName() + " Avail.", new Double(collabBean.getTotalUsage().getBalance())); // keep track of the current project so we can explode that piece // of the pie. if (project.equals(GridChem.project)) { defaultProjectIndex = pds.getItemCount() - 1; } } } return pds; }
From source file:dbseer.gui.panel.DBSeerSelectableChartPanel.java
@Override public void chartMouseClicked(ChartMouseEvent chartMouseEvent) { ChartEntity entity = chartMouseEvent.getEntity(); MouseEvent mouseEvent = chartMouseEvent.getTrigger(); if (SwingUtilities.isLeftMouseButton(mouseEvent) && entity != null && entity instanceof PieSectionEntity) { java.util.List<String> names = dataset.getTransactionTypeNames(); PieSectionEntity pieSectionEntity = (PieSectionEntity) entity; int idx = pieSectionEntity.getSectionIndex(); String name = (String) JOptionPane.showInputDialog(null, "Enter the name for this transaction type", "Transaction Type", JOptionPane.PLAIN_MESSAGE, null, null, ""); if (name != null) { if (names.contains(name) && !names.get(idx).equals(name) && !name.isEmpty()) { JOptionPane.showMessageDialog(null, "Please enter a different name for the transaction type.\nEach name has to be unique.", "Warning", JOptionPane.WARNING_MESSAGE); } else { PieDataset oldDataset = pieSectionEntity.getDataset(); DefaultPieDataset newDataset = new DefaultPieDataset(); PiePlot plot = (PiePlot) chart.getPlot(); String oldName = (String) oldDataset.getKey(idx); names.set(idx, name);//from ww w . jav a 2 s . com dataset.setTransactionTypeName(idx, name); for (int i = 0; i < oldDataset.getItemCount(); ++i) { String key = (String) oldDataset.getKey(i); Number number = oldDataset.getValue(i); if (key.equals(oldName)) { if (name.isEmpty()) newDataset.setValue("Transaction Type " + (i + 1), number); else newDataset.setValue(name, number); } else { newDataset.setValue(key, number); } } Paint[] tempPaint = new Paint[oldDataset.getItemCount()]; for (int i = 0; i < oldDataset.getItemCount(); ++i) { String key = (String) oldDataset.getKey(i); tempPaint[i] = plot.getSectionPaint(key); } ((DefaultPieDataset) oldDataset).clear(); plot.setDataset(newDataset); for (int i = 0; i < newDataset.getItemCount(); ++i) { String key = (String) newDataset.getKey(i); plot.setSectionPaint(key, tempPaint[i]); } } } } }
From source file:com.opensourcestrategies.activities.reports.ActivitiesChartsService.java
private String createPieChart(DefaultPieDataset dataset, String title) throws InfrastructureException, IOException { Debug.logInfo("Charting dashboard [" + title + "]", MODULE); // set up the chart JFreeChart chart = ChartFactory.createPieChart(title, dataset, true, // include legend true, // tooltips false // urls );// www .j a va2 s .c om chart.setBackgroundPaint(Color.white); chart.setBorderVisible(true); chart.setPadding(new RectangleInsets(5.0, 5.0, 5.0, 5.0)); // get a reference to the plot for further customization... final PiePlot plot = (PiePlot) chart.getPlot(); plot.setBackgroundPaint(Color.white); plot.setCircular(true); plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0}: {1} / {2}", NumberFormat.getNumberInstance(), NumberFormat.getPercentInstance())); plot.setNoDataMessage("No data available"); Color[] colors = { Color.decode("#" + infrastructure.getConfigurationValue( OpentapsConfigurationTypeConstants.ACTIVITIES_DASHBOARD_LEADS_NEW_COLOR)), Color.decode("#" + infrastructure.getConfigurationValue( OpentapsConfigurationTypeConstants.ACTIVITIES_DASHBOARD_LEADS_OLD_COLOR)), Color.decode("#" + infrastructure.getConfigurationValue( OpentapsConfigurationTypeConstants.ACTIVITIES_DASHBOARD_LEADS_NO_ACTIVITY_COLOR)) }; for (int i = 0; i < dataset.getItemCount(); i++) { Comparable<?> key = dataset.getKey(i); plot.setSectionPaint(key, colors[i]); } // save as a png and return the file name return ServletUtilities.saveChartAsPNG(chart, chartWidth, chartHeight, null); }