List of usage examples for org.jfree.chart.plot PiePlot setExplodePercent
public void setExplodePercent(int section, double percent)
From source file:edu.uara.wrappers.customcharts.CustomPieChart.java
/** * Function to set exploded parts of the chart * key--category to be exploded from the chart * percent-- percentage of the radius of the pie chart *//*from w w w . j ava 2 s . c om*/ @Override public void setExplodePercent(String key, double percent) { Plot plot = chart.getPlot(); if (plot instanceof MultiplePiePlot) { MultiplePiePlot p = (MultiplePiePlot) plot; JFreeChart pieCh = p.getPieChart(); PiePlot piePlot = (PiePlot) pieCh.getPlot(); piePlot.setExplodePercent(key, percent); } else { PiePlot p = (PiePlot) plot; p.setExplodePercent(key, percent); } }
From source file:result.analysis.Chart.java
void perSemPerformace(String batch, String sem, String[] colleges) { DefaultCategoryDataset dataset = new DefaultCategoryDataset(); for (String college : colleges) { db = mongoClient.getDB(college); String collection_name = "cs_" + batch + "_" + sem + "_sem"; DBCollection collection = db.getCollection(collection_name); analyz = new Analyze(db); double number = analyz.GetNumber(collection, "FAIL"); dataset.setValue(number, college, "FAIL"); number = analyz.GetNumber(collection, "FIRST CLASS"); dataset.setValue(number, college, "First Class"); number = analyz.GetNumber(collection, "SECOND CLASS"); dataset.setValue(number, college, "Second class"); number = analyz.GetNumber(collection, "FIRST CLASS WITH DISTINCTION"); dataset.setValue(number, college, "First Class With Distinction"); }/*ww w. j a va2 s . c o m*/ JFreeChart pieChart = ChartFactory.createMultiplePieChart("Classwise Distribution", dataset, TableOrder.BY_ROW, true, true, true); // MultiplePiePlot plot = (MultiplePiePlot) pieChart.getPlot(); // plot.setStartAngle(290); // plot.setDirection(Rotation.CLOCKWISE); // plot.setForegroundAlpha(0.5f); MultiplePiePlot plot = (MultiplePiePlot) pieChart.getPlot(); JFreeChart subchart = plot.getPieChart(); PiePlot p = (PiePlot) subchart.getPlot(); // p.setSimpleLabels(true); p.setExplodePercent("First Class With Distinction", 0.10); p.setExplodePercent("First Class", 0.10); p.setExplodePercent("Second class", 0.10); p.setExplodePercent("FAIL", 0.10); PieSectionLabelGenerator gen = new StandardPieSectionLabelGenerator("{0}: {1} ({2})", new DecimalFormat("0"), new DecimalFormat("0%")); p.setLabelGenerator(gen); ChartFrame frame = new ChartFrame("Semester Wise Performance of " + batch + " year", pieChart); frame.setVisible(true); frame.setSize(500, 500); save_jpeg(pieChart); }
From source file:edu.ucla.stat.SOCR.chart.demo.PieChartDemo2.java
/** * Creates a sample chart./*from w w w. ja v a 2s .c o m*/ * * @param dataset the dataset. * * @return A chart. */ protected JFreeChart createChart(PieDataset dataset) { JFreeChart chart = ChartFactory.createPieChart(chartTitle, // chart title dataset, // dataset !legendPanelOn, // include legend true, false); PiePlot plot = (PiePlot) chart.getPlot(); plot.setNoDataMessage("No data available"); for (int i = 0; i < pulloutFlag.length; i++) { //System.out.println("\""+pulloutFlag[i]+"\""); if (isPullout(i)) { Comparable key = dataset.getKey(i); plot.setExplodePercent(key, 0.30); } } plot.setLegendLabelToolTipGenerator(new StandardPieSectionLabelGenerator("Tooltip for legend item {0}")); if (rotateOn) { Rotator rotator = new Rotator(plot); rotator.start(); } setCategorySummary(dataset); return chart; }
From source file:com.itemanalysis.jmetrik.graph.piechart.PieChartPanel.java
public void setGraph() { if (hasGroupVariable) { DefaultCategoryDataset piedat = new DefaultCategoryDataset(); chart = ChartFactory.createMultiplePieChart(chartTitle, piedat, TableOrder.BY_ROW, showLegend, true, false);/* w w w . ja v a2s . c om*/ if (chartSubtitle != null && !"".equals(chartSubtitle)) { TextTitle subtitle1 = new TextTitle(chartSubtitle); chart.addSubtitle(subtitle1); } MultiplePiePlot plot = (MultiplePiePlot) chart.getPlot(); JFreeChart subchart = plot.getPieChart(); PiePlot p = (PiePlot) subchart.getPlot(); p.setBackgroundPaint(Color.WHITE); p.setLabelGenerator(new StandardPieSectionLabelGenerator("{0} ({2})")); if (explode) p.setExplodePercent(explodeValue, explodePercent); ChartPanel panel = new ChartPanel(chart); panel.setPreferredSize(new Dimension(width, height)); chart.setPadding(new RectangleInsets(20.0, 5.0, 20.0, 5.0)); this.add(panel); } else { DefaultPieDataset piedat = new DefaultPieDataset(); if (command.getSelectOneOption("view").isValueSelected("3D")) { chart = ChartFactory.createPieChart3D(chartTitle, piedat, showLegend, true, false); PiePlot3D plot = (PiePlot3D) chart.getPlot(); plot.setStartAngle(290); plot.setDirection(Rotation.CLOCKWISE); plot.setForegroundAlpha(0.5f); plot.setNoDataMessage("No data to display"); if (explode) plot.setExplodePercent(explodeValue, explodePercent); } else { chart = ChartFactory.createPieChart(command.getFreeOption("title").getString(), piedat, showLegend, true, false); } if (chartSubtitle != null && !"".equals(chartSubtitle)) { TextTitle subtitle = new TextTitle(chartSubtitle); chart.addSubtitle(subtitle); } PiePlot plot = (PiePlot) chart.getPlot(); plot.setLabelGap(0.02); plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0} ({2})")); plot.setBackgroundPaint(Color.WHITE); if (explode) plot.setExplodePercent(explodeValue, explodePercent); ChartPanel panel = new ChartPanel(chart); panel.getPopupMenu().addSeparator(); this.addJpgMenuItem(this, panel.getPopupMenu()); panel.setPreferredSize(new Dimension(width, height)); chart.setPadding(new RectangleInsets(5.0, 5.0, 5.0, 5.0)); this.setBackground(Color.WHITE); this.add(panel); } }
From source file:sentimentanalyzer.ChartController.java
public void createAndPopulatePieChart__TESTER(JPanel pnlPieChart) { DefaultPieDataset data = new DefaultPieDataset(); data.setValue(Pos, 0 /*count for 1 */); data.setValue(Neu, 0 /*count for 0 */); data.setValue(Neg, 0 /*count for -1 */); JFreeChart chart = ChartFactory.createPieChart("Sent. Distr. for Testing", data, false, // legend? false, // tooltips? false // URLs? );//w w w .j a v a2 s . c o m ChartPanel CP = new ChartPanel(chart); PiePlot plot = (PiePlot) chart.getPlot(); plot.setSectionPaint("Pie chart is not available", Color.LIGHT_GRAY); plot.setExplodePercent(Pos, 0.025); plot.setExplodePercent(Neg, 0.025); plot.setExplodePercent(Neu, 0.025); //Customize PieChart to show absolute values and percentages; PieSectionLabelGenerator gen = new StandardPieSectionLabelGenerator("{0}: {1} ({2})", new DecimalFormat("0"), new DecimalFormat("0.00%")); plot.setLabelGenerator(gen); TextTitle legendText = new TextTitle("The total number of tweets: "); legendText.setPosition(RectangleEdge.BOTTOM); chart.addSubtitle(legendText); pnlPieChart.setLayout(new java.awt.BorderLayout()); pnlPieChart.add(CP, BorderLayout.CENTER); }
From source file:sentimentanalyzer.ChartController.java
public void createAndPopulatePieChart(JPanel pnlPieChart, double positiveValue, double negativeValue, double neutralValue) { DefaultPieDataset data = new DefaultPieDataset(); data.setValue(Pos, positiveValue /*count for 1 */); data.setValue(Neu, neutralValue /*count for 0 */); data.setValue(Neg, negativeValue /*count for -1 */); JFreeChart chart = ChartFactory.createPieChart("Sent. Distr. for Testing", data, false, // legend? false, // tooltips? false // URLs? );/*from www.ja v a2s .c o m*/ ChartPanel CP = new ChartPanel(chart); PiePlot plot = (PiePlot) chart.getPlot(); plot.setSectionPaint("Pie chart is not available", Color.LIGHT_GRAY); plot.setExplodePercent(Pos, 0.02); plot.setExplodePercent(Neg, 0.02); plot.setExplodePercent(Neu, 0.02); double sum = positiveValue + negativeValue + neutralValue; int z = (int) sum; //Customize PieChart to show absolute values and percentages; PieSectionLabelGenerator gen = new StandardPieSectionLabelGenerator("{0}: {1} ({2})", new DecimalFormat("0"), new DecimalFormat("0.00%")); plot.setLabelGenerator(gen); TextTitle legendText = new TextTitle("The total number of tweets: " + z); legendText.setPosition(RectangleEdge.BOTTOM); chart.addSubtitle(legendText); pnlPieChart.removeAll(); pnlPieChart.setLayout(new java.awt.BorderLayout()); pnlPieChart.add(CP, BorderLayout.CENTER); }
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);//w ww . java2 s .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; }
From source file:msi.gama.outputs.layers.charts.ChartJFreeChartOutputPie.java
@Override protected void createNewSerie(final IScope scope, final String serieid) { // final ChartDataSeries dataserie = chartdataset.getDataSeries(scope, // serieid);// ww w.j a va 2s .co m final PiePlot plot = (PiePlot) this.chart.getPlot(); // final DefaultPieDataset firstdataset = (DefaultPieDataset) // plot.getDataset(); nbseries++; IdPosition.put(serieid, nbseries - 1); if (getStyle().equals(IKeyword.EXPLODED)) { plot.setExplodePercent(serieid, 0.20); } // DEBUG.LOG("new serie"+serieid+" at // "+IdPosition.get(serieid)+" jfds "+jfreedataset.size()+" datasc "+" // nbse "+nbseries); }
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);/* w w w . ja v a2 s. c o 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:edu.ucla.stat.SOCR.chart.demo.PieChartDemo4.java
protected JFreeChart createChart(PieDataset dataset) { // create the chart... JFreeChart chart = ChartFactory.createPieChart(chartTitle, // chart title dataset, // dataset !legendPanelOn, // include legend true, false);/*from w w w. j a v a 2s.c o m*/ // set the background color for the chart... chart.setBackgroundPaint(new Color(222, 222, 255)); PiePlot plot = (PiePlot) chart.getPlot(); plot.setBackgroundPaint(Color.white); plot.setCircular(true); for (int i = 0; i < pulloutFlag.length; i++) { //System.out.println("\""+pulloutFlag[i]+"\""); if (isPullout(i)) { Comparable key = dataset.getKey(i); plot.setExplodePercent(key, 0.30); } } plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0} = {2}", NumberFormat.getNumberInstance(), NumberFormat.getPercentInstance())); plot.setNoDataMessage("No data available"); if (rotateOn) { Rotator rotator = new Rotator(plot); rotator.start(); } setCategorySummary(dataset); return chart; }