List of usage examples for org.jfree.data.general DefaultPieDataset getKeys
@Override
public List getKeys()
From source file:draw.charts.PieRenderer.java
/** * Iterates through the Pie dataset keys and assigns proper colors to their * segments.//from w w w.j av a 2 s.com * * @param plot PiePlot object. * @param dataset DefaultPieDataset that the charts is drawn from. */ public void setColor(PiePlot plot, DefaultPieDataset dataset) { List<Comparable> keys = dataset.getKeys(); int colorIndex; for (int i = 0; i < keys.size(); i++) { colorIndex = i % this.colors.length; plot.setSectionPaint(keys.get(i), this.colors[colorIndex]); } }
From source file:draw.charts.PieRenderer.java
/** * Iterates through the Pie dataset keys and assigns proper colors to their * segments./*from w w w .j av a 2 s .c o m*/ * * @param plot PiePlot3D object. * @param dataset DefaultPieDataset that the charts is drawn from. */ public void setColor(PiePlot3D plot, DefaultPieDataset dataset) { List<Comparable> keys = dataset.getKeys(); int colorIndex; for (int i = 0; i < keys.size(); i++) { colorIndex = i % this.colors.length; plot.setSectionPaint(keys.get(i), this.colors[colorIndex]); } }
From source file:edu.monash.merc.struts2.action.TLSumChartAction.java
@SuppressWarnings("unchecked") private void setColor(PiePlot plot, DefaultPieDataset dataset, Color[] colors) { List<Comparable> keys = dataset.getKeys(); for (int i = 0; i < keys.size(); i++) { plot.setSectionPaint(keys.get(i), colors[i]); }/* w ww . j a v a2s .c o m*/ }
From source file:edu.ku.brc.specify.plugins.ipadexporter.ChartHelper.java
/** * @param plot/*from w w w. j a v a2 s .com*/ * @param dataset */ public void setColors(PiePlot plot, DefaultPieDataset dataset) { if (colors.size() == 0) { for (int i = 0; i < rgbs.length / 3; i++) { int inx = i * 3; colors.add(new Color(rgbs[inx], rgbs[inx + 1], rgbs[inx + 2])); } } List<?> keys = dataset.getKeys(); for (int i = 0; i < keys.size(); i++) { int inx = i % this.colors.size(); plot.setSectionPaint((Comparable<?>) keys.get(i), this.colors.get(inx)); //System.out.println("Setting section paint " + keys.get(i).toString() + " " + // Colors.getColors()[aInt].toString()); } }
From source file:uk.ac.lkl.cram.ui.report.Report.java
private void addLearningTypes() { MainDocumentPart mdp = wordMLPackage.getMainDocumentPart(); mdp.addStyledParagraphOfText("Heading1", "Learning Types"); LearningTypeChartMaker maker = new LearningTypeChartMaker(module); JFreeChart chart = maker.getChartPanel().getChart(); DefaultPieDataset dataset = (DefaultPieDataset) maker.getDataset(); Tbl table = factory.createTbl();/* w w w . j a v a2 s .c om*/ double total = 0f; for (Object key : dataset.getKeys()) { total += (Double) dataset.getValue((Comparable) key); } boolean first = true; for (Object key : dataset.getKeys()) { Tr tableRow = factory.createTr(); Tc tableCell = factory.createTc(); TcPr tcpr = factory.createTcPr(); tableCell.setTcPr(tcpr); VMerge vMerge = factory.createTcPrInnerVMerge(); tcpr.setVMerge(vMerge); if (first) { vMerge.setVal("restart"); /* Specify the height and width of the Pie Chart */ int width = (int) (480f * 0.9f); /* Width of the chart */ int height = (int) (360f * 0.9f); /* Height of the chart */ tableCell.getContent().add(createChart(chart, width, height)); first = false; } else { tableCell.getContent().add(factory.createP()); } tableRow.getContent().add(tableCell); double percent = (Double) dataset.getValue((Comparable) key) / total; addSimpleTableCell(tableRow, key.toString()); addTableCell(tableRow, PERCENT_FORMATTER.format(percent), JcEnumeration.RIGHT, false); table.getContent().add(tableRow); } addBorders(table); mdp.addObject(table); }
From source file:org.sakaiproject.sitestats.impl.chart.ChartServiceImpl.java
private AbstractDataset getPieDataset(Report report) { List<Stat> reportData = report.getReportData(); // fill dataset DefaultPieDataset dataSet = new DefaultPieDataset(); String dataSource = report.getReportDefinition().getReportParams().getHowChartSource(); //int total = 0; double total = 0; for (Stat s : reportData) { Comparable key = getStatValue(s, dataSource); if (key != null) { try { Number existingValue = dataSet.getValue(key); dataSet.setValue(key, getTotalValue(existingValue, s, report)); total += getTotalValue(s, report).doubleValue(); } catch (UnknownKeyException e) { dataSet.setValue(key, getTotalValue(s, report)); total += getTotalValue(s, report).doubleValue(); }/*from w w w . j ava2s. c o m*/ } } // sort dataSet.sortByValues(SortOrder.DESCENDING); // fill in final key values in dataset // show only top values (aggregate remaining in 'others') int maxDisplayedItems = 10; int currItem = 1; Number othersValues = Integer.valueOf(0); List<Comparable> keys = dataSet.getKeys(); for (Comparable key : keys) { Number existingValue = dataSet.getValue(key); if (currItem < maxDisplayedItems) { // re-compute values double percentage = (double) existingValue.doubleValue() * 100 / total; double valuePercentage = Util.round(percentage, (percentage > 0.1) ? 1 : 2); // replace key with updated label StringBuilder keyStr = new StringBuilder(key.toString()); keyStr.append(' '); keyStr.append(valuePercentage); keyStr.append("% ("); if ((double) existingValue.intValue() == existingValue.doubleValue()) keyStr.append(existingValue.intValue()); else keyStr.append(existingValue.doubleValue()); keyStr.append(")"); dataSet.remove(key); dataSet.setValue(keyStr.toString(), existingValue); } else { othersValues = Integer.valueOf(othersValues.intValue() + existingValue.intValue()); dataSet.remove(key); } currItem++; } // compute "Others" value if (othersValues.intValue() > 0) { double percentage = (double) othersValues.doubleValue() * 100 / total; double valuePercentage = Util.round(percentage, (percentage > 0.1) ? 1 : 2); // replace key with updated label StringBuilder keyStr = new StringBuilder(msgs.getString("pie_chart_others")); keyStr.append(' '); keyStr.append(valuePercentage); keyStr.append("% ("); if ((double) othersValues.intValue() == othersValues.doubleValue()) keyStr.append(othersValues.intValue()); else keyStr.append(othersValues.doubleValue()); keyStr.append(")"); dataSet.setValue(keyStr.toString(), othersValues); } return dataSet; }