aspose file tools*
The moose likes Other Open Source Projects and the fly likes JFree chart display in JSF page Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Products » Other Open Source Projects
Bookmark "JFree chart display in JSF page" Watch "JFree chart display in JSF page" New topic
Author

JFree chart display in JSF page

Roshnara Rose
Greenhorn

Joined: Nov 08, 2005
Posts: 15
Hi,

I have configured JFree chart for my charting purpose and could plot the bar chart using <c:chart> tag and CategoryDataset. Now i would like to customize the chart from my backing bean and display in jsf page. But i'm getting
" org.jfree.chart.JFreeChart@133c2d2 " in the page while displaying.
Following the code for generating the chart

JFreeChart freeChart = ChartFactory.createBarChart("", "Y Axis", "X Axis", pieDataSet, PlotOrientation.HORIZONTAL, false, true, false);
CategoryPlot categoryplot = (CategoryPlot)freeChart.getPlot();
categoryplot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);
categoryplot.setDomainGridlinesVisible(true);
BarRenderer barrenderer = (BarRenderer)categoryplot.getRenderer();
barrenderer.setDrawBarOutline(false);
GradientPaint gradientpaint = new GradientPaint(0.0F, 0.0F, Color.blue, 0.0F, 0.0F, new Color(0, 0, 64));
barrenderer.setSeriesPaint(0, gradientpaint);
//ChartRenderingInfo barRenderInfo = new ChartRenderingInfo();
//freeChart.createBufferedImage(300, 400, barRenderInfo);
outputComponent = new UIOutput();
outputComponent.setValue(freeChart);
dataPanel.getChildren().add(outputComponent);
dataPanel.setRendered(true);

I'm pretty new to JSF. Please advice how i can display the customized graph from the bean.

Thanks in advance.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39575
    
  27
What is this "c:chart" tag? Some kind of 3rd party tag library? I don't think JSF has built-in JFreeChart support, does it?


Ping & DNS - updated with new look and Ping home screen widget
Roshnara Rose
Greenhorn

Joined: Nov 08, 2005
Posts: 15
in jsf, c points to the Jfree chart taglib

<jsp:root xmlns:c="http://sourceforge.net/projects/jsf-comp>

and i had used

<c:chart id="chart1" datasource="#{backBean.pieDataSet}" type="bar" is3d="false" orientation="horizontal" colors="blue" antialias="false" height="250" width="500"></c:chart>

The pieDataSet is the DefaultCategoryDataset to display the bar graph.
I could display the chart using this. Now i want more customization on the graph.

For Jfree chart support, I have included all needed jars (chartcreator, jfreechart & jcommon) in the app.

Regards,
Rose
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39575
    
  27
OK, so you are using a 3rd party charting component called jsf-comp.
The fact that you were able to pass a DataSet parameter in the datasource attribute makes me think that you can't substitute a JFreeChart instead, which is a completely different beast. Have you seen anything that indicates this should be possible?
Roshnara Rose
Greenhorn

Joined: Nov 08, 2005
Posts: 15
I'm trying to build the UI from the bean. For that i can't use the <c:chart> tag as it offers only limited customization.
In the code i'm getting the <h anelGrid id="barGraph") and trying to add the chart as a child to it.

UIForm form = (UIForm) context.getViewRoot().findComponent("topTenForm");
UIPanel dataPanel = (UIPanel) form.findComponent("barGraph");
dataPanel.getChildren().clear();

My doubt is here

outputComponent = new UIOutput();
outputComponent.setValue(freeChart);
dataPanel.getChildren().add(outputComponent);

Can i add the JfreeChart to panelGrid like this?
I have sample codes using awt. But none from JSF. I searched for long time but didn't get some useful stuffs.
I have noted one thread in this forum but that's with jsp.
http://www.coderanch.com/t/414194/JSP/java/display-Buffered-Image-object-jsp

Is there anyway to use that in JSF?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39575
    
  27
I'd be very surprised if the JSF tags knew what to do with a JFreeChart component. That's what that library is for, after all.

My preferred way of including JFreeChart images in JSPs is the cewolf library, which is linked in my signature. It has a number of so-called "post processors" that can be used to customize charts; if none of those do what you need, then it's not hard to write your own.
Roshnara Rose
Greenhorn

Joined: Nov 08, 2005
Posts: 15
Hi,

I could generate the byte[] for the jfreechart image. Right now i'm looking for an option to render this byte[] as an image in jsf page.

The code follows
JFreeChart freeChart = ChartFactory.createBarChart("", "Y Axis", "X Axis", pieDataSet, PlotOrientation.HORIZONTAL, false, true, false);
CategoryPlot categoryplot = (CategoryPlot)freeChart.getPlot();
categoryplot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);
categoryplot.setDomainGridlinesVisible(true);
BarRenderer barrenderer = (BarRenderer)categoryplot.getRenderer();
barrenderer.setDrawBarOutline(false);
GradientPaint gradientpaint = new GradientPaint(0.0F, 0.0F, Color.blue, 0.0F, 0.0F, new Color(0, 0, 64));
barrenderer.setSeriesPaint(0, gradientpaint);
ChartRenderingInfo barRenderInfo = new ChartRenderingInfo();
BufferedImage image = freeChart.createBufferedImage(300, 400, barRenderInfo);
byte[] imgByte = ChartUtilities.encodeAsPNG(image);

How i can display this byte[] as image using HtmlGraphicImage?

B/w i'm checking on the cewlof for the same. But if i can make any progress in this , that will be more appreciated.

Thanks,
tester testser
Greenhorn

Joined: Dec 11, 2008
Posts: 1
I have the same problem where the chart is not being displayed in a JSF page. I see org.jfree.chart.JFreeChart@133c2d2 " in the page source while
displaying.

Were you able to fix this problem? Please share any ideas that I can use

Thanks
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39575
    
  27
Hello "tester testser "-

Welcome to JavaRanch.

On your way in you may have missed that we have a policy on screen names here at JavaRanch. Basically, it must consist of a first name, a space, and a last name, and not be obviously fictitious. Since yours does not conform with it, please take a moment to change it, which you can do right here.

As to your question, how are you trying to display the chart? A chart image (or a JFreeChart object) is not something you can output from a JSP/JSP page. You need to embed an <img> link that points to an URL where an image generated from that chart can be gotten. A library like cewolf (or apparently "jsf-comp") can do this for you.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JFree chart display in JSF page
 
Similar Threads
Displaying scalable vector graphics on ibm aix
Barchart diagrams in jsp
de.flaures.cewolf.PreProcessorException Error.
JFreeChart: Need to change starting of bar point
jfreechart bar chart - show item value