List of usage examples for org.jfree.chart.entity StandardEntityCollection StandardEntityCollection
public StandardEntityCollection()
From source file:urbanchart.java
public static void main(String[] arg) { final DefaultPieDataset data = new DefaultPieDataset(); data.setValue("Housing(35%)($1050)", new Double(35)); data.setValue("Debt(15%)($450)", new Double(15)); data.setValue("transportation(15%)($450)", new Double(15)); data.setValue("Food(15%)($450)", new Double(25)); data.setValue("Saving(10%)($300)", new Double(10)); JFreeChart chart = ChartFactory.createPieChart( "Average Distribution of expenses on income assuming 3000$/month (Urban areas)", data, true, true, false);/*w ww.j a v a 2s. c om*/ final ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection()); final File file1 = new File("E:\\java projects\\hackathon1\\web\\piecharturban.jpg"); try { ChartUtilities.saveChartAsPNG(file1, chart, 600, 400, info); } catch (IOException ex) { Logger.getLogger(urbanchart.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:ruralchart.java
public static void main(String[] arg) { final DefaultPieDataset data = new DefaultPieDataset(); data.setValue("Housing(35%)($350)", new Double(35)); data.setValue("Debt(15%)($150)", new Double(15)); data.setValue("transportation(15%)($150)", new Double(15)); data.setValue("Food(15%)($250)", new Double(25)); data.setValue("Saving(10%)($100)", new Double(10)); JFreeChart chart = ChartFactory.createPieChart( "Average Distribution of expenses on income assuming 1000$/month (Rural areas)", data, true, true, false);//www .j ava2s. c om final ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection()); final File file1 = new File("E:\\java projects\\hackathon1\\web\\piechartrural.jpg"); try { ChartUtilities.saveChartAsPNG(file1, chart, 600, 400, info); } catch (IOException ex) { Logger.getLogger(urbanchart.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:org.jfree.chart.demo.ImageMapDemo7.java
/** * Starting point for the demo.// w w w .j a v a 2s . c o m * * @param args ignored. */ public static void main(final String[] args) { final XYDataset data = new SampleXYDataset2(); final JFreeChart chart = ChartFactory.createScatterPlot("Scatter Plot Demo", "X", "Y", data, PlotOrientation.VERTICAL, true, true, false); // final Legend legend = chart.getLegend(); // if (legend instanceof StandardLegend) { // final StandardLegend sl = (StandardLegend) legend; // sl.setDisplaySeriesShapes(true); //} final NumberAxis domainAxis = (NumberAxis) chart.getXYPlot().getDomainAxis(); domainAxis.setAutoRangeIncludesZero(false); chart.setBackgroundPaint(java.awt.Color.white); // **************************************************************************** // * JFREECHART DEVELOPER GUIDE * // * The JFreeChart Developer Guide, written by David Gilbert, is available * // * to purchase from Object Refinery Limited: * // * * // * http://www.object-refinery.com/jfreechart/guide.html * // * * // * Sales are used to provide funding for the JFreeChart project - please * // * support us so that we can continue developing free software. * // **************************************************************************** // save it to an image try { final ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection()); final File file1 = new File("scatter100.png"); ChartUtilities.saveChartAsPNG(file1, chart, 600, 400, info); // write an HTML page incorporating the image with an image map final File file2 = new File("scatter100.html"); final OutputStream out = new BufferedOutputStream(new FileOutputStream(file2)); final PrintWriter writer = new PrintWriter(out); writer.println("<HTML>"); writer.println("<HEAD><TITLE>JFreeChart Image Map Demo</TITLE></HEAD>"); writer.println("<BODY>"); // ChartUtilities.writeImageMap(writer, "chart", info); writer.println("<IMG SRC=\"scatter100.png\" " + "WIDTH=\"600\" HEIGHT=\"400\" BORDER=\"0\" USEMAP=\"#chart\">"); writer.println("</BODY>"); writer.println("</HTML>"); writer.close(); } catch (IOException e) { System.out.println(e.toString()); } }
From source file:org.jfree.chart.demo.ImageMapDemo2.java
/** * The starting point for the demo./*w w w . j a v a 2s . c om*/ * * @param args ignored. */ public static void main(final String[] args) { // create a chart final DefaultPieDataset data = new DefaultPieDataset(); data.setValue("One", new Double(43.2)); data.setValue("Two", new Double(10.0)); data.setValue("Three", new Double(27.5)); data.setValue("Four", new Double(17.5)); data.setValue("Five", new Double(11.0)); data.setValue("Six", new Double(19.4)); JFreeChart chart = null; final boolean drilldown = true; // create the chart... if (drilldown) { final PiePlot plot = new PiePlot(data); // plot.setInsets(new Insets(0, 5, 5, 5)); plot.setToolTipGenerator(new StandardPieItemLabelGenerator()); plot.setURLGenerator(new StandardPieURLGenerator("pie_chart_detail.jsp")); chart = new JFreeChart("Pie Chart Demo 1", JFreeChart.DEFAULT_TITLE_FONT, plot, true); } else { chart = ChartFactory.createPieChart("Pie Chart Demo 1", // chart title data, // data true, // include legend true, false); } chart.setBackgroundPaint(java.awt.Color.white); // **************************************************************************** // * JFREECHART DEVELOPER GUIDE * // * The JFreeChart Developer Guide, written by David Gilbert, is available * // * to purchase from Object Refinery Limited: * // * * // * http://www.object-refinery.com/jfreechart/guide.html * // * * // * Sales are used to provide funding for the JFreeChart project - please * // * support us so that we can continue developing free software. * // **************************************************************************** // save it to an image try { final ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection()); final File file1 = new File("piechart100.png"); ChartUtilities.saveChartAsPNG(file1, chart, 600, 400, info); // write an HTML page incorporating the image with an image map final File file2 = new File("piechart100.html"); final OutputStream out = new BufferedOutputStream(new FileOutputStream(file2)); final PrintWriter writer = new PrintWriter(out); writer.println("<HTML>"); writer.println("<HEAD><TITLE>JFreeChart Image Map Demo 2</TITLE></HEAD>"); writer.println("<BODY>"); // ChartUtilities.writeImageMap(writer, "chart", info); writer.println("<IMG SRC=\"piechart100.png\" " + "WIDTH=\"600\" HEIGHT=\"400\" BORDER=\"0\" USEMAP=\"#chart\">"); writer.println("</BODY>"); writer.println("</HTML>"); writer.close(); } catch (IOException e) { System.out.println(e.toString()); } }
From source file:org.jfree.chart.demo.ImageMapDemo4.java
/** * Starting point for the demo.//from www . java2 s .co m * * @param args ignored. */ public static void main(final String[] args) { // create a chart final double[][] data = new double[][] { { 56.0, -12.0, 34.0, 76.0, 56.0, 100.0, 67.0, 45.0 }, { 37.0, 45.0, 67.0, 25.0, 34.0, 34.0, 100.0, 53.0 }, { 43.0, 54.0, 34.0, 34.0, 87.0, 64.0, 73.0, 12.0 } }; final CategoryDataset dataset = DatasetUtilities.createCategoryDataset("Series ", "Type ", data); JFreeChart chart = null; final boolean drilldown = true; if (drilldown) { final CategoryAxis3D categoryAxis = new CategoryAxis3D("Category"); final ValueAxis valueAxis = new NumberAxis3D("Value"); final BarRenderer3D renderer = new BarRenderer3D(); renderer.setToolTipGenerator(new StandardCategoryToolTipGenerator()); renderer.setItemURLGenerator(new StandardCategoryURLGenerator("bar_chart_detail.jsp")); final CategoryPlot plot = new CategoryPlot(dataset, categoryAxis, valueAxis, renderer); plot.setOrientation(PlotOrientation.VERTICAL); chart = new JFreeChart("Bar Chart", JFreeChart.DEFAULT_TITLE_FONT, plot, true); } else { chart = ChartFactory.createBarChart3D("Bar Chart", // chart title "Category", // domain axis label "Value", // range axis label dataset, // data PlotOrientation.VERTICAL, true, // include legend true, false); } chart.setBackgroundPaint(java.awt.Color.white); // **************************************************************************** // * JFREECHART DEVELOPER GUIDE * // * The JFreeChart Developer Guide, written by David Gilbert, is available * // * to purchase from Object Refinery Limited: * // * * // * http://www.object-refinery.com/jfreechart/guide.html * // * * // * Sales are used to provide funding for the JFreeChart project - please * // * support us so that we can continue developing free software. * // **************************************************************************** // save it to an image try { final ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection()); final File file1 = new File("barchart101.png"); ChartUtilities.saveChartAsPNG(file1, chart, 600, 400, info); // write an HTML page incorporating the image with an image map final File file2 = new File("barchart101.html"); final OutputStream out = new BufferedOutputStream(new FileOutputStream(file2)); final PrintWriter writer = new PrintWriter(out); writer.println("<HTML>"); writer.println("<HEAD><TITLE>JFreeChart Image Map Demo</TITLE></HEAD>"); writer.println("<BODY>"); // ChartUtilities.writeImageMap(writer, "chart", info); writer.println("<IMG SRC=\"barchart100.png\" " + "WIDTH=\"600\" HEIGHT=\"400\" BORDER=\"0\" USEMAP=\"#chart\">"); writer.println("</BODY>"); writer.println("</HTML>"); writer.close(); } catch (IOException e) { System.out.println(e.toString()); } }
From source file:org.jfree.chart.demo.ImageMapDemo1.java
/** * Starting point for the demo./*w w w .j a va 2 s . co m*/ * * @param args ignored. */ public static void main(final String[] args) { // create a chart final double[][] data = new double[][] { { 56.0, -12.0, 34.0, 76.0, 56.0, 100.0, 67.0, 45.0 }, { 37.0, 45.0, 67.0, 25.0, 34.0, 34.0, 100.0, 53.0 }, { 43.0, 54.0, 34.0, 34.0, 87.0, 64.0, 73.0, 12.0 } }; final CategoryDataset dataset = DatasetUtilities.createCategoryDataset("Series ", "Type ", data); JFreeChart chart = null; final boolean drilldown = true; if (drilldown) { final CategoryAxis categoryAxis = new CategoryAxis("Category"); final ValueAxis valueAxis = new NumberAxis("Value"); final BarRenderer renderer = new BarRenderer(); renderer.setToolTipGenerator(new StandardCategoryToolTipGenerator()); renderer.setItemURLGenerator(new StandardCategoryURLGenerator("bar_chart_detail.jsp")); final CategoryPlot plot = new CategoryPlot(dataset, categoryAxis, valueAxis, renderer); plot.setOrientation(PlotOrientation.VERTICAL); chart = new JFreeChart("Bar Chart", JFreeChart.DEFAULT_TITLE_FONT, plot, true); } else { chart = ChartFactory.createBarChart("Vertical Bar Chart", // chart title "Category", // domain axis label "Value", // range axis label dataset, // data PlotOrientation.VERTICAL, true, // include legend true, false); } chart.setBackgroundPaint(java.awt.Color.white); // **************************************************************************** // * JFREECHART DEVELOPER GUIDE * // * The JFreeChart Developer Guide, written by David Gilbert, is available * // * to purchase from Object Refinery Limited: * // * * // * http://www.object-refinery.com/jfreechart/guide.html * // * * // * Sales are used to provide funding for the JFreeChart project - please * // * support us so that we can continue developing free software. * // **************************************************************************** // save it to an image try { final ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection()); final File file1 = new File("barchart100.png"); ChartUtilities.saveChartAsPNG(file1, chart, 600, 400, info); // write an HTML page incorporating the image with an image map final File file2 = new File("barchart100.html"); final OutputStream out = new BufferedOutputStream(new FileOutputStream(file2)); final PrintWriter writer = new PrintWriter(out); writer.println("<HTML>"); writer.println("<HEAD><TITLE>JFreeChart Image Map Demo</TITLE></HEAD>"); writer.println("<BODY>"); // ChartUtilities.writeImageMap(writer, "chart", info); writer.println("<IMG SRC=\"barchart100.png\" " + "WIDTH=\"600\" HEIGHT=\"400\" BORDER=\"0\" USEMAP=\"#chart\">"); writer.println("</BODY>"); writer.println("</HTML>"); writer.close(); } catch (IOException e) { System.out.println(e.toString()); } }
From source file:org.jfree.chart.demo.ImageMapDemo3.java
/** * Starting point for the demo.// w w w . jav a 2s. com * * @param args ignored. * * @throws ParseException if there is a problem parsing dates. */ public static void main(final String[] args) throws ParseException { // Create a sample dataset final SimpleDateFormat sdf = new SimpleDateFormat("dd-MMM-yyyy"); final XYSeries dataSeries = new XYSeries("Curve data"); final ArrayList toolTips = new ArrayList(); dataSeries.add(sdf.parse("01-Jul-2002").getTime(), 5.22); toolTips.add("1D - 5.22"); dataSeries.add(sdf.parse("02-Jul-2002").getTime(), 5.18); toolTips.add("2D - 5.18"); dataSeries.add(sdf.parse("03-Jul-2002").getTime(), 5.23); toolTips.add("3D - 5.23"); dataSeries.add(sdf.parse("04-Jul-2002").getTime(), 5.15); toolTips.add("4D - 5.15"); dataSeries.add(sdf.parse("05-Jul-2002").getTime(), 5.22); toolTips.add("5D - 5.22"); dataSeries.add(sdf.parse("06-Jul-2002").getTime(), 5.25); toolTips.add("6D - 5.25"); dataSeries.add(sdf.parse("07-Jul-2002").getTime(), 5.31); toolTips.add("7D - 5.31"); dataSeries.add(sdf.parse("08-Jul-2002").getTime(), 5.36); toolTips.add("8D - 5.36"); final XYSeriesCollection xyDataset = new XYSeriesCollection(dataSeries); final CustomXYToolTipGenerator ttg = new CustomXYToolTipGenerator(); ttg.addToolTipSeries(toolTips); // Create the chart final StandardXYURLGenerator urlg = new StandardXYURLGenerator("xy_details.jsp"); final ValueAxis timeAxis = new DateAxis(""); final NumberAxis valueAxis = new NumberAxis(""); valueAxis.setAutoRangeIncludesZero(false); // override default final XYPlot plot = new XYPlot(xyDataset, timeAxis, valueAxis, null); final StandardXYItemRenderer sxyir = new StandardXYItemRenderer( StandardXYItemRenderer.LINES + StandardXYItemRenderer.SHAPES, ttg, urlg); sxyir.setShapesFilled(true); plot.setRenderer(sxyir); final JFreeChart chart = new JFreeChart("", JFreeChart.DEFAULT_TITLE_FONT, plot, false); chart.setBackgroundPaint(java.awt.Color.white); // **************************************************************************** // * JFREECHART DEVELOPER GUIDE * // * The JFreeChart Developer Guide, written by David Gilbert, is available * // * to purchase from Object Refinery Limited: * // * * // * http://www.object-refinery.com/jfreechart/guide.html * // * * // * Sales are used to provide funding for the JFreeChart project - please * // * support us so that we can continue developing free software. * // **************************************************************************** // save it to an image try { final ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection()); final File file1 = new File("xychart100.png"); ChartUtilities.saveChartAsPNG(file1, chart, 600, 400, info); // write an HTML page incorporating the image with an image map final File file2 = new File("xychart100.html"); final OutputStream out = new BufferedOutputStream(new FileOutputStream(file2)); final PrintWriter writer = new PrintWriter(out); writer.println("<HTML>"); writer.println("<HEAD><TITLE>JFreeChart Image Map Demo</TITLE></HEAD>"); writer.println("<BODY>"); // ChartUtilities.writeImageMap(writer, "chart", info); writer.println("<IMG SRC=\"xychart100.png\" " + "WIDTH=\"600\" HEIGHT=\"400\" BORDER=\"0\" USEMAP=\"#chart\">"); writer.println("</BODY>"); writer.println("</HTML>"); writer.close(); } catch (IOException e) { System.out.println(e.toString()); } return; }
From source file:com.googlecode.tawus.jfreechart.ChartModel.java
public ChartModel(JFreeChart chart, int width, int height) { this.chart = chart; this.width = width; this.height = height; info = new ChartRenderingInfo(new StandardEntityCollection()); }
From source file:com.glaf.chart.util.ChartUtils.java
public static byte[] createChart(Chart chartModel, JFreeChart chart) { ByteArrayOutputStream baos = null; BufferedOutputStream bos = null; try {/* www . j a v a 2 s . co m*/ baos = new ByteArrayOutputStream(); bos = new BufferedOutputStream(baos); java.awt.image.BufferedImage bi = chart.createBufferedImage(chartModel.getChartWidth(), chartModel.getChartHeight()); if ("png".equalsIgnoreCase(chartModel.getImageType())) { EncoderUtil.writeBufferedImage(bi, chartModel.getImageType(), bos); ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection()); ServletUtilities.saveChartAsPNG(chart, chartModel.getChartWidth(), chartModel.getChartHeight(), info, null); } else if ("jpeg".equalsIgnoreCase(chartModel.getImageType())) { EncoderUtil.writeBufferedImage(bi, chartModel.getImageType(), bos); ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection()); ServletUtilities.saveChartAsJPEG(chart, chartModel.getChartWidth(), chartModel.getChartHeight(), info, null); } bos.flush(); baos.flush(); return baos.toByteArray(); } catch (Exception ex) { throw new RuntimeException(ex); } finally { IOUtils.closeQuietly(baos); IOUtils.closeQuietly(bos); } }
From source file:nl.wur.plantbreeding.www.marker2seq.GoDistribution.java
/** * Generate the Pie chart for a set of given Go terms. * @param distrib a HashMap of GO name and GO frequency * @param title the title of the GO graph * @param url the url used for the tooltips * @param session the HttpSession used to save the file * @param legend Print the legend or not * @param tooltips Add tooltip or not/*from w ww. ja va 2s.c o m*/ * @param urls Add urls or not (link in the graph) * @param max Maximum number of item to display * @return a list containing the filename and the map for the figure * @throws IOException when something happens while writting the image */ public static String[] generateDistribution(final HashMap<String, Integer> distrib, final String title, final String url, final HttpSession session, final boolean legend, final boolean tooltips, final boolean urls, final int max) throws IOException { final PieChart piec = new PieChart(); final PieDataset piedata = piec.createDataset(distrib); final JFreeChart chart = piec.createChart(piedata, title, legend, tooltips, urls); final PiePlot plot = (PiePlot) chart.getPlot(); if (distrib.size() >= max) { plot.setLabelGenerator(null); } plot.setURLGenerator(new StandardPieURLGenerator(url, "section")); final ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection()); final String filename = ServletUtilities.saveChartAsPNG(chart, 500, 400, info, session); final String map = ChartUtilities.getImageMap(filename, info); final String[] output = { filename, map }; return output; }