List of usage examples for org.jfree.data.general PieDataset getKeys
public List getKeys();
From source file:org.openfaces.component.chart.impl.helpers.ChartInfoUtil.java
public static PieSectorInfo getPieSectorInfo(PieDataset pieDataset, Comparable comparable, int dsIndex) { double total = 0; List keys = pieDataset.getKeys(); for (Object key : keys) { Object value = pieDataset.getValue((Comparable) key); if (value != null) { double dValue = ((Number) value).doubleValue(); if (dValue > 0) total = total + dValue;/*from w w w . j a v a2 s.co m*/ } } int index = pieDataset.getIndex(comparable); Object value = pieDataset.getValue(index); double dValue = 0; if (value != null) { dValue = ((Number) value).doubleValue(); } PieSectorInfo sector = new PieSectorInfoImpl(); sector.setKey(comparable); sector.setValue(value); sector.setSeriesTotal(total); sector.setIndex(index); sector.setSeries(new SeriesInfoImpl()); sector.getSeries().setIndex(dsIndex); double p = (dValue / total); DecimalFormat nf1 = new DecimalFormat("#.00%"); String proportionalPercent = nf1.format(p); sector.setProportionalValue(proportionalPercent); return sector; }
From source file:canreg.client.analysis.Tools.java
public static String getChartData(JFreeChart chart, String separatingCharacter, boolean quotesOn) { String endLine = "\n"; String quotes = ""; if (quotesOn) { quotes = "\""; }/*w w w . jav a2 s . co m*/ StringBuilder stringBuilder = new StringBuilder(); String plotType = chart.getPlot().getPlotType(); // System.out.println("Plot Type: " + plotType); if (plotType.equalsIgnoreCase("Pie Plot")) { PiePlot plot = (PiePlot) chart.getPlot(); PieDataset dataset = plot.getDataset(); Comparable key; for (int i = 0; i < dataset.getKeys().size(); i++) { key = dataset.getKey(i); stringBuilder.append(quotes).append(key).append(quotes).append(separatingCharacter).append(quotes) .append(dataset.getValue(key)).append(quotes).append(endLine); } } else if (plotType.equalsIgnoreCase("Category Plot")) { CategoryPlot plot = (CategoryPlot) chart.getPlot(); CategoryDataset dataset = plot.getDataset(); Comparable rowkey; Comparable columnkey; for (int r = 0; r < dataset.getRowCount(); r++) { rowkey = dataset.getRowKey(r); columnkey = dataset.getColumnKey(r); // this is weird... but it works! stringBuilder.append(quotes).append(columnkey).append(quotes).append(separatingCharacter) .append(quotes).append(dataset.getValue(rowkey, columnkey)).append(quotes).append(endLine); } } return stringBuilder.toString(); }
From source file:org.hxzon.demo.jfreechart.PieDatasetDemo2.java
private static JFreeChart createPieChart(PieDataset dataset, PieDataset previousDataset) { final boolean greenForIncrease = true; final boolean subTitle = true; final boolean showDifference = true; int percentDiffForMaxScale = 20; PiePlot plot = new PiePlot(dataset); plot.setLabelGenerator(new StandardPieSectionLabelGenerator()); plot.setInsets(new RectangleInsets(0.0, 5.0, 5.0, 5.0)); if (tooltips) { plot.setToolTipGenerator(new StandardPieToolTipGenerator()); }/*from w ww . j av a2 s . c o m*/ if (urls) { plot.setURLGenerator(new StandardPieURLGenerator()); } @SuppressWarnings({ "rawtypes", "unchecked" }) List<Comparable> keys = dataset.getKeys(); DefaultPieDataset series = null; if (showDifference) { series = new DefaultPieDataset(); } double colorPerPercent = 255.0 / percentDiffForMaxScale; for (@SuppressWarnings("rawtypes") Comparable key : keys) { Number newValue = dataset.getValue(key); Number oldValue = previousDataset.getValue(key); if (oldValue == null) { if (greenForIncrease) { plot.setSectionPaint(key, Color.green); } else { plot.setSectionPaint(key, Color.red); } if (showDifference) { series.setValue(key + " (+100%)", newValue); } } else { double percentChange = (newValue.doubleValue() / oldValue.doubleValue() - 1.0) * 100.0; double shade = (Math.abs(percentChange) >= percentDiffForMaxScale ? 255 : Math.abs(percentChange) * colorPerPercent); if (greenForIncrease && newValue.doubleValue() > oldValue.doubleValue() || !greenForIncrease && newValue.doubleValue() < oldValue.doubleValue()) { plot.setSectionPaint(key, new Color(0, (int) shade, 0)); } else { plot.setSectionPaint(key, new Color((int) shade, 0, 0)); } if (showDifference) { series.setValue( key + " (" + (percentChange >= 0 ? "+" : "") + NumberFormat.getPercentInstance().format(percentChange / 100.0) + ")", newValue); } } } if (showDifference) { plot.setDataset(series); } JFreeChart chart = new JFreeChart("Pie Chart Demo 2", JFreeChart.DEFAULT_TITLE_FONT, plot, legend); if (subTitle) { TextTitle subtitle = null; subtitle = new TextTitle("Bright " + (greenForIncrease ? "red" : "green") + "=change >=-" + percentDiffForMaxScale + "%, Bright " + (!greenForIncrease ? "red" : "green") + "=change >=+" + percentDiffForMaxScale + "%", new Font("SansSerif", Font.PLAIN, 10)); chart.addSubtitle(subtitle); } plot.setNoDataMessage("No data available"); return chart; }
From source file:com.recomdata.charting.PieRenderer.java
public void setColor(PiePlot plot, PieDataset dataset) { List<Comparable> keys = dataset.getKeys(); int aInt;//from w w w. ja v a 2 s .c om for (int i = 0; i < keys.size(); i++) { aInt = i % this.color.length; plot.setSectionPaint(keys.get(i), this.color[aInt]); } }
From source file:org.pentaho.plugin.jfreereport.reportcharts.FormulaPieTooltipGenerator.java
/** * Generates a tool tip text item for the specified item in the dataset. This method can return <code>null</code> to * indicate that no tool tip should be displayed for an item. * * @param dataset the dataset (<code>null</code> not permitted). * @param key the section key (<code>null</code> not permitted). * @return The tool tip text (possibly <code>null</code>). *///from w ww . j a va 2s .co m public String generateToolTip(PieDataset dataset, Comparable key) { try { final Object[] keys = dataset.getKeys().toArray(); final Object[] items = new Object[keys.length]; for (int i = 0; i < keys.length; i++) { items[i] = dataset.getValue(i); } final Object[] values = new Object[] { key, keys, dataset.getValue(key), items, IntegerCache.getInteger(dataset.getIndex(key)) }; formulaExpression.setRuntime( new WrapperExpressionRuntime(new StaticDataRow(ADDITIONAL_COLUMN_KEYS, values), runtime)); final Object o = formulaExpression.getValue(); if (o == null) { return null; } return String.valueOf(o); } finally { formulaExpression.setRuntime(null); } }
From source file:org.pentaho.plugin.jfreereport.reportcharts.FormulaPieURLGenerator.java
/** * Generates a URL for one item in a {@link org.jfree.data.general.PieDataset}. As a guideline, the URL should be * valid within the context of an XHTML 1.0 document. * * @param dataset the dataset (<code>null</code> not permitted). * @param key the item key (<code>null</code> not permitted). * @param pieIndex the pie index (differentiates between pies in a 'multi' pie chart). * @return A string containing the URL./*from ww w . ja v a 2s . c o m*/ */ public String generateURL(final PieDataset dataset, final Comparable key, final int pieIndex) { try { final Object[] keys = dataset.getKeys().toArray(); final Object[] items = new Object[keys.length]; for (int i = 0; i < keys.length; i++) { items[i] = dataset.getValue(key); } final Object[] values = new Object[] { key, keys, dataset.getValue(key), items, IntegerCache.getInteger(pieIndex) }; formulaExpression.setRuntime( new WrapperExpressionRuntime(new StaticDataRow(ADDITIONAL_COLUMN_KEYS, values), runtime)); final Object o = formulaExpression.getValue(); if (o == null) { return null; } return String.valueOf(o); } finally { formulaExpression.setRuntime(null); } }
From source file:net.sourceforge.processdash.ui.web.reports.PieChart.java
private void configureIndividualColors(PiePlot plot, PieDataset pieData) { int num = 1;//from www . j av a 2 s .c om for (Object key : pieData.getKeys()) { String colorKey = "c" + num; String color = getParameter(colorKey); if (color != null) plot.setSectionPaint((Comparable) key, Color.decode("#" + color)); num++; } }
From source file:net.sourceforge.processdash.ui.web.reports.PieChart.java
private void maybeConfigurePhaseColors(final PiePlot plot, PieDataset pieData) { ProcessUtil procUtil = new ProcessUtil(getDataContext()); new PhaseChartColorer(procUtil, pieData.getKeys()) { public void setItemColor(Object key, int pos, Color c) { plot.setSectionPaint((Comparable) key, c); }/*from ww w . j ava 2 s .c o m*/ }.run(); }
From source file:net.sourceforge.processdash.ui.web.reports.PieChart.java
private void configureConsistentColors(final PiePlot plot, PieDataset pieData) { DefaultDrawingSupplier s = new DefaultDrawingSupplier(); String skip = getParameter("consistentSkip"); if (skip != null) for (int i = Integer.parseInt(skip); i-- > 0;) s.getNextPaint();//from ww w. j a va 2 s . c o m for (Object key : pieData.getKeys()) { Paint paint = s.getNextPaint(); plot.setSectionPaint((Comparable) key, paint); } }
From source file:net.sqs2.omr.result.export.chart.ChartImageWriter.java
private void setSectionPaint(PieDataset dataSet, PiePlot piePlot) { Paint outlinePaint = Color.BLACK; Stroke outlineStroke = new BasicStroke(1.0f); if (this.itemBackgroundImages != null && 0 < this.itemBackgroundImages.length) { int index = 0; for (Object key : dataSet.getKeys()) { int imageIndex = index % this.itemBackgroundImages.length; BufferedImage texture = this.itemBackgroundImages[imageIndex]; Rectangle2D anchor = new Rectangle2D.Double(0, 0, texture.getWidth(), texture.getHeight()); TexturePaint fillPaint = new TexturePaint(texture, anchor); piePlot.setSectionPaint((Comparable<?>) key, fillPaint); piePlot.setSectionOutlinePaint((Comparable<?>) key, outlinePaint); piePlot.setSectionOutlineStroke((Comparable<?>) key, outlineStroke); index++;/*w ww . ja v a 2 s.c om*/ } } piePlot.setOutlineVisible(true); piePlot.setOutlinePaint(outlinePaint); piePlot.setOutlineStroke(outlineStroke); piePlot.setSectionOutlinesVisible(true); piePlot.setBaseSectionOutlinePaint(outlinePaint); piePlot.setBaseSectionOutlineStroke(outlineStroke); }