"Header", dataset, true, true, false); PiePlot plot = (PiePlot) someChart.getPlot(); plot.setSectionPaint(KEY1, Color.green); plot.setSectionPaint(KEY2, Color.red); plot.setExplodePercent(KEY1, 0.10); plot.setSimpleLabels(true);
PieDataset dataset = ... JFreeChart chart = ChartFactory.createPieChart("My Chart", dataset, false, true, false); // all possible colors for each piece of the pie Color[] colors = new Color[] { new Color(232, 124, 35), new Color(51, 109, 178), new Color(182, 52, 49), new Color(103, 131, 45), new Color(108, 77, 146), new Color(46, 154, 183), new Color(151, 64, 64) }; PiePlot plot = (PiePlot) chart.getPlot(); // set each sections inside paint int i = 0; for (Object key : dataset.getKeys()) { plot.setSectionPaint((Comparable) key, colors[i % colors.length]); i++; }
/** * Sets the paint used to fill a section of the pie and sends a * {@link PlotChangeEvent} to all registered listeners. * * @param section the section index (zero-based). * @param paint the paint (<code>null</code> permitted). * * @deprecated Use {@link #setSectionPaint(Comparable, Paint)} instead. */ public void setSectionPaint(int section, Paint paint) { Comparable key = getSectionKey(section); setSectionPaint(key, paint); }
/** * Sets the color for dataset (ordered on index) * @param plot * @param dataset */ @SuppressWarnings("rawtypes") public void setColor(PiePlot plot, DefaultPieDataset dataset) { @SuppressWarnings("unchecked") List<Comparable> keys = dataset.getKeys(); for (int i = 0; i < keys.size(); i++) { plot.setSectionPaint(keys.get(i), this.color[i]); } } }
static class PieRenderer { private Color[] color; public PieRenderer(Color[] color) { this.color = color; } public void setColor(PiePlot plot, DefaultPieDataset dataset) { List <Comparable> keys = dataset.getKeys(); int aInt; for (int i = 0; i < keys.size(); i++) { aInt = i % this.color.length; plot.setSectionPaint(keys.get(i), this.color[aInt]); } } }
private static void setSectionColor(PieDataset dataset, PiePlot plot, int section, Color outline, Color paint ) { try { Comparable key = dataset.getKey(section); plot.setSectionOutlinePaint(key, outline); plot.setSectionPaint(key, paint); } catch (IndexOutOfBoundsException ie) { // This item hasn't been created, in the dataset so we skip it and don't set its colours // No further action is currently required in this case. } } }
pieplot.setSectionPaint(api, palette.get(i%palette.size())); i++;
for (int s = s1; s <= s2; s++) { Color c = interpolatedColor(c1, c2, s - s1, s2 - s1); plot.setSectionPaint(dataset.getKey(s), c); plot.setSectionPaint(dataset.getKey(i), colors[i]);
plot.setSectionPaint(key, Color.GREEN); plot.setSectionPaint(key, Color.RED); || !greenForIncrease && newValue.doubleValue() < oldValue.doubleValue()) { plot.setSectionPaint(key, new Color(0, (int) shade, 0)); plot.setSectionPaint(key, new Color((int) shade, 0, 0));
plot.setSectionPaint(key, Color.green); plot.setSectionPaint(key, Color.red); || !greenForIncrease && newValue.doubleValue() < oldValue.doubleValue()) { plot.setSectionPaint(key, new Color(0, (int) shade, 0)); plot.setSectionPaint(key, new Color((int) shade, 0, 0));
plot.setSectionPaint(key, Color.GREEN); plot.setSectionPaint(key, Color.RED); || !greenForIncrease && newValue.doubleValue() < oldValue.doubleValue()) { plot.setSectionPaint(key, new Color(0, (int) shade, 0)); plot.setSectionPaint(key, new Color((int) shade, 0, 0));
/** * Handle color customization requested. * - get customization parameters from parameter Map and modify plot accordingly * @param parameters macro parameters * @param plot chart plot * @throws MacroExecutionException */ void handleColorCustomization(Map parameters, Plot plot) throws MacroExecutionException { String colors = (String) parameters.get("colors"); if (colors != null) { String[] color = colors.split(","); for (int i = 0; i < color.length; i++) { if (plot instanceof CategoryPlot) { ((CategoryPlot) plot).getRenderer().setSeriesPaint(i, stringToColor(color[i])); } else if (plot instanceof XYPlot) { ((XYPlot) plot).getRenderer().setSeriesPaint(i, stringToColor(color[i])); } else if (plot instanceof PiePlot) { PiePlot piePlot = (PiePlot)plot; PieDataset pieDataset = piePlot.getDataset(); if (i < pieDataset.getItemCount()) piePlot.setSectionPaint(pieDataset.getKey(i), stringToColor(color[i])); } } } }
p = (Paint) this.sectionPaints.get(key); piePlot.setSectionPaint(key, p);
p = (Paint) this.sectionPaints.get(key); piePlot.setSectionPaint(key, p);
for (int i = 0; i < dataset.getItemCount(); i++) { String key = (String) dataset.getKey(i); plot.setSectionPaint(key, seriesColorsByName.get(key));
plot.setSectionPaint(dataset.getKey(j), ChartDefaults.darkColors[j]); plot.setSectionPaint(j, ChartDefaults.darkColors[j]);
plot.setSectionPaint(dataset.getKey(j), ChartDefaults.darkColors[j]);
((PiePlot) plot).setSectionPaint("A", labelA); ((PiePlot) plot).setSectionPaint("B", labelB); ((PiePlot) plot).setSectionPaint("C", labelC); ((PiePlot) plot).setSectionPaint("D", labelD);
plot.setSectionPaint(getKey(), UIChart.findColor(getSectionPaint()));
private JFreeChart getMultiplePieChart( BaseChart chart, CategoryDataset[] dataSets ) { JFreeChart multiplePieChart = ChartFactory.createMultiplePieChart( chart.getName(), dataSets[0], TableOrder.BY_ROW, !chart.isHideLegend(), false, false ); setBasicConfig( multiplePieChart, chart ); if ( multiplePieChart.getLegend() != null ) { multiplePieChart.getLegend().setItemFont( SUB_TITLE_FONT ); } MultiplePiePlot multiplePiePlot = (MultiplePiePlot) multiplePieChart.getPlot(); JFreeChart pieChart = multiplePiePlot.getPieChart(); pieChart.setBackgroundPaint( DEFAULT_BACKGROUND_COLOR ); pieChart.getTitle().setFont( SUB_TITLE_FONT ); PiePlot piePlot = (PiePlot) pieChart.getPlot(); piePlot.setBackgroundPaint( DEFAULT_BACKGROUND_COLOR ); piePlot.setOutlinePaint( DEFAULT_BACKGROUND_COLOR ); piePlot.setLabelFont( LABEL_FONT ); piePlot.setLabelGenerator( new StandardPieSectionLabelGenerator( "{2}" ) ); piePlot.setSimpleLabels( true ); piePlot.setIgnoreZeroValues( true ); piePlot.setIgnoreNullValues( true ); piePlot.setShadowXOffset( 0d ); piePlot.setShadowYOffset( 0d ); for ( int i = 0; i < dataSets[0].getColumnCount(); i++ ) { piePlot.setSectionPaint( dataSets[0].getColumnKey( i ), COLORS[(i % COLORS.length)] ); } return multiplePieChart; }