Board index JavaServer Faces General PrimeFaces Mobile + Chart

PrimeFaces Mobile + Chart

Components, Ajax Framework, Utilities and More.

Post 15 Nov 2011, 23:06

Posts: 11
Location: Brazil
Hello,

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

<pm:content>
       <p:lineChart value="#{chartBean.model}" legendPosition="e"/> 
</pm:content>

Into my bean has some random values...


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

Cheers!

JSF 2.0 and PrimeFaces 3.0.M4
Lucas FGC

JSF 2.0 and PrimeFaces 3.0.M4

Post 07 Apr 2012, 16:39

Posts: 1
You can use something like this:

See : http://www.primefaces.org/showcase-labs ... 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 java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
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.jfree.data.general.DefaultPieDataset;
import org.jfree.data.general.PieDataset;
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");

//Chart
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");

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

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;
}
}


Return to General