List of usage examples for org.jfree.data.general PieDataset getItemCount
public int getItemCount();
From source file:org.gaixie.micrite.jfreechart.style.PieStyle.java
/** * ?1 ,? Familiar(30%) // w ww . ja va2 s . c o m * @param chart */ public static void styleOne(JFreeChart chart) { PiePlot plot = (PiePlot) chart.getPlot(); PieDataset pd = plot.getDataset(); PieStyle.setBackground(chart); if (pd != null) { //? plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0} ({2})")); //?? for (int i = 0; i < pd.getItemCount(); i++) { int color = i % colors.length; plot.setSectionPaint(pd.getKey(i), colors[color]); } } else { plot.setNoDataMessage("NO DATA"); } }
From source file:org.talend.dataprofiler.chart.ChartDecorator.java
public static void decorateDuplicatePieChart(JFreeChart chart) { if (chart != null) { Plot plot = chart.getPlot();/*ww w. ja v a2 s . c om*/ if (plot instanceof PiePlot) { decoratePiePlot(chart); // ADD msjian TDQ-8046 2013-10-17: add the color's control for pie chart PieDataset piedataset = ((PiePlot) plot).getDataset(); for (int i = 0; i < piedataset.getItemCount(); i++) { if (i >= DUPLICATE_PIE_COLOR_LIST.size()) { DUPLICATE_PIE_COLOR_LIST.add(generateRandomColor(DUPLICATE_PIE_COLOR_LIST)); } Comparable<?> key = piedataset.getKey(i); ((PiePlot) plot).setSectionPaint(key, DUPLICATE_PIE_COLOR_LIST.get(i)); } // TDQ-8046~ } } }
From source file:org.talend.dataprofiler.chart.ChartDecorator.java
/** * DOC bZhou Comment method "decorate"./*ww w.j a va 2s. c o m*/ * * @param chart */ public static void decorate(JFreeChart chart, PlotOrientation orientation) { if (chart != null) { // TDQ-11522: Set white background on charts in the editors chart.setBackgroundPaint(Color.white); // TDQ-11522~ Plot plot = chart.getPlot(); if (plot instanceof CategoryPlot) { decorateCategoryPlot(chart, orientation); CategoryDataset dataset = chart.getCategoryPlot().getDataset(); int rowCount = dataset != null ? dataset.getRowCount() : 20; for (int i = 0; i < rowCount; i++) { // by zshen bug 14173 add the color in the colorList when chart need more the color than 8. if (i >= COLOR_LIST.size()) { COLOR_LIST.add(generateRandomColor(COLOR_LIST)); } // ~14173 ((CategoryPlot) plot).getRenderer().setSeriesPaint(i, COLOR_LIST.get(i)); } } else if (plot instanceof XYPlot) { decorateXYPlot(chart); int count = chart.getXYPlot().getDataset().getSeriesCount(); for (int i = 0; i < count; i++) { // by zshen bug 14173 add the color in the colorList when chart need the colors more than 8. if (i >= COLOR_LIST.size()) { COLOR_LIST.add(generateRandomColor(COLOR_LIST)); } // ~14173 ((XYPlot) plot).getRenderer().setSeriesPaint(i, COLOR_LIST.get(i)); } } else if (plot instanceof PiePlot) { decoratePiePlot(chart); // ADD msjian TDQ-8046 2013-10-17: add the color's control for pie chart PieDataset piedataset = ((PiePlot) plot).getDataset(); for (int i = 0; i < piedataset.getItemCount(); i++) { if (i >= PIE_COLOR_LIST.size()) { PIE_COLOR_LIST.add(generateRandomColor(PIE_COLOR_LIST)); } Comparable<?> key = piedataset.getKey(i); ((PiePlot) plot).setSectionPaint(key, PIE_COLOR_LIST.get(i)); } // TDQ-8046~ } } }
From source file:net.sf.dynamicreports.test.jasper.chart.ChartSeriesColorsByNameTest.java
@Override public void test() { super.test(); numberOfPagesTest(1);/*from w w w . j av a 2s . co m*/ chartCountTest("summary.chart1", 1); JFreeChart chart = getChart("summary.chart1", 0); CategoryItemRenderer renderer1 = chart.getCategoryPlot().getRenderer(); CategoryDataset dataset1 = chart.getCategoryPlot().getDataset(); for (int i = 0; i < dataset1.getRowCount(); i++) { String key = (String) dataset1.getRowKey(i); Assert.assertNotNull("null series color", colors.get(key)); Assert.assertEquals("series color", colors.get(key), renderer1.getSeriesPaint(i)); } chartCountTest("summary.chart2", 1); chart = getChart("summary.chart2", 0); CategoryItemRenderer renderer2 = chart.getCategoryPlot().getRenderer(); CategoryDataset dataset2 = chart.getCategoryPlot().getDataset(); for (int i = 0; i < dataset2.getRowCount(); i++) { String key = (String) dataset2.getRowKey(i); key = StringUtils.substringAfter(key, GroupedStackedBarRendererCustomizer.GROUP_SERIES_KEY); Assert.assertNotNull("null series color", colors.get(key)); Assert.assertEquals("series color", colors.get(key), renderer2.getSeriesPaint(i)); } for (int i = 0; i < chart.getCategoryPlot().getFixedLegendItems().getItemCount(); i++) { LegendItem legendItem = chart.getCategoryPlot().getFixedLegendItems().get(i); Assert.assertNotNull("null series color", colors.get(legendItem.getLabel())); Assert.assertEquals("series color", colors.get(legendItem.getLabel()), legendItem.getFillPaint()); } chartCountTest("summary.chart3", 1); chart = getChart("summary.chart3", 0); PiePlot plot3 = (PiePlot) chart.getPlot(); PieDataset dataset3 = plot3.getDataset(); for (int i = 0; i < dataset3.getItemCount(); i++) { String key = (String) dataset3.getKey(i); Assert.assertNotNull("null series color", colors.get(key)); Assert.assertEquals("series color", colors.get(key), plot3.getSectionPaint(key)); } chartCountTest("summary.chart4", 1); chart = getChart("summary.chart4", 0); XYItemRenderer renderer4 = chart.getXYPlot().getRenderer(); XYDataset dataset4 = chart.getXYPlot().getDataset(); for (int i = 0; i < dataset4.getSeriesCount(); i++) { String key = (String) dataset4.getSeriesKey(i); Assert.assertNotNull("null series color", colors.get(key)); Assert.assertEquals("series color", colors.get(key), renderer4.getSeriesPaint(i)); } }
From source file:com.intel.stl.ui.main.view.NodeStatesPie.java
protected void fillLengendPanel(JPanel panel, PieDataset dataset, Color[] colors) { panel.removeAll();//from w w w . j av a2 s . co m GridBagConstraints gc = new GridBagConstraints(); gc.fill = GridBagConstraints.BOTH; int size = dataset.getItemCount(); stateLabels = new JLabel[size]; for (int i = 0; i < size; i++) { gc.insets = new Insets(2, 5, 2, 2); gc.weightx = 0; gc.gridwidth = 1; JLabel label = new JLabel(dataset.getKey(i).toString(), Util.generateImageIcon(colors[i], 8, new Insets(1, 1, 1, 1)), JLabel.LEFT); label.setFont(UIConstants.H5_FONT); label.setForeground(UIConstants.INTEL_DARK_GRAY); panel.add(label, gc); gc.gridwidth = GridBagConstraints.REMAINDER; gc.weightx = 0; stateLabels[i] = new JLabel(); stateLabels[i].setForeground(UIConstants.INTEL_DARK_GRAY); stateLabels[i].setFont(UIConstants.H3_FONT); panel.add(stateLabels[i], gc); } }
From source file:com.intel.stl.ui.common.view.ComponentFactory.java
/** * Create a simple pie chart without title, legend, label etc. * //from w w w. ja va 2 s . c o m * @param dataset * the dataset to be renderer * @param colors * an color array specify each item's color. The order of the * array correspond to the item order in dataset * @return a pie chart */ public static JFreeChart createPlainPieChart(PieDataset dataset, Color[] colors) { if (dataset == null) { throw new IllegalArgumentException("No dataset."); } if (colors != null && colors.length != dataset.getItemCount()) { throw new IllegalArgumentException("Data have " + dataset.getItemCount() + " values, while we have " + colors.length + " colors for them."); } JFreeChart jfreechart = ChartFactory.createPieChart(null, dataset, false, true, false); PiePlot pieplot = (PiePlot) jfreechart.getPlot(); if (colors != null) { for (int i = 0; i < colors.length; i++) { pieplot.setSectionPaint(dataset.getKey(i), colors[i]); } } pieplot.setBackgroundPaint(null); pieplot.setOutlineStroke(null); pieplot.setLabelGenerator(null); pieplot.setNoDataMessage(UILabels.STL40001_ERROR_No_DATA.getDescription()); pieplot.setCircular(true); pieplot.setInteriorGap(0.000001); return jfreechart; }
From source file:org.jfree.data.category.CategoryToPieDataset.java
/** * Tests this dataset for equality with an arbitrary object, returning * <code>true</code> if <code>obj</code> is a dataset containing the same * keys and values in the same order as this dataset. * * @param obj the object to test (<code>null</code> permitted). * * @return A boolean.//from w w w.j a v a 2 s.c o m */ @Override public boolean equals(Object obj) { if (obj == this) { return true; } if (!(obj instanceof PieDataset)) { return false; } PieDataset that = (PieDataset) obj; int count = getItemCount(); if (that.getItemCount() != count) { return false; } for (int i = 0; i < count; i++) { Comparable k1 = getKey(i); Comparable k2 = that.getKey(i); if (!k1.equals(k2)) { return false; } Number v1 = getValue(i); Number v2 = that.getValue(i); if (v1 == null) { if (v2 != null) { return false; } } else { if (!v1.equals(v2)) { return false; } } } return true; }
From source file:org.jfree.data.general.DefaultPieDataset.java
/** * Tests if this object is equal to another. * * @param obj the other object./* ww w . j a va 2s .co m*/ * * @return A boolean. */ @Override public boolean equals(Object obj) { if (obj == this) { return true; } if (!(obj instanceof PieDataset)) { return false; } PieDataset that = (PieDataset) obj; int count = getItemCount(); if (that.getItemCount() != count) { return false; } for (int i = 0; i < count; i++) { Comparable k1 = getKey(i); Comparable k2 = that.getKey(i); if (!k1.equals(k2)) { return false; } Number v1 = getValue(i); Number v2 = that.getValue(i); if (v1 == null) { if (v2 != null) { return false; } } else { if (!v1.equals(v2)) { return false; } } } return true; }
From source file:org.jfree.chart.demo.selection.SelectionDemo6Pie.java
private static JFreeChart createChart(final PieDataset dataset, DatasetSelectionExtension<PieCursor<String>> ext) { JFreeChart chart = ChartFactory.createPieChart("Pie Chart Demo 2", dataset); final PiePlot plot = (PiePlot) chart.getPlot(); plot.setSectionPaint("One", new Color(160, 160, 255)); plot.setSectionPaint("Two", new Color(128, 128, 255 - 32)); plot.setSectionPaint("Three", new Color(96, 96, 255 - 64)); plot.setSectionPaint("Four", new Color(64, 64, 255 - 96)); plot.setSectionPaint("Five", new Color(32, 32, 255 - 128)); plot.setSectionPaint("Six", new Color(0, 0, 255 - 144)); plot.setNoDataMessage("No data available"); plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0} ({2} percent)")); plot.setLabelBackgroundPaint(new Color(220, 220, 220)); plot.setLegendLabelToolTipGenerator(new StandardPieSectionLabelGenerator("Tooltip for legend item {0}")); plot.setSimpleLabels(true);//from w w w . j a va2 s .co m plot.setInteriorGap(0.1); //pie plots done use abstract renderers need to react to selection on our own final PieCursor<String> cursor = new PieCursor<String>(); ext.addChangeListener(new SelectionChangeListener<PieCursor<String>>() { public void selectionChanged(SelectionChangeEvent<PieCursor<String>> event) { for (int i = 0; i < dataset.getItemCount(); i++) { cursor.setPosition((String) dataset.getKey(i)); if (event.getSelectionExtension().isSelected(cursor)) { plot.setExplodePercent(cursor.key, 0.15); } else { plot.setExplodePercent(cursor.key, 0.0); } } } }); return chart; }
From source file:org.jfree.expdemo.SelectionDemo6Pie.java
private static JFreeChart createChart(final PieDataset dataset, DatasetSelectionExtension ext) { JFreeChart chart = ChartFactory.createPieChart("Pie Chart Demo 2", // chart title dataset, // dataset true, // include legend true, false);/*from w ww .j a v a 2s. c o m*/ final PiePlot plot = (PiePlot) chart.getPlot(); plot.setSectionPaint("One", new Color(160, 160, 255)); plot.setSectionPaint("Two", new Color(128, 128, 255 - 32)); plot.setSectionPaint("Three", new Color(96, 96, 255 - 64)); plot.setSectionPaint("Four", new Color(64, 64, 255 - 96)); plot.setSectionPaint("Five", new Color(32, 32, 255 - 128)); plot.setSectionPaint("Six", new Color(0, 0, 255 - 144)); plot.setNoDataMessage("No data available"); plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0} ({2} percent)")); plot.setLabelBackgroundPaint(new Color(220, 220, 220)); plot.setLegendLabelToolTipGenerator(new StandardPieSectionLabelGenerator("Tooltip for legend item {0}")); plot.setSimpleLabels(true); plot.setInteriorGap(0.1); //pie plots done use abstract renderers need to react to selection on our own final PieCursor cursor = new PieCursor(); ext.addSelectionChangeListener(new SelectionChangeListener() { public void selectionChanged(SelectionChangeEvent event) { for (int i = 0; i < dataset.getItemCount(); i++) { cursor.setPosition(dataset.getKey(i)); if (event.getSelectionExtension().isSelected(cursor)) { plot.setExplodePercent(cursor.key, 0.15); } else { plot.setExplodePercent(cursor.key, 0.0); } } } }); return chart; }