List of usage examples for org.jfree.chart ChartFactory createPieChart
public static JFreeChart createPieChart(String title, PieDataset dataset, boolean legend, boolean tooltips, boolean urls)
From source file:Graphic.camembert.java
public camembert(List<Float> valeurs) { DefaultPieDataset pieDataset = new DefaultPieDataset(); for (int i = 0; i < valeurs.size(); i++) { pieDataset.setValue("" + (i + 1), valeurs.get(i)); }/* ww w.j a va 2 s .c om*/ final JFreeChart pieChart = ChartFactory.createPieChart("Repartition des camions", pieDataset, true, false, false); final ChartPanel cPanel = new ChartPanel(pieChart); add(cPanel); }
From source file:com.voterData.graph.Graph.java
public static JFreeChart getPopulationDistChart(ArrayList<VoterDetails> voterDetList) { DefaultPieDataset dataset = new DefaultPieDataset(); for (VoterDetails voterDetObj : voterDetList) { dataset.setValue(voterDetObj.getRes_city_desc(), Double.parseDouble(voterDetObj.getVoter_reg_num())); }/* www .j ava 2 s .co m*/ boolean legend = true; boolean tooltips = false; boolean urls = false; JFreeChart chart = ChartFactory.createPieChart("Population Distribution of Mecklenburg County", dataset, legend, tooltips, urls); //chart.setBorderPaint(Color.GREEN); //chart.setBorderStroke(new BasicStroke(5.0f)); //chart.setBorderVisible(true); /* DefaultCategoryDataset bardataset = new DefaultCategoryDataset(); for(VoterDetails voterDetObj : voterDetList){ bardataset.setValue(Double.parseDouble(voterDetObj.getVoter_reg_num()), "Population(%)", voterDetObj.getRes_city_desc()); } JFreeChart barchart = ChartFactory.createBarChart3D( "Population-Cities", //Title "Cities in Mecklenburg County", // X-axis Label "Population(%)", // Y-axis Label bardataset, // Dataset PlotOrientation.VERTICAL, //Plot orientation false, // Show legend true, // Use tooltips false // Generate URLs ); */ return chart; }
From source file:framepackage.MyPieChart.java
public MyPieChart() { DefaultPieDataset pieDataset = new DefaultPieDataset(); pieDataset.setValue("Online", new Integer(10)); pieDataset.setValue("Offline", new Integer(20)); pieDataset.setValue("Busy", new Integer(30)); pieDataset.setValue("Away", new Integer(40)); JFreeChart chart = ChartFactory.createPieChart("my pie", pieDataset, true, true, true); PiePlot P = (PiePlot) chart.getPlot(); //P.setForegroundAlpha(TOP_ALIGNMENT); ChartFrame f = new ChartFrame("chart", chart); f.setVisible(true);//from w ww.ja va 2s . c o m f.setSize(500, 700); }
From source file:com.globalsight.util.JfreeCharUtil.java
public static void drawPieChart2D(String title, Map<String, Double> datas, File OutFile) { PieDataset dataset = buildDatas(datas); JFreeChart chart = ChartFactory.createPieChart(title, dataset, true, true, false); PiePlot plot = (PiePlot) chart.getPlot(); plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0}={1}({2})", NumberFormat.getNumberInstance(), new DecimalFormat("0.00%"))); plot.setLegendLabelGenerator(new StandardPieSectionLabelGenerator("{0}={1}({2})")); chart.setBackgroundPaint(Color.white); plot.setCircular(true);// w w w. ja va 2 s .co m TextTitle textTitle = new TextTitle(title); Font font = new Font(textTitle.getFont().getName(), Font.CENTER_BASELINE, 20); textTitle.setFont(font); chart.setTitle(textTitle); FileOutputStream fos_jpg = null; try { fos_jpg = new FileOutputStream(OutFile); ChartUtilities.writeChartAsJPEG(fos_jpg, 1, chart, 640, 480, null); fos_jpg.close(); } catch (Exception e) { s_logger.error(e.getMessage(), e); } }
From source file:org.jfree.chart.demo.MouseListenerDemo1.java
public MouseListenerDemo1(String s) { super(s);//from w w w. j a v a 2 s . c o m DefaultPieDataset defaultpiedataset = new DefaultPieDataset(); defaultpiedataset.setValue("Java", new Double(43.200000000000003D)); defaultpiedataset.setValue("Visual Basic", new Double(0.0D)); defaultpiedataset.setValue("C/C++", new Double(17.5D)); org.jfree.chart.JFreeChart jfreechart = ChartFactory.createPieChart("Pie Chart Demo 1", defaultpiedataset, true, true, false); ChartPanel chartpanel = new ChartPanel(jfreechart, false, false, false, false, false); chartpanel.addChartMouseListener(this); chartpanel.setPreferredSize(new Dimension(500, 270)); setContentPane(chartpanel); }
From source file:userInterface.MonitoringTeamRole.DashBoarJPanel.java
private static JFreeChart createChart(PieDataset dataset) { JFreeChart chart = ChartFactory.createPieChart("Successful authentication login vs failed login events", // chart title dataset, // data true, // include legend true, false);/*ww w .ja v a2s . c o m*/ return chart; }
From source file:thesisdata.PieChartDemo1.java
/** * Creates a chart./* w w w . j a v a 2 s .c o m*/ * * @param dataset the dataset. * * @return A chart. */ private static JFreeChart createChart(PieDataset dataset) { JFreeChart chart = ChartFactory.createPieChart("Death Causes Detection", // chart title dataset, // data true, // include legend true, false); PiePlot plot = (PiePlot) chart.getPlot(); plot.setLabelFont(new Font("SansSerif", Font.PLAIN, 12)); plot.setNoDataMessage("No data available"); plot.setCircular(false); plot.setLabelGap(0.02); return chart; }
From source file:JchartTest.JfreeChartAction.java
@Override public String execute() throws Exception { DefaultPieDataset dataSet = new DefaultPieDataset(); dataSet.setValue("Agriculture", 10); dataSet.setValue("Residential heating", 4); dataSet.setValue("Commercial products", 15); dataSet.setValue("Industry", 42); dataSet.setValue("Transportation", 26); dataSet.setValue("Others", 3); chart = ChartFactory.createPieChart("Source of Air Pollution ", // Title dataSet, // Data true, // Display the legend true, // Display tool tips false // No URLs );/*from ww w . j ava 2s. c o m*/ chart.setBorderVisible(true); return SUCCESS; }
From source file:statistic.ca.gui.Charts.java
public static JFreeChart createBarChart(ChartData data) { if (data.getDiagramType().equals("bar")) { chart = ChartFactory.createBarChart(data.getTitle(), // Title data.getYAxisLabel(), // X-Axis label "", // Y-Axis label data.getCDataSet(), // CategoryDataset PlotOrientation.VERTICAL, false, true, false // Show legend );/* w ww . j a v a2 s.c o m*/ CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.setBackgroundPaint(Color.LIGHT_GRAY); plot.setDomainGridlinePaint(Color.WHITE); plot.setRangeGridlinePaint(Color.WHITE); plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0)); } if (data.getDiagramType().equals("pie")) { chart = ChartFactory.createPieChart(data.getTitle(), // Title data.getPieDataSet(), false, true, false); } chart.setBackgroundPaint(Color.WHITE); return chart; }
From source file:com.gallatinsystems.common.util.JFreechartChartUtil.java
/** * generates a pie chart with the set of labels and values passed in (the labels and values * arrays must both be non-null and contain the same number of elements). The chart is returned * as a byte array representing the image. * /*from ww w . j a v a 2 s .c o m*/ * @param labels * @param values * @param title * @param width * @param height * @return - byte array containing the image, null if there is an error. */ public static byte[] getPieChart(List<String> labels, List<String> values, String title, int width, int height) { DefaultPieDataset pieDataset = new DefaultPieDataset(); for (int i = 0; i < labels.size(); i++) { pieDataset.setValue(labels.get(i) + " (" + values.get(i) + ")", Double.parseDouble(values.get(i))); } JFreeChart chart = ChartFactory.createPieChart(title, pieDataset, false, false, false); try { return ChartUtilities.encodeAsPNG(chart.createBufferedImage(width, height)); } catch (Exception e) { e.printStackTrace(System.err); return null; } }