List of usage examples for org.jfree.chart JFreeChart createBufferedImage
public BufferedImage createBufferedImage(int width, int height, int imageType, ChartRenderingInfo info)
From source file:de.forsthaus.webui.customer.CustomerChartCtrl.java
/** * onClick button PieChart 3D. <br> * // w w w .ja v a 2 s.c o m * @param event * @throws IOException */ public void onClick$button_CustomerChart_PieChart3D(Event event) throws InterruptedException, IOException { // logger.debug(event.toString()); div_chartArea.getChildren().clear(); // get the customer ID for which we want show a chart long kunId = getCustomer().getId(); // get a list of data List<ChartData> kunAmountList = getChartService().getChartDataForCustomer(kunId); if (kunAmountList.size() > 0) { DefaultPieDataset pieDataset = new DefaultPieDataset(); for (ChartData chartData : kunAmountList) { Calendar calendar = new GregorianCalendar(); calendar.setTime(chartData.getChartKunInvoiceDate()); int month = calendar.get(Calendar.MONTH) + 1; int year = calendar.get(Calendar.YEAR); String key = String.valueOf(month) + "/" + String.valueOf(year); BigDecimal bd = chartData.getChartKunInvoiceAmount().setScale(15, 3); String amount = String.valueOf(bd.doubleValue()); // fill the data pieDataset.setValue(key + " " + amount, new Double(chartData.getChartKunInvoiceAmount().doubleValue())); } String title = "Monthly amount for year 2009"; JFreeChart chart = ChartFactory.createPieChart3D(title, pieDataset, true, true, true); PiePlot3D plot = (PiePlot3D) chart.getPlot(); plot.setForegroundAlpha(0.5f); BufferedImage bi = chart.createBufferedImage(chartWidth, chartHeight, BufferedImage.TRANSLUCENT, null); byte[] bytes = EncoderUtil.encode(bi, ImageFormat.PNG, true); AImage chartImage = new AImage("Pie Chart", bytes); Image img = new Image(); img.setContent(chartImage); img.setParent(this.div_chartArea); } else { div_chartArea.getChildren().clear(); Label label = new Label(); label.setValue("This customer have no data for showing in a chart!"); label.setParent(div_chartArea); } }
From source file:org.jivesoftware.openfire.reporting.graph.GraphEngine.java
/** * Creates a graph in PNG format. The PNG graph is encoded by the KeypointPNGEncoderAdapter * so that the resulting PNG is encoded with alpha transparency. * * @param key//from w w w.ja v a 2s . c o m * @param width * @param height * @param startTime * @param endTime * @param dataPoints * @return * @throws IOException */ public byte[] generateGraph(String key, int width, int height, String color, long startTime, long endTime, int dataPoints) throws IOException { JFreeChart chart = generateChart(key, width, height, color, startTime, endTime, dataPoints); KeypointPNGEncoderAdapter encoder = new KeypointPNGEncoderAdapter(); encoder.setEncodingAlpha(true); return encoder.encode(chart.createBufferedImage(width, height, BufferedImage.BITMASK, null)); }
From source file:de.forsthaus.webui.customer.CustomerChartCtrl.java
/** * onClick button Bar Chart. <br>/*from w w w .java 2s.c o m*/ * * @param event * @throws IOException */ public void onClick$button_CustomerChart_BarChart(Event event) throws InterruptedException, IOException { // logger.debug(event.toString()); div_chartArea.getChildren().clear(); // get the customer ID for which we want show a chart long kunId = getCustomer().getId(); // get a list of data List<ChartData> kunAmountList = getChartService().getChartDataForCustomer(kunId); if (kunAmountList.size() > 0) { DefaultCategoryDataset dataset = new DefaultCategoryDataset(); for (ChartData chartData : kunAmountList) { Calendar calendar = new GregorianCalendar(); calendar.setTime(chartData.getChartKunInvoiceDate()); int month = calendar.get(Calendar.MONTH) + 1; int year = calendar.get(Calendar.YEAR); String key = String.valueOf(month) + "/" + String.valueOf(year); BigDecimal bd = chartData.getChartKunInvoiceAmount().setScale(15, 3); String amount = String.valueOf(bd.doubleValue()); // fill the data dataset.setValue(new Double(chartData.getChartKunInvoiceAmount().doubleValue()), key + " " + amount, key + " " + amount); } String title = "Monthly amount for year 2009"; PlotOrientation po = PlotOrientation.VERTICAL; JFreeChart chart = ChartFactory.createBarChart(title, "Month", "Amount", dataset, po, true, true, true); CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.setForegroundAlpha(0.5f); BufferedImage bi = chart.createBufferedImage(chartWidth, chartHeight, BufferedImage.TRANSLUCENT, null); byte[] bytes = EncoderUtil.encode(bi, ImageFormat.PNG, true); AImage chartImage = new AImage("Bar Chart", bytes); Image img = new Image(); img.setContent(chartImage); img.setParent(div_chartArea); } else { div_chartArea.getChildren().clear(); Label label = new Label(); label.setValue("This customer have no data for showing in a chart!"); label.setParent(div_chartArea); } }
From source file:de.forsthaus.webui.customer.CustomerChartCtrl.java
/** * onClick button Bar Chart 3D. <br> * /* w ww.j a v a2s. co m*/ * @param event * @throws IOException */ public void onClick$button_CustomerChart_BarChart3D(Event event) throws InterruptedException, IOException { // logger.debug(event.toString()); div_chartArea.getChildren().clear(); // get the customer ID for which we want show a chart long kunId = getCustomer().getId(); // get a list of data List<ChartData> kunAmountList = getChartService().getChartDataForCustomer(kunId); if (kunAmountList.size() > 0) { DefaultCategoryDataset dataset = new DefaultCategoryDataset(); for (ChartData chartData : kunAmountList) { Calendar calendar = new GregorianCalendar(); calendar.setTime(chartData.getChartKunInvoiceDate()); int month = calendar.get(Calendar.MONTH) + 1; int year = calendar.get(Calendar.YEAR); String key = String.valueOf(month) + "/" + String.valueOf(year); BigDecimal bd = chartData.getChartKunInvoiceAmount().setScale(15, 3); String amount = String.valueOf(bd.doubleValue()); // fill the data dataset.setValue(new Double(chartData.getChartKunInvoiceAmount().doubleValue()), key + " " + amount, key + " " + amount); } String title = "Monthly amount for year 2009"; PlotOrientation po = PlotOrientation.VERTICAL; JFreeChart chart = ChartFactory.createBarChart3D(title, "Month", "Amount", dataset, po, true, true, true); CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.setForegroundAlpha(0.5f); BufferedImage bi = chart.createBufferedImage(chartWidth, chartHeight, BufferedImage.TRANSLUCENT, null); byte[] bytes = EncoderUtil.encode(bi, ImageFormat.PNG, true); AImage chartImage = new AImage("Bar Chart 3D", bytes); Image img = new Image(); img.setContent(chartImage); img.setParent(div_chartArea); } else { div_chartArea.getChildren().clear(); Label label = new Label(); label.setValue("This customer have no data for showing in a chart!"); label.setParent(div_chartArea); } }
From source file:de.forsthaus.webui.customer.CustomerChartCtrl.java
/** * onClick button Line Bar Chart. <br> * /* ww w .ja va 2 s .co m*/ * @param event * @throws IOException */ public void onClick$button_CustomerChart_LineBar(Event event) throws InterruptedException, IOException { // logger.debug(event.toString()); div_chartArea.getChildren().clear(); // get the customer ID for which we want show a chart long kunId = getCustomer().getId(); // get a list of data List<ChartData> kunAmountList = getChartService().getChartDataForCustomer(kunId); if (kunAmountList.size() > 0) { DefaultCategoryDataset dataset = new DefaultCategoryDataset(); for (ChartData chartData : kunAmountList) { Calendar calendar = new GregorianCalendar(); calendar.setTime(chartData.getChartKunInvoiceDate()); int month = calendar.get(Calendar.MONTH) + 1; int year = calendar.get(Calendar.YEAR); String key = String.valueOf(month) + "/" + String.valueOf(year); BigDecimal bd = chartData.getChartKunInvoiceAmount().setScale(15, 3); String amount = String.valueOf(bd.doubleValue()); // fill the data dataset.setValue(new Double(chartData.getChartKunInvoiceAmount().doubleValue()), "2009", key + " " + amount); } String title = "Monthly amount for year 2009"; PlotOrientation po = PlotOrientation.VERTICAL; JFreeChart chart = ChartFactory.createLineChart(title, "Month", "Amount", dataset, po, true, true, true); CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.setForegroundAlpha(0.5f); BufferedImage bi = chart.createBufferedImage(chartWidth, chartHeight, BufferedImage.TRANSLUCENT, null); byte[] bytes = EncoderUtil.encode(bi, ImageFormat.PNG, true); AImage chartImage = new AImage("Line Bar Chart", bytes); Image img = new Image(); img.setContent(chartImage); img.setParent(div_chartArea); } else { div_chartArea.getChildren().clear(); Label label = new Label(); label.setValue("This customer have no data for showing in a chart!"); label.setParent(div_chartArea); } }
From source file:de.forsthaus.webui.customer.CustomerChartCtrl.java
/** * onClick button Line Bar 3D Chart. <br> * // w w w . ja v a 2 s . c o m * @param event * @throws IOException */ public void onClick$button_CustomerChart_LineBar3D(Event event) throws InterruptedException, IOException { // logger.debug(event.toString()); div_chartArea.getChildren().clear(); // get the customer ID for which we want show a chart long kunId = getCustomer().getId(); // get a list of data List<ChartData> kunAmountList = getChartService().getChartDataForCustomer(kunId); if (kunAmountList.size() > 0) { DefaultCategoryDataset dataset = new DefaultCategoryDataset(); for (ChartData chartData : kunAmountList) { Calendar calendar = new GregorianCalendar(); calendar.setTime(chartData.getChartKunInvoiceDate()); int month = calendar.get(Calendar.MONTH) + 1; int year = calendar.get(Calendar.YEAR); String key = String.valueOf(month) + "/" + String.valueOf(year); BigDecimal bd = chartData.getChartKunInvoiceAmount().setScale(15, 3); String amount = String.valueOf(bd.doubleValue()); // fill the data dataset.setValue(new Double(chartData.getChartKunInvoiceAmount().doubleValue()), "2009", key + " " + amount); } String title = "Monthly amount for year 2009"; PlotOrientation po = PlotOrientation.VERTICAL; JFreeChart chart = ChartFactory.createLineChart3D(title, "Month", "Amount", dataset, po, true, true, true); CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.setForegroundAlpha(0.5f); BufferedImage bi = chart.createBufferedImage(chartWidth, chartHeight, BufferedImage.TRANSLUCENT, null); byte[] bytes = EncoderUtil.encode(bi, ImageFormat.PNG, true); AImage chartImage = new AImage("Line Bar Chart 3D", bytes); Image img = new Image(); img.setContent(chartImage); img.setParent(div_chartArea); } else { div_chartArea.getChildren().clear(); Label label = new Label(); label.setValue("This customer have no data for showing in a chart!"); label.setParent(div_chartArea); } }
From source file:de.forsthaus.webui.customer.CustomerChartCtrl.java
/** * onClick button Stacked Bar Chart. <br> * // w ww . j a va 2 s . c om * @param event * @throws IOException */ public void onClick$button_CustomerChart_StackedBar(Event event) throws InterruptedException, IOException { // logger.debug(event.toString()); div_chartArea.getChildren().clear(); // get the customer ID for which we want show a chart long kunId = getCustomer().getId(); // get a list of data List<ChartData> kunAmountList = getChartService().getChartDataForCustomer(kunId); if (kunAmountList.size() > 0) { DefaultCategoryDataset dataset = new DefaultCategoryDataset(); for (ChartData chartData : kunAmountList) { Calendar calendar = new GregorianCalendar(); calendar.setTime(chartData.getChartKunInvoiceDate()); int month = calendar.get(Calendar.MONTH) + 1; int year = calendar.get(Calendar.YEAR); String key = String.valueOf(month) + "/" + String.valueOf(year); BigDecimal bd = chartData.getChartKunInvoiceAmount().setScale(15, 3); String amount = String.valueOf(bd.doubleValue()); // fill the data dataset.setValue(new Double(chartData.getChartKunInvoiceAmount().doubleValue()), key + " " + amount, key + " " + amount); } String title = "Monthly amount for year 2009"; PlotOrientation po = PlotOrientation.VERTICAL; JFreeChart chart = ChartFactory.createStackedBarChart(title, "Month", "Amount", dataset, po, true, true, true); CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.setForegroundAlpha(0.5f); BufferedImage bi = chart.createBufferedImage(chartWidth, chartHeight, BufferedImage.TRANSLUCENT, null); byte[] bytes = EncoderUtil.encode(bi, ImageFormat.PNG, true); AImage chartImage = new AImage("Stacked Bar Chart", bytes); Image img = new Image(); img.setContent(chartImage); img.setParent(div_chartArea); } else { div_chartArea.getChildren().clear(); Label label = new Label(); label.setValue("This customer have no data for showing in a chart!"); label.setParent(div_chartArea); } }
From source file:de.forsthaus.webui.customer.CustomerChartCtrl.java
/** * onClick button Stacked Bar 3D Chart. <br> * /*from www . ja va2 s . c om*/ * @param event * @throws IOException */ public void onClick$button_CustomerChart_StackedBar3D(Event event) throws InterruptedException, IOException { // logger.debug(event.toString()); div_chartArea.getChildren().clear(); // get the customer ID for which we want show a chart long kunId = getCustomer().getId(); // get a list of data List<ChartData> kunAmountList = getChartService().getChartDataForCustomer(kunId); if (kunAmountList.size() > 0) { DefaultCategoryDataset dataset = new DefaultCategoryDataset(); for (ChartData chartData : kunAmountList) { Calendar calendar = new GregorianCalendar(); calendar.setTime(chartData.getChartKunInvoiceDate()); int month = calendar.get(Calendar.MONTH) + 1; int year = calendar.get(Calendar.YEAR); String key = String.valueOf(month) + "/" + String.valueOf(year); BigDecimal bd = chartData.getChartKunInvoiceAmount().setScale(15, 3); String amount = String.valueOf(bd.doubleValue()); // fill the data dataset.setValue(new Double(chartData.getChartKunInvoiceAmount().doubleValue()), key + " " + amount, key + " " + amount); } String title = "Monthly amount for year 2009"; PlotOrientation po = PlotOrientation.VERTICAL; JFreeChart chart = ChartFactory.createStackedBarChart3D(title, "Month", "Amount", dataset, po, true, true, true); CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.setForegroundAlpha(0.5f); BufferedImage bi = chart.createBufferedImage(chartWidth, chartHeight, BufferedImage.TRANSLUCENT, null); byte[] bytes = EncoderUtil.encode(bi, ImageFormat.PNG, true); AImage chartImage = new AImage("Stacked Bar Chart 3D", bytes); Image img = new Image(); img.setContent(chartImage); img.setParent(div_chartArea); } else { div_chartArea.getChildren().clear(); Label label = new Label(); label.setValue("This customer have no data for showing in a chart!"); label.setParent(div_chartArea); } }
From source file:fr.ens.transcriptome.corsen.gui.qt.ResultGraphs.java
/** * Create a scatter plot//from w ww .jav a 2s.c o m * @param particles Particle data to use * @param title Title of the graph * @return a QImage */ public QImage createScatterPlot(final Particles3D particles, final String title, final String unit) { if (particles == null) return null; List<Particle3D> pars = particles.getParticles(); final int count = pars.size(); final double[][] data = new double[2][]; data[0] = new double[count]; data[1] = new double[count]; int i = 0; for (Particle3D p : pars) { data[0][i] = p.getIntensity(); data[1][i] = p.getVolume(); i++; } DefaultXYDataset xydataset = new DefaultXYDataset(); xydataset.addSeries("data", data); JFreeChart chart = ChartFactory.createScatterPlot(title, "Intensity", "Volume" + unitLegendCude(unit), xydataset, PlotOrientation.VERTICAL, false, true, false); addTransparency(chart); XYPlot xyplot = (XYPlot) chart.getPlot(); XYDotRenderer xydotrenderer = new XYDotRenderer(); xydotrenderer.setDotWidth(2); xydotrenderer.setDotHeight(2); xyplot.setRenderer(xydotrenderer); NumberAxis numberaxis = (NumberAxis) xyplot.getDomainAxis(); numberaxis.setAutoRangeIncludesZero(false); final BufferedImage image = chart.createBufferedImage(this.width, this.height, BufferedImage.TYPE_INT_ARGB, null); return new QImage(toByte(image.getData().getDataBuffer()), this.width, this.height, QImage.Format.Format_ARGB32); }
From source file:org.sipfoundry.sipxconfig.site.cdr.CdrReports.java
private Image createCallDirectionCallsPieImage(List<CdrGraphBean> beans) { // Create a dataset DefaultKeyedValuesDataset data = new DefaultKeyedValuesDataset(); // Fill dataset with beans data for (CdrGraphBean directionCall : beans) { data.setValue(directionCall.getKey(), directionCall.getCount()); }/*from w w w . j a v a2 s.co m*/ // Create a chart with the dataset JFreeChart chart = ChartFactory.createPieChart(EMPTY_TITLE, data, true, true, false); chart.setBackgroundPaint(Color.lightGray); chart.setTitle("Summary - " + getMessages().getMessage(TITLE_CALLDIRECTION_REPORT_KEY)); chart.getTitle().setPaint(Color.BLACK); PiePlot chartplot = (PiePlot) chart.getPlot(); chartplot.setCircular(true); chartplot.setLabelGenerator(new StandardPieSectionLabelGenerator(PIECHART_SECTIONLABEL_FORMAT)); // Create and return the image return chart.createBufferedImage(500, 220, BufferedImage.TYPE_INT_RGB, null); }