/** * Creates a sample chart for the given dataset. * * @param dataset * the dataset. * * @return A sample chart. */ private JFreeChart createChartCategory(final CategoryDataset dataset) { final JFreeChart chart = ChartFactory.createMultiplePieChart3D("Multiple Pie Chart Demo 4", dataset, TableOrder.BY_COLUMN, false, true, false); chart.setBackgroundPaint(new Color(216, 255, 216)); final MultiplePiePlot plot = (MultiplePiePlot) chart.getPlot(); final JFreeChart subchart = plot.getPieChart(); // final StandardLegend legend = new StandardLegend(); // legend.setItemFont(new Font("SansSerif", Font.PLAIN, 8)); // legend.setAnchor(Legend.SOUTH); // subchart.setLegend(legend); plot.setLimit(0.10); final PiePlot p = (PiePlot) subchart.getPlot(); // p.setLabelGenerator(new StandardPieItemLabelGenerator("{0}")); p.setLabelFont(new Font("SansSerif", Font.PLAIN, 8)); p.setInteriorGap(0.30); return chart; }
public void updateDefaultCategoryDataset(TwoWayTable table){ DefaultCategoryDataset dataset=new DefaultCategoryDataset(); Iterator<Comparable<?>> rowIter = table.rowValuesIterator(); Iterator<Comparable<?>> colIter = null; Comparable<?> r = null; Comparable<?> c = null; while(rowIter.hasNext()){ r = rowIter.next(); colIter = table.colValuesIterator(); while(colIter.hasNext()){ c = colIter.next(); dataset.addValue(table.getCount(r,c), r.toString(), c.toString()); } } MultiplePiePlot plot = (MultiplePiePlot)chart.getPlot(); plot.setDataset(dataset); }
/** * Fetches the legend items and checks the values. */ public void testGetLegendItems() { DefaultCategoryDataset dataset = new DefaultCategoryDataset(); dataset.addValue(35.0, "S1", "C1"); dataset.addValue(45.0, "S1", "C2"); dataset.addValue(55.0, "S2", "C1"); dataset.addValue(15.0, "S2", "C2"); MultiplePiePlot plot = new MultiplePiePlot(dataset); JFreeChart chart = new JFreeChart(plot); LegendItemCollection legendItems = plot.getLegendItems(); assertEquals(2, legendItems.getItemCount()); LegendItem item1 = legendItems.get(0); assertEquals("S1", item1.getLabel()); assertEquals("S1", item1.getSeriesKey()); assertEquals(0, item1.getSeriesIndex()); assertEquals(dataset, item1.getDataset()); assertEquals(0, item1.getDatasetIndex()); LegendItem item2 = legendItems.get(1); assertEquals("S2", item2.getLabel()); assertEquals("S2", item2.getSeriesKey()); assertEquals(1, item2.getSeriesIndex()); assertEquals(dataset, item2.getDataset()); assertEquals(0, item2.getDatasetIndex()); }
/** * Creates a chart that displays multiple pie plots. The chart object * returned by this method uses a {@link MultiplePiePlot} instance as the * plot. * * @param title the chart title (<code>null</code> permitted). * @param dataset the dataset (<code>null</code> permitted). * @param order the order that the data is extracted (by row or by column) * (<code>null</code> not permitted). * @param legend include a legend? * * @return A chart. */ public static JFreeChart createMultiplePieChart(String title, CategoryDataset dataset, TableOrder order, boolean legend) { if (order == null) { throw new IllegalArgumentException("Null 'order' argument."); } MultiplePiePlot plot = new MultiplePiePlot(dataset); plot.setDataExtractOrder(order); plot.setBackgroundPaint(null); plot.setOutlineStroke(null); PieToolTipGenerator tooltipGenerator = new StandardPieToolTipGenerator(); PiePlot pp = (PiePlot) plot.getPieChart().getPlot(); pp.setToolTipGenerator(tooltipGenerator); JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend); currentTheme.apply(chart); return chart; }
/** * Check that the equals() method distinguishes the required fields. */ public void testEquals() { MultiplePiePlot p1 = new MultiplePiePlot(); MultiplePiePlot p2 = new MultiplePiePlot(); assertTrue(p1.equals(p2)); assertTrue(p2.equals(p1)); p1.setDataExtractOrder(TableOrder.BY_ROW); assertFalse(p1.equals(p2)); p2.setDataExtractOrder(TableOrder.BY_ROW); assertTrue(p1.equals(p2)); p1.setLimit(1.23); assertFalse(p1.equals(p2)); p2.setLimit(1.23); assertTrue(p1.equals(p2)); p1.setAggregatedItemsKey("Aggregated Items"); assertFalse(p1.equals(p2)); p2.setAggregatedItemsKey("Aggregated Items"); assertTrue(p1.equals(p2)); p1.setAggregatedItemsPaint(new GradientPaint(1.0f, 2.0f, Color.red, 3.0f, 4.0f, Color.yellow)); assertFalse(p1.equals(p2)); p2.setAggregatedItemsPaint(new GradientPaint(1.0f, 2.0f, Color.red, 3.0f, 4.0f, Color.yellow)); assertTrue(p1.equals(p2)); p1.setPieChart(ChartFactory.createPieChart("Title", null, true, true, true)); assertFalse(p1.equals(p2)); p2.setPieChart(ChartFactory.createPieChart("Title", null, true, true, true)); assertTrue(p1.equals(p2)); }
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( COLOR_TRANSPARENT ); pieChart.getTitle().setFont( SUB_TITLE_FONT ); PiePlot piePlot = (PiePlot) pieChart.getPlot(); piePlot.setBackgroundPaint( COLOR_TRANSPARENT ); piePlot.setOutlinePaint( COLOR_TRANSPARENT ); 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; }
public PieChartAnimator( int frameCount, int frameDelay, MultiplePiePlot mpplot, Interpolator spinInterpolator, Interpolator alphaInterpolator) { super(frameCount, frameDelay); this.mpplot = mpplot; this.spinInterpolator = spinInterpolator; this.alphaInterpolator = alphaInterpolator; }
/** * Check that the equals() method distinguishes the required fields. */ public void testEquals() { MultiplePiePlot p1 = new MultiplePiePlot(); MultiplePiePlot p2 = new MultiplePiePlot(); assertTrue(p1.equals(p2)); assertTrue(p2.equals(p1)); p1.setDataExtractOrder(TableOrder.BY_ROW); assertFalse(p1.equals(p2)); p2.setDataExtractOrder(TableOrder.BY_ROW); assertTrue(p1.equals(p2)); p1.setLimit(1.23); assertFalse(p1.equals(p2)); p2.setLimit(1.23); assertTrue(p1.equals(p2)); p1.setAggregatedItemsKey("Aggregated Items"); assertFalse(p1.equals(p2)); p2.setAggregatedItemsKey("Aggregated Items"); assertTrue(p1.equals(p2)); p1.setAggregatedItemsPaint(new GradientPaint(1.0f, 2.0f, Color.red, 3.0f, 4.0f, Color.yellow)); assertFalse(p1.equals(p2)); p2.setAggregatedItemsPaint(new GradientPaint(1.0f, 2.0f, Color.red, 3.0f, 4.0f, Color.yellow)); assertTrue(p1.equals(p2)); p1.setPieChart(ChartFactory.createPieChart("Title", null, true)); assertFalse(p1.equals(p2)); p2.setPieChart(ChartFactory.createPieChart("Title", null, true)); assertTrue(p1.equals(p2)); p1.setLegendItemShape(new Rectangle2D.Double(1.0, 2.0, 3.0, 4.0)); assertFalse(p1.equals(p2)); p2.setLegendItemShape(new Rectangle2D.Double(1.0, 2.0, 3.0, 4.0)); assertTrue(p1.equals(p2)); }
/** * Creates a chart that displays multiple pie plots. The chart object * returned by this method uses a {@link MultiplePiePlot} instance as the * plot. * * @param title the chart title (<code>null</code> permitted). * @param dataset the dataset (<code>null</code> permitted). * @param order the order that the data is extracted (by row or by column) * (<code>null</code> not permitted). * @param legend include a legend? * * @return A chart. */ public static JFreeChart createMultiplePieChart3D(String title, CategoryDataset dataset, TableOrder order, boolean legend) { if (order == null) { throw new IllegalArgumentException("Null 'order' argument."); } MultiplePiePlot plot = new MultiplePiePlot(dataset); plot.setDataExtractOrder(order); plot.setBackgroundPaint(null); plot.setOutlineStroke(null); JFreeChart pieChart = new JFreeChart(new PiePlot3D(null)); TextTitle seriesTitle = new TextTitle("Series Title", new Font("Tahoma", Font.BOLD, 12)); seriesTitle.setPosition(RectangleEdge.BOTTOM); pieChart.setTitle(seriesTitle); pieChart.removeLegend(); pieChart.setBackgroundPaint(null); plot.setPieChart(pieChart); PieToolTipGenerator tooltipGenerator = new StandardPieToolTipGenerator(); PiePlot pp = (PiePlot) plot.getPieChart().getPlot(); pp.setToolTipGenerator(tooltipGenerator); JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend); currentTheme.apply(chart); return chart; }
/** * Applies the attributes of this theme to a plot. * * @param plot the plot (<code>null</code>). */ protected void applyToPlot(Plot plot) { ParamChecks.nullNotPermitted(plot, "plot"); if (plot.getDrawingSupplier() != null) { plot.setDrawingSupplier(getDrawingSupplier()); } if (plot.getBackgroundPaint() != null) { plot.setBackgroundPaint(this.plotBackgroundPaint); } plot.setOutlinePaint(this.plotOutlinePaint); // now handle specific plot types (and yes, I know this is some // really ugly code that has to be manually updated any time a new // plot type is added - I should have written something much cooler, // but I didn't and neither did anyone else). if (plot instanceof PiePlot) { applyToPiePlot((PiePlot) plot); } else if (plot instanceof MultiplePiePlot) { applyToMultiplePiePlot((MultiplePiePlot) plot); } else if (plot instanceof CategoryPlot) { applyToCategoryPlot((CategoryPlot) plot); } else if (plot instanceof XYPlot) { applyToXYPlot((XYPlot) plot); } else if (plot instanceof FastScatterPlot) { applyToFastScatterPlot((FastScatterPlot) plot); } else if (plot instanceof MeterPlot) { applyToMeterPlot((MeterPlot) plot); } else if (plot instanceof ThermometerPlot) { applyToThermometerPlot((ThermometerPlot) plot); } else if (plot instanceof SpiderWebPlot) { applyToSpiderWebPlot((SpiderWebPlot) plot); } else if (plot instanceof PolarPlot) { applyToPolarPlot((PolarPlot) plot); } }
/** * Applies the attributes of this theme to a plot. * * @param plot the plot ({@code null}). */ protected void applyToPlot(Plot plot) { Args.nullNotPermitted(plot, "plot"); if (plot.getDrawingSupplier() != null) { plot.setDrawingSupplier(getDrawingSupplier()); } if (plot.getBackgroundPaint() != null) { plot.setBackgroundPaint(this.plotBackgroundPaint); } plot.setOutlinePaint(this.plotOutlinePaint); // now handle specific plot types (and yes, I know this is some // really ugly code that has to be manually updated any time a new // plot type is added - I should have written something much cooler, // but I didn't and neither did anyone else). if (plot instanceof PiePlot) { applyToPiePlot((PiePlot) plot); } else if (plot instanceof MultiplePiePlot) { applyToMultiplePiePlot((MultiplePiePlot) plot); } else if (plot instanceof CategoryPlot) { applyToCategoryPlot((CategoryPlot) plot); } else if (plot instanceof XYPlot) { applyToXYPlot((XYPlot) plot); } else if (plot instanceof FastScatterPlot) { applyToFastScatterPlot((FastScatterPlot) plot); } else if (plot instanceof MeterPlot) { applyToMeterPlot((MeterPlot) plot); } else if (plot instanceof ThermometerPlot) { applyToThermometerPlot((ThermometerPlot) plot); } else if (plot instanceof SpiderWebPlot) { applyToSpiderWebPlot((SpiderWebPlot) plot); } else if (plot instanceof PolarPlot) { applyToPolarPlot((PolarPlot) plot); } }
/** * Applies the attributes of this theme to a plot. * * @param plot the plot (<code>null</code>). */ protected void applyToPlot(Plot plot) { if (plot == null) { throw new IllegalArgumentException("Null 'plot' argument."); } if (plot.getDrawingSupplier() != null) { plot.setDrawingSupplier(getDrawingSupplier()); } if (plot.getBackgroundPaint() != null) { plot.setBackgroundPaint(this.plotBackgroundPaint); } plot.setOutlinePaint(this.plotOutlinePaint); // now handle specific plot types (and yes, I know this is some // really ugly code that has to be manually updated any time a new // plot type is added - I should have written something much cooler, // but I didn't and neither did anyone else). if (plot instanceof PiePlot) { applyToPiePlot((PiePlot) plot); } else if (plot instanceof MultiplePiePlot) { applyToMultiplePiePlot((MultiplePiePlot) plot); } else if (plot instanceof CategoryPlot) { applyToCategoryPlot((CategoryPlot) plot); } else if (plot instanceof XYPlot) { applyToXYPlot((XYPlot) plot); } else if (plot instanceof FastScatterPlot) { applyToFastScatterPlot((FastScatterPlot) plot); } else if (plot instanceof MeterPlot) { applyToMeterPlot((MeterPlot) plot); } else if (plot instanceof ThermometerPlot) { applyToThermometerPlot((ThermometerPlot) plot); } else if (plot instanceof SpiderWebPlot) { applyToSpiderWebPlot((SpiderWebPlot) plot); } else if (plot instanceof PolarPlot) { applyToPolarPlot((PolarPlot) plot); } }
public boolean canAnimate(JFreeChart chart) { if (!(chart.getPlot() instanceof MultiplePiePlot)) { return false; } return true; }
/** * Applies the attributes of this theme to a {@link MultiplePiePlot}. * * @param plot the plot (<code>null</code> not permitted). */ protected void applyToMultiplePiePlot(MultiplePiePlot plot) { apply(plot.getPieChart()); }
/** * Applies the attributes of this theme to a {@link MultiplePiePlot}. * * @param plot the plot ({@code null} not permitted). */ protected void applyToMultiplePiePlot(MultiplePiePlot plot) { apply(plot.getPieChart()); }