List of usage examples for org.jfree.chart ChartFactory createPieChart3D
public static JFreeChart createPieChart3D(String title, PieDataset dataset, boolean legend, boolean tooltips, boolean urls)
From source file:statisticslabro.StatisticsLabr.java
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed List<String> Temp = new ArrayList<String>(); List<String> check = new ArrayList<String>(); List<Double> fnl = new ArrayList<>(); List<String> frame = new ArrayList<String>(); List<String> name = new ArrayList<String>(); List<String> name2 = new ArrayList<String>(); List<Double> frame2 = new ArrayList<Double>(); List<Double> limitLeft = new ArrayList<>(); List<Double> limitRight = new ArrayList<>(); List<Double> trueLimitLeft = new ArrayList<>(); List<Double> trueLimitRight = new ArrayList<>(); List<Double> midpoint = new ArrayList<>(); List<Integer> frequency = new ArrayList<>(); List<Double> percent = new ArrayList<>(); List<Integer> cf = new ArrayList<>(); List<Double> cp = new ArrayList<>(); Integer freq = 0;/* www .j a v a2 s. c o m*/ Double freqtot = 0.0; if (Categorical.isSelected() == true && Numerical.isSelected() == false) { for (int i = 0; i < jTable1.getRowCount(); i++) { frame.add((String) jTable1.getModel().getValueAt(i, 0)); } Collections.sort(frame); Integer size = frame.size(); System.out.println(size); for (Object b : frame) { String c = b + ""; Temp.add(c); } for (int i = 0; i < jTable1.getRowCount(); i++) { for (int j = 0; j < jTable1.getColumnCount(); j++) { jTable1.setValueAt("", i, j); } } int ct = 0; for (Object z : frame) { String a = z + ""; System.out.print(check.contains(a)); if (!(check.contains(a))) { for (int i = 0; i < Temp.size(); i++) { if (a.equals(Temp.get(i))) { freq++; } } Double freque = (((freq + .0) / size) * 100); fnl.add(freque); name.add(a); freqtot += freque; jTable1.getModel().setValueAt(a, ct, 0); jTable1.getModel().setValueAt(String.format("%1.1f", freque) + "%", ct, 1); ct++; freq = 0; check.add(a); } total.setText("Total :" + String.format("%1.1f", freqtot)); } if (Chart.isSelected() == true) { DefaultPieDataset chart = new DefaultPieDataset(); int h = 0; for (Double z : fnl) { chart.setValue(name.get(h) + "", new Double(z)); h++; } JFreeChart mychart = ChartFactory.createPieChart3D(Desc.getText() + "", chart, true, true, true); PiePlot3D p = (PiePlot3D) mychart.getPlot(); ChartFrame charteuFrame = new ChartFrame(Desc.getText(), mychart); charteuFrame.setVisible(true); charteuFrame.setSize(450, 500); } } else if (Numerical.isSelected() == true && Categorical.isSelected() == false) { double subtrahend = 0.5; for (int i = 0; i < jTable1.getRowCount();) { double d = Double.parseDouble((String) jTable1.getModel().getValueAt(i, 0)); frame2.add(d); i++; } double max = 0; double min = frame2.get(0); for (int j = 0; j < frame2.size(); j++) { System.out.print("Sulod"); if (max < frame2.get(j)) { max = frame2.get(j); } if (min > frame2.get(j)) { min = frame2.get(j); } } System.out.print(frame2); double range = max - min; double k = Math.ceil(1 + 3.322 * Math.log10(frame2.size())); int width = (int) Math.ceil(range / k); System.out.println("char: " + max + " " + min + " " + range + " " + k + " width: " + width); double limit = min; while (limit < max) { limitLeft.add(limit); limit += width; } for (int j = 0; j < limitLeft.size(); j++) { System.out.print(limitLeft.get(j) + " "); } double limit2 = min + width - 1; while (limit2 <= max) { limitRight.add(limit2); limit2 += width; } if (limitRight.get(limitRight.size() - 1) != max) { limitRight.add(max); } System.out.println(); for (int j = 0; j < limitRight.size(); j++) { System.out.print(limitRight.get(j) + " "); } //true limit if (((String) choice.getSelectedItem()).equals("Integer")) { for (int j = 0; j < limitLeft.size(); j++) { trueLimitLeft.add(limitLeft.get(j) - 0.5); } System.out.println(); for (int j = 0; j < trueLimitLeft.size(); j++) { System.out.print(trueLimitLeft.get(j) + " "); } for (int j = 0; j < limitRight.size(); j++) { trueLimitRight.add(limitRight.get(j) + 0.5); } System.out.println(); for (int j = 0; j < trueLimitRight.size(); j++) { System.out.print(trueLimitRight.get(j) + " "); } } else if (((String) choice.getSelectedItem()).equals("Floating")) { int count1 = 0; float diff = 0; boolean flag = false; for (int j = 0; j < frame2.size(); j++) { double value = Math.floor(frame2.get(j)); System.out.println(frame.get(j)); diff = (float) (frame2.get(j) - value); System.out.println("diff: " + diff); String counts = String.valueOf(diff); if (diff > 0.0) { if (counts.length() - 1 > count1) { count1 = counts.length() - 1; System.out.println(count1); } } } System.out.println(count1); for (int j = 0; j < count1 - 1; j++) { subtrahend /= 10; System.out.println(subtrahend); } System.out.println("sub: " + subtrahend); for (int j = 0; j < limitLeft.size(); j++) { trueLimitLeft.add(limitLeft.get(j) - subtrahend); } for (int j = 0; j < limitRight.size(); j++) { trueLimitRight.add(limitRight.get(j) + subtrahend); } } //midpoint for (int j = 0; j < limitLeft.size(); j++) { midpoint.add((limitLeft.get(j) + limitRight.get(j)) / 2); } System.out.println(); for (int j = 0; j < midpoint.size(); j++) { System.out.print(midpoint.get(j) + " "); } //frequency for (int j = 0; j < limitLeft.size(); j++) { int count = 0; for (int m = 0; m < frame2.size(); m++) { if (frame2.get(m) >= limitLeft.get(j) && frame2.get(m) <= limitRight.get(j)) { count++; } } frequency.add(count); } System.out.println(); for (int j = 0; j < frequency.size(); j++) { System.out.print(frequency.get(j) + " "); } //percent for (int j = 0; j < frequency.size(); j++) { double pp = (((double) frequency.get(j) / frame2.size()) * 100); percent.add(pp); } System.out.println(); for (int j = 0; j < percent.size(); j++) { System.out.print(percent.get(j) + " "); } int cff = 0; for (int j = 0; j < frequency.size(); j++) { cff += frequency.get(j); cf.add(cff); } System.out.println(); for (int j = 0; j < cf.size(); j++) { System.out.print(cf.get(j) + " "); } double cpp = 0; for (int j = 0; j < percent.size(); j++) { cpp += percent.get(j); cp.add(cpp); } System.out.println(); for (int j = 0; j < cp.size(); j++) { System.out.print(cp.get(j) + " "); } DefaultTableModel dtm = (DefaultTableModel) jTable1.getModel(); dtm.setRowCount(limitLeft.size()); int ct = 0; if (collapse.isSelected() == true) { for (int j = 0; j < limitLeft.size(); j++) { if (ct == 0) { jTable1.getModel().setValueAt("< " + limitRight.get(j), ct, 1); jTable1.getModel().setValueAt("-", ct, 3); name.add("<"); } else if (ct == limitLeft.size() - 1) { jTable1.getModel().setValueAt("> " + limitLeft.get(j), ct, 1); jTable1.getModel().setValueAt("-", ct, 3); name.add(">"); } else { jTable1.getModel().setValueAt(limitLeft.get(j) + "-" + limitRight.get(j), ct, 1); jTable1.getModel().setValueAt(midpoint.get(j), ct, 3); name.add(midpoint.get(j) + ""); } jTable1.getModel().setValueAt(trueLimitLeft.get(j) + "-" + trueLimitRight.get(j), ct, 2); jTable1.getModel().setValueAt(frequency.get(j), ct, 4); jTable1.getModel().setValueAt(percent.get(j), ct, 5); jTable1.getModel().setValueAt(cf.get(j), ct, 6); jTable1.getModel().setValueAt(cp.get(j), ct, 7); ct++; } } else { for (int j = 0; j < limitLeft.size(); j++) { jTable1.getModel().setValueAt(limitLeft.get(j) + "-" + limitRight.get(j), ct, 1); jTable1.getModel().setValueAt(trueLimitLeft.get(j) + "-" + trueLimitRight.get(j), ct, 2); jTable1.getModel().setValueAt(midpoint.get(j), ct, 3); name.add(midpoint.get(j) + ""); jTable1.getModel().setValueAt(frequency.get(j), ct, 4); jTable1.getModel().setValueAt(percent.get(j), ct, 5); jTable1.getModel().setValueAt(cf.get(j), ct, 6); jTable1.getModel().setValueAt(cp.get(j), ct, 7); ct++; } } } if (Chart.isSelected() == true) { DefaultCategoryDataset chart = new DefaultCategoryDataset(); int h = 0; for (Integer z : frequency) { chart.setValue(z, "Frequency", name.get(h)); h++; } JFreeChart mychart = ChartFactory.createBarChart(Desc.getText() + "", "Midpoint", "Frequency", chart, PlotOrientation.VERTICAL, true, false, false); CategoryPlot p = (CategoryPlot) mychart.getPlot(); p.setDomainGridlinesVisible(true); p.getDomainAxis().setCategoryMargin(0.0); ChartFrame charteuFrame = new ChartFrame(Desc.getText(), mychart); charteuFrame.setVisible(true); charteuFrame.setSize(450, 500); } }
From source file:statisticsintegration.StatisticsLabr.java
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed List<String> Temp = new ArrayList<String>(); List<String> check = new ArrayList<String>(); List<Double> fnl = new ArrayList<>(); List<String> frame = new ArrayList<String>(); List<String> name = new ArrayList<String>(); List<String> name2 = new ArrayList<String>(); List<Double> frame2 = new ArrayList<Double>(); List<Double> limitLeft = new ArrayList<>(); List<Double> limitRight = new ArrayList<>(); List<Double> trueLimitLeft = new ArrayList<>(); List<Double> trueLimitRight = new ArrayList<>(); List<Double> midpoint = new ArrayList<>(); List<Integer> frequency = new ArrayList<>(); List<Double> percent = new ArrayList<>(); List<Integer> cf = new ArrayList<>(); List<Double> cp = new ArrayList<>(); Integer freq = 0;/*from w ww. j a va2s. c o m*/ Double freqtot = 0.0; if (Categorical.isSelected() == true && Numerical.isSelected() == false) { for (int i = 0; i < jTable1.getRowCount(); i++) { frame.add((String) jTable1.getModel().getValueAt(i, 0)); } Collections.sort(frame); Integer size = frame.size(); System.out.println(size); for (Object b : frame) { String c = b + ""; Temp.add(c); } for (int i = 0; i < jTable1.getRowCount(); i++) { for (int j = 0; j < jTable1.getColumnCount(); j++) { jTable1.setValueAt("", i, j); } } int ct = 0; for (Object z : frame) { String a = z + ""; System.out.print(check.contains(a)); if (!(check.contains(a))) { for (int i = 0; i < Temp.size(); i++) { if (a.equals(Temp.get(i))) { freq++; } } Double freque = (((freq + .0) / size) * 100); fnl.add(freque); name.add(a); freqtot += freque; jTable1.getModel().setValueAt(a, ct, 0); jTable1.getModel().setValueAt(String.format("%1.1f", freque) + "%", ct, 1); ct++; freq = 0; check.add(a); } total.setText("Total :" + String.format("%1.1f", freqtot)); } if (Chart.isSelected() == true) { DefaultPieDataset chart = new DefaultPieDataset(); int h = 0; for (Double z : fnl) { chart.setValue(name.get(h) + "", new Double(z)); h++; } JFreeChart mychart = ChartFactory.createPieChart3D(Desc.getText() + "", chart, true, true, true); PiePlot3D p = (PiePlot3D) mychart.getPlot(); ChartFrame charteuFrame = new ChartFrame(Desc.getText(), mychart); charteuFrame.setVisible(true); charteuFrame.setSize(450, 500); } } else if (Numerical.isSelected() == true && Categorical.isSelected() == false) { double subtrahend = 0.5; for (int i = 0; i < jTable1.getRowCount();) { double d = Double.parseDouble((String) jTable1.getModel().getValueAt(i, 0)); frame2.add(d); i++; } double max = 0; double min = frame2.get(0); for (int j = 0; j < frame2.size(); j++) { System.out.print("Sulod"); if (max < frame2.get(j)) { max = frame2.get(j); } if (min > frame2.get(j)) { min = frame2.get(j); } } System.out.print(frame2); double range = max - min; double k = Math.ceil(1 + 3.322 * Math.log10(frame2.size())); int width = (int) Math.ceil(range / k); System.out.println("char: " + max + " " + min + " " + range + " " + k + " width: " + width); double limit = min; while (limit < max) { limitLeft.add(limit); limit += width; } for (int j = 0; j < limitLeft.size(); j++) { System.out.print(limitLeft.get(j) + " "); } double limit2 = min + width - 1; while (limit2 <= max) { limitRight.add(limit2); limit2 += width; } if (limitRight.get(limitRight.size() - 1) != max) { limitRight.add(max); } System.out.println(); for (int j = 0; j < limitRight.size(); j++) { System.out.print(limitRight.get(j) + " "); } //true limit if (((String) choice.getSelectedItem()).equals("Integer")) { for (int j = 0; j < limitLeft.size(); j++) { trueLimitLeft.add(limitLeft.get(j) - 0.5); } System.out.println(); for (int j = 0; j < trueLimitLeft.size(); j++) { System.out.print(trueLimitLeft.get(j) + " "); } for (int j = 0; j < limitRight.size(); j++) { trueLimitRight.add(limitRight.get(j) + 0.5); } System.out.println(); for (int j = 0; j < trueLimitRight.size(); j++) { System.out.print(trueLimitRight.get(j) + " "); } } else if (((String) choice.getSelectedItem()).equals("Floating")) { int count1 = 0; float diff = 0; boolean flag = false; for (int j = 0; j < frame2.size(); j++) { double value = Math.floor(frame2.get(j)); // System.out.println(frame.get(j)); diff = (float) (frame2.get(j) - value); System.out.println("diff: " + diff); String counts = String.valueOf(diff); if (diff > 0.0) { if (counts.length() - 1 > count1) { count1 = counts.length() - 1; System.out.println(count1); } } } System.out.println(count1); for (int j = 0; j < count1 - 1; j++) { subtrahend /= 10; System.out.println(subtrahend); } System.out.println("sub: " + subtrahend); for (int j = 0; j < limitLeft.size(); j++) { trueLimitLeft.add(limitLeft.get(j) - subtrahend); } for (int j = 0; j < limitRight.size(); j++) { trueLimitRight.add(limitRight.get(j) + subtrahend); } } //midpoint for (int j = 0; j < limitLeft.size(); j++) { midpoint.add((limitLeft.get(j) + limitRight.get(j)) / 2); } System.out.println(); for (int j = 0; j < midpoint.size(); j++) { System.out.print(midpoint.get(j) + " "); } //frequency for (int j = 0; j < limitLeft.size(); j++) { int count = 0; for (int m = 0; m < frame2.size(); m++) { if (frame2.get(m) >= limitLeft.get(j) && frame2.get(m) <= limitRight.get(j)) { count++; } } frequency.add(count); } System.out.println(); for (int j = 0; j < frequency.size(); j++) { System.out.print(frequency.get(j) + " "); } //percent for (int j = 0; j < frequency.size(); j++) { double pp = (((double) frequency.get(j) / frame2.size()) * 100); percent.add(pp); } System.out.println(); for (int j = 0; j < percent.size(); j++) { System.out.print(percent.get(j) + " "); } int cff = 0; for (int j = 0; j < frequency.size(); j++) { cff += frequency.get(j); cf.add(cff); } System.out.println(); for (int j = 0; j < cf.size(); j++) { System.out.print(cf.get(j) + " "); } double cpp = 0; for (int j = 0; j < percent.size(); j++) { cpp += percent.get(j); cp.add(cpp); } System.out.println(); for (int j = 0; j < cp.size(); j++) { System.out.print(cp.get(j) + " "); } DefaultTableModel dtm = (DefaultTableModel) jTable1.getModel(); dtm.setRowCount(limitLeft.size()); int ct = 0; if (collapse.isSelected() == true) { for (int j = 0; j < limitLeft.size(); j++) { if (ct == 0) { jTable1.getModel().setValueAt("< " + limitRight.get(j), ct, 1); jTable1.getModel().setValueAt("-", ct, 3); name.add("<"); } else if (ct == limitLeft.size() - 1) { jTable1.getModel().setValueAt("> " + limitLeft.get(j), ct, 1); jTable1.getModel().setValueAt("-", ct, 3); name.add(">"); } else { jTable1.getModel().setValueAt(limitLeft.get(j) + "-" + limitRight.get(j), ct, 1); jTable1.getModel().setValueAt(midpoint.get(j), ct, 3); name.add(midpoint.get(j) + ""); } jTable1.getModel().setValueAt(trueLimitLeft.get(j) + "-" + trueLimitRight.get(j), ct, 2); jTable1.getModel().setValueAt(frequency.get(j), ct, 4); jTable1.getModel().setValueAt(percent.get(j), ct, 5); jTable1.getModel().setValueAt(cf.get(j), ct, 6); jTable1.getModel().setValueAt(cp.get(j), ct, 7); ct++; } } else { for (int j = 0; j < limitLeft.size(); j++) { jTable1.getModel().setValueAt(limitLeft.get(j) + "-" + limitRight.get(j), ct, 1); jTable1.getModel().setValueAt(trueLimitLeft.get(j) + "-" + trueLimitRight.get(j), ct, 2); jTable1.getModel().setValueAt(midpoint.get(j), ct, 3); name.add(midpoint.get(j) + ""); jTable1.getModel().setValueAt(frequency.get(j), ct, 4); jTable1.getModel().setValueAt(percent.get(j), ct, 5); jTable1.getModel().setValueAt(cf.get(j), ct, 6); jTable1.getModel().setValueAt(cp.get(j), ct, 7); ct++; } } if (Chart.isSelected() == true) { DefaultCategoryDataset chart = new DefaultCategoryDataset(); int h = 0; for (Integer z : frequency) { chart.setValue(z, "Frequency", name.get(h)); h++; } JFreeChart mychart = ChartFactory.createBarChart(Desc.getText() + "", "Midpoint", "Frequency", chart, PlotOrientation.VERTICAL, true, false, false); CategoryPlot p = (CategoryPlot) mychart.getPlot(); p.setDomainGridlinesVisible(true); p.getDomainAxis().setCategoryMargin(0.0); ChartFrame charteuFrame = new ChartFrame(Desc.getText(), mychart); charteuFrame.setVisible(true); charteuFrame.setSize(450, 500); } } }
From source file:net.sf.eclipsecs.ui.stats.views.GraphStatsView.java
/** * Cre le graphe JFreeChart./*from w w w . j a va 2 s .c o m*/ * * @param piedataset * : la source de donnes afficher * @return le diagramme */ private JFreeChart createChart(GraphPieDataset piedataset) { JFreeChart jfreechart = ChartFactory.createPieChart3D(null, piedataset, false, true, false); jfreechart.setAntiAlias(true); jfreechart.setTextAntiAlias(true); PiePlot pieplot3d = (PiePlot) jfreechart.getPlot(); pieplot3d.setInsets(new RectangleInsets(0, 0, 0, 0)); final double angle = 290D; pieplot3d.setStartAngle(angle); pieplot3d.setDirection(Rotation.CLOCKWISE); final float foreground = 0.5F; pieplot3d.setForegroundAlpha(foreground); pieplot3d.setNoDataMessage(Messages.GraphStatsView_noDataToDisplay); pieplot3d.setCircular(true); pieplot3d.setOutlinePaint(null); pieplot3d.setLabelFont(new Font("SansSerif", Font.PLAIN, 10)); pieplot3d.setLabelGap(0.02); pieplot3d.setLabelOutlinePaint(null); pieplot3d.setLabelShadowPaint(null); pieplot3d.setLabelBackgroundPaint(Color.WHITE); pieplot3d.setBackgroundPaint(Color.WHITE); pieplot3d.setInteriorGap(0.02); pieplot3d.setMaximumLabelWidth(0.20); return jfreechart; }
From source file:org.jivesoftware.openfire.reporting.graph.GraphEngine.java
/** * Creates a Pie Chart based on map./*from www.j a v a 2 s .c om*/ * * @return the Pie Chart generated. */ public JFreeChart getPieChart(Map<String, Double> pieValues) { DefaultPieDataset dataset = new DefaultPieDataset(); for (String key : pieValues.keySet()) { dataset.setValue(key, pieValues.get(key)); } JFreeChart chart = ChartFactory.createPieChart3D(null, // chart title dataset, // data true, // include legend true, false); chart.setBackgroundPaint(Color.white); chart.setBorderVisible(false); chart.setBorderPaint(null); PiePlot plot = (PiePlot) chart.getPlot(); plot.setSectionOutlinesVisible(false); plot.setLabelFont(new Font("SansSerif", Font.BOLD, 12)); plot.setNoDataMessage("No data available"); plot.setCircular(true); plot.setLabelGap(0.02); plot.setOutlinePaint(null); plot.setLabelLinksVisible(false); plot.setLabelGenerator(null); plot.setLegendLabelGenerator(new StandardPieSectionLabelGenerator("{0}")); plot.setStartAngle(270); plot.setDirection(Rotation.ANTICLOCKWISE); plot.setForegroundAlpha(0.60f); plot.setInteriorGap(0.33); return chart; }
From source file:org.bhavaya.ui.view.ChartView.java
private JFreeChart createPieChart() { JFreeChart chart;/*from www . j av a 2 s . c o m*/ if (isPlot3D()) { chart = ChartFactory.createPieChart3D(getName(), DatasetUtilities.createPieDatasetForRow(tableModelDataSet, 0), true, true, false); chart.getPlot().setForegroundAlpha(0.5f); } else { chart = ChartFactory.createPieChart(getName(), DatasetUtilities.createPieDatasetForRow(tableModelDataSet, 0), true, true, false); } return chart; }
From source file:GUI.VentanaPrincipal.java
void GraficaPastel() { JFreeChart chart = null;// ww w . j a v a 2s . c om //grafico de pastel //addtablespaceInfoToTable(); DefaultPieDataset data = new DefaultPieDataset(); data.setValue("Categora 1", 20); data.setValue("Categora 2", 60); data.setValue("Categora 3", 20); chart = ChartFactory.createPieChart3D("Grfico de Pastel", data, true, true, true); pastel.setVisible(true); Capas.setLayer(pastel, 0, 0); ChartPanel panel; panel = new ChartPanel(chart); panel.setBounds(5, 10, 410, 400); pastel.add(panel); pastel.repaint(); }
From source file:lucee.runtime.tag.Chart.java
private void chartPie() throws PageException, IOException { // do dataset DefaultPieDataset dataset = new DefaultPieDataset(); ChartSeriesBean csb = _series.get(0); ChartDataBean cdb;//from w w w .ja v a 2 s .c o m List datas = csb.getDatas(); if (sortxaxis) Collections.sort(datas); Iterator itt = datas.iterator(); while (itt.hasNext()) { cdb = (ChartDataBean) itt.next(); dataset.setValue(cdb.getItemAsString(), cdb.getValue()); } JFreeChart chart = show3d ? ChartFactory.createPieChart3D(title, dataset, false, true, true) : ChartFactory.createPieChart(title, dataset, false, true, true); Plot p = chart.getPlot(); PiePlot pp = (PiePlot) p; Font _font = getFont(); pp.setLegendLabelGenerator(new PieSectionLegendLabelGeneratorImpl(_font, chartwidth)); pp.setBaseSectionOutlinePaint(Color.GRAY); // border pp.setLegendItemShape(new Rectangle(7, 7)); pp.setLabelFont(new Font(font, 0, 11)); pp.setLabelLinkPaint(COLOR_333333); pp.setLabelLinkMargin(-0.05); pp.setInteriorGap(0.123); pp.setLabelGenerator(new PieSectionLabelGeneratorImpl(labelFormat)); databackgroundcolor = backgroundcolor; setBackground(chart, p); setBorder(chart, p); setLegend(chart, p, _font); set3d(p); setFont(chart, _font); setTooltip(chart); setScale(chart); // Slice Type and colors boolean doSclice = pieslicestyle == PIE_SLICE_STYLE_SLICED; Color[] colors = csb.getColorlist(); Iterator it = csb.getDatas().iterator(); int count = 0; while (it.hasNext()) { cdb = (ChartDataBean) it.next(); if (doSclice) pp.setExplodePercent(cdb.getItemAsString(), 0.13); if (count < colors.length) { pp.setSectionPaint(cdb.getItemAsString(), colors[count]); } count++; } writeOut(chart); }
From source file:org.sakaiproject.sitestats.impl.chart.ChartServiceImpl.java
private byte[] generatePieChart(String siteId, PieDataset dataset, int width, int height, boolean render3d, float transparency, boolean smallFontInDomainAxis) { JFreeChart chart = null;//w w w.jav a2 s.c o m if (render3d) chart = ChartFactory.createPieChart3D(null, dataset, false, false, false); else chart = ChartFactory.createPieChart(null, dataset, false, false, false); PiePlot plot = (PiePlot) chart.getPlot(); // set start angle (135 or 150 deg so minor data has more space on the left) plot.setStartAngle(150D); // set transparency plot.setForegroundAlpha(transparency); // set background chart.setBackgroundPaint(parseColor(M_sm.getChartBackgroundColor())); plot.setBackgroundPaint(parseColor(M_sm.getChartBackgroundColor())); // fix border offset chart.setPadding(new RectangleInsets(5, 5, 5, 5)); plot.setInsets(new RectangleInsets(1, 1, 1, 1)); // set chart border plot.setOutlinePaint(null); chart.setBorderVisible(true); chart.setBorderPaint(parseColor("#cccccc")); // set antialias chart.setAntiAlias(true); BufferedImage img = chart.createBufferedImage(width, height); final ByteArrayOutputStream out = new ByteArrayOutputStream(); try { ImageIO.write(img, "png", out); } catch (IOException e) { LOG.warn("Error occurred while generating SiteStats chart image data", e); } return out.toByteArray(); }
From source file:msi.gama.outputs.layers.ChartLayerStatement.java
private void createChart(final IScope scope) { switch (type) { case SERIES_CHART: { chart = ChartFactory.createXYLineChart(getName(), "time", "", null, PlotOrientation.VERTICAL, true, false, false);// ww w . j a v a2 s . co m break; } case PIE_CHART: { if (style.equals(IKeyword.THREE_D)) { chart = ChartFactory.createPieChart3D(getName(), null, false, true, false); } else if (style.equals(IKeyword.RING)) { chart = ChartFactory.createRingChart(getName(), null, false, true, false); } else if (style.equals(IKeyword.EXPLODED)) { chart = ChartFactory.createPieChart(getName(), null, false, true, false); exploded = true; } else { chart = ChartFactory.createPieChart(getName(), null, false, true, false); } break; } case HISTOGRAM_CHART: { if (style.equals(IKeyword.THREE_D)) { chart = ChartFactory.createBarChart3D(getName(), null, null, null, PlotOrientation.VERTICAL, true, true, false); } else if (style.equals(IKeyword.STACK)) { chart = ChartFactory.createStackedBarChart(getName(), null, null, null, PlotOrientation.VERTICAL, true, true, false); } else { chart = ChartFactory.createBarChart(getName(), null, null, null, PlotOrientation.VERTICAL, true, true, false); } break; } case XY_CHART: chart = ChartFactory.createXYLineChart(getName(), "", "", null, PlotOrientation.VERTICAL, true, false, false); break; case SCATTER_CHART: chart = ChartFactory.createXYLineChart(getName(), "", "", null, PlotOrientation.VERTICAL, true, false, false); break; case BOX_WHISKER_CHART: { chart = ChartFactory.createBoxAndWhiskerChart(getName(), "Time", "Value", (BoxAndWhiskerCategoryDataset) dataset, true); chart.setBackgroundPaint(new Color(249, 231, 236)); break; } } Plot plot = chart.getPlot(); chart.getTitle().setFont(getTitleFont()); if (backgroundColor == null) { plot.setBackgroundPaint(null); chart.setBackgroundPaint(null); chart.setBorderPaint(null); if (chart.getLegend() != null) { chart.getLegend().setBackgroundPaint(null); } } else { Color bg = backgroundColor; chart.setBackgroundPaint(bg); plot.setBackgroundPaint(bg); chart.setBorderPaint(bg); if (chart.getLegend() != null) { chart.getLegend().setBackgroundPaint(bg); } } // chart.getLegend().setItemPaint(axesColor); // chart.getLegend().setBackgroundPaint(null); if (plot instanceof CategoryPlot) { final CategoryPlot pp = (CategoryPlot) chart.getPlot(); pp.setDomainGridlinePaint(axesColor); pp.setRangeGridlinePaint(axesColor); // plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0)); // plot.setDomainCrosshairVisible(true); pp.setRangeCrosshairVisible(true); } else if (plot instanceof XYPlot) { final XYPlot pp = (XYPlot) chart.getPlot(); pp.setDomainGridlinePaint(axesColor); pp.setRangeGridlinePaint(axesColor); pp.setDomainCrosshairPaint(axesColor); pp.setRangeCrosshairPaint(axesColor); pp.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0)); pp.setDomainCrosshairVisible(true); pp.setRangeCrosshairVisible(true); } }
From source file:org.jfree.eastwood.ChartEngine.java
/** * Creates a pie chart with 3D effect.//from ww w. j av a 2 s.c om * * @return A pie chart. */ private static JFreeChart createPieChart3D() { JFreeChart chart = ChartFactory.createPieChart3D(null, null, false, true, false); chart.setBackgroundPaint(Color.white); chart.setBorderPaint(Color.white); PiePlot3D plot = (PiePlot3D) chart.getPlot(); plot.setInsets(RectangleInsets.ZERO_INSETS); plot.setDarkerSides(true); plot.setBaseSectionOutlinePaint(new Color(0, 0, 0, 0)); plot.setStartAngle(0.0); plot.setInteriorGap(0.10); plot.setLabelGenerator(null); plot.setOutlineVisible(false); plot.setLabelBackgroundPaint(Color.white); plot.setLabelOutlinePaint(null); plot.setLabelShadowPaint(null); plot.setLabelPadding(RectangleInsets.ZERO_INSETS); plot.setLabelFont(new Font("Dialog", Font.PLAIN, 12)); plot.setLabelPaint(Color.darkGray); plot.setToolTipGenerator(new StandardPieToolTipGenerator("{2}")); return chart; }