PrimeFaces Mobile + Chart

Components, Ajax Framework, Utilities and More.
Post Reply
Posts: 11
Joined: 14 Nov 2011, 03:32
Location: Brazil

15 Nov 2011, 23:06


I'm trying to make a simple example and it's not working...

I'd like to use PrimeFaces Mobile and some of the Charts provided by PrimeFaces.
But i'm getting just a blank page!

I've done this

Code: Select all

       <p:lineChart value="#{chartBean.model}" legendPosition="e"/>  
Into my bean has some random values...

Could someone help or just tell me if it works or not (mobile + chart) ??


JSF 2.0 and PrimeFaces 3.0.M4
Lucas FGC

JSF 2.0 and PrimeFaces 3.0.M4

Posts: 1
Joined: 07 Apr 2012, 16:31

07 Apr 2012, 16:39

You can use something like this:

See : ... cImage.jsf

<h3>JFreeChart on-the-fly</h3>
<p:graphicImage value="#{dynamicImageController.chart}" />

<h3>Barcode on-the-fly</h3>
<p:graphicImage value="#{dynamicImageController.barcode}" />

<h3>GraphicText on-the-fly</h3>
<p:graphicImage value="#{dynamicImageController.graphicText}" />

And the managedbean:

package org.primefaces.examples.view;

import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import javax.imageio.ImageIO;

import net.sourceforge.barbecue.BarcodeFactory;
import net.sourceforge.barbecue.BarcodeImageHandler;

import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartUtilities;
import org.jfree.chart.JFreeChart;
import org.primefaces.model.DefaultStreamedContent;
import org.primefaces.model.StreamedContent;

public class DynamicImageController {

private StreamedContent graphicText;

private StreamedContent barcode;

private StreamedContent chart;

public DynamicImageController() {
try {
//Graphic Text
BufferedImage bufferedImg = new BufferedImage(100, 25, BufferedImage.TYPE_INT_RGB);
Graphics2D g2 = bufferedImg.createGraphics();
g2.drawString("This is a text", 0, 10);
ByteArrayOutputStream os = new ByteArrayOutputStream();
ImageIO.write(bufferedImg, "png", os);
graphicText = new DefaultStreamedContent(new ByteArrayInputStream(os.toByteArray()), "image/png");

JFreeChart jfreechart = ChartFactory.createPieChart("Turkish Cities", createDataset(), true, true, false);
File chartFile = new File("dynamichart");
ChartUtilities.saveChartAsPNG(chartFile, jfreechart, 375, 300);
chart = new DefaultStreamedContent(new FileInputStream(chartFile), "image/png");

File barcodeFile = new File("dynamicbarcode");
BarcodeImageHandler.saveJPEG(BarcodeFactory.createCode128("PRIMEFACES"), barcodeFile);
barcode = new DefaultStreamedContent(new FileInputStream(barcodeFile), "image/jpeg");
} catch (Exception e) {

public StreamedContent getBarcode() {
return barcode;

public StreamedContent getGraphicText() {
return graphicText;

public StreamedContent getChart() {
return chart;

private PieDataset createDataset() {
DefaultPieDataset dataset = new DefaultPieDataset();
dataset.setValue("Istanbul", new Double(45.0));
dataset.setValue("Ankara", new Double(15.0));
dataset.setValue("Izmir", new Double(25.2));
dataset.setValue("Antalya", new Double(14.8));

return dataset;

Post Reply
  • Information
  • Who is online

    Users browsing this forum: Baidu [Spider], Google [Bot] and 4 guests