JSF Chart Creator Component Based on JFreeChart

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
talonjj
Posts: 6
Joined: Tue Jul 25, 2006 10:08 pm

MyFaces and the JSF Chart Creator Component

Post by talonjj » Thu Jul 27, 2006 5:33 pm

Ok, I have a working project with the JSF RI but I'd like to set it up with MyFaces instead to be able to use the panelLayout and panelStack components. I've set everything up and tried to run the same project without any changes to the page and I'm getting this error:

Code: Select all

java.lang.NoClassDefFoundError: com.sun.faces.taglib.jsf_core.ViewTag
I've traced this class back to the JSF RI but it is something else in MyFaces.
I'm not absolutely sure but I think this is caused by the call to the JSF ChartCreator tag.
If that's the case would this mean that this component can only be used with the Reference Implementation?

Any suggestions would be helpful!

Thanks!

cagatay_civici
Posts: 54
Joined: Sun Aug 28, 2005 8:13 pm

Post by cagatay_civici » Fri Jul 28, 2006 6:47 am

I've stated the required mappings in the doc;

http://jsf-comp.sourceforge.net/compone ... index.html

Either /faces/* or *.jsf can be used. The reason is, instead of a servlet a jsf phaselistener is used to create the charts. So there is no need to make a servlet configuration. I'll also take *.faces into account in the upcoming releases.

Also I've tested the component with MyFaces and RI, there is no problem with the compatibility. What have you done to bring myfaces to your project? Which jars did you include? The components you mentioned are in tomahawk.

talonjj
Posts: 6
Joined: Tue Jul 25, 2006 10:08 pm

Post by talonjj » Fri Jul 28, 2006 10:13 pm

cagatay_civici wrote:I've stated the required mappings in the doc;

http://jsf-comp.sourceforge.net/compone ... index.html

Either /faces/* or *.jsf can be used. The reason is, instead of a servlet a jsf phaselistener is used to create the charts. So there is no need to make a servlet configuration. I'll also take *.faces into account in the upcoming releases.
Yeah, I figured out that *.faces doesn't work and everything works fine now with the /faces/* mapping.
cagatay_civici wrote:Also I've tested the component with MyFaces and RI, there is no problem with the compatibility. What have you done to bring myfaces to your project? Which jars did you include? The components you mentioned are in tomahawk.
The problem was my mistake I believe and MyFaces documentation problems. Every single MyFaces web.xml file that I could find on the internet showed the FacesServlet coming from the net.sourceforge.... package. I basically used those xml files to try and get a sample MyFaces working but none of them did. I finally figured out, after delving into the package structure of he newest download of the MyFaces core impl and api packages, that the FacesServlet is contained in the org.apache.myfaces.webapp..... packages. After I changed my web.xml file and added the commons-codec library that I had forgot the webapp worked fine. I don't have the source with me right now but it is working and I'll post it when I can. I haven't added the Tomahawk portion yet but right now I just wanted to get it working with the MyFaces implementation. Next step...include the Tomahawk extensions and add the components I want.

Thanks for your help and keep up the good work on this project!

Question: Is there a way to include tooltips for the charts? If so, are they customizable?

talonjj
Posts: 6
Joined: Tue Jul 25, 2006 10:08 pm

image map question

Post by talonjj » Thu Aug 03, 2006 4:17 pm

I'm needing a little help implementing the usemap attribute of the ChartCreator component. I've already coded everything and gotten my application to create the display the tooltips but it seems that the positions are inaccurate. For example, I have a pie chart on the screen and the tooltips don't match up to the correct sections of the chart. I have another chart that's a bar chart and the tool tip doesn't reach all the way to the end of the bar.

Here's the code that creates the ChartRenderingInfo and the assosicated maps:

Code: Select all

JFreeChart piechart = ChartFactory.createPieChart3D("", pie, true, true, false);
ChartRenderingInfo pieRenderInfo = new ChartRenderingInfo();
piechart.createBufferedImage(300, 400, pieRenderInfo);
piechart = null;

JFreeChart barchart = ChartFactory.createBarChart3D("", "", "", bar, PlotOrientation.HORIZONTAL, true, true, false);
ChartRenderingInfo barRenderInfo = new ChartRenderingInfo();
barchart.createBufferedImage(300, 400, barRenderInfo);
barchart = null;
Here's the charts and maps created by the web page:

Code: Select all

<img id="appChartPages:0:chartForm:piechart" width="400" height="300" src="chartcreatorrequest.jsf?ts=1154617795620&id=appChartPages:0:chartForm:piechart" onclick="alert('pie chart clicked');" usemap="#pieImageMap_app_INBOUND" /><map id="pieImageMap_app_INBOUND" name="pieImageMap_app_INBOUND">
<area shape="poly" coords="101,89,111,73,123,61,136,54,150,51,150,150,150,150" title="WT2 = 1" alt=""/>
<area shape="poly" coords="89,172,88,150,89,128,94,108,101,89,150,150,150,150" title="AHL = 1" alt=""/>
<area shape="poly" coords="210,172,207,189,202,203,196,217,188,228,180,237,170,244,160,248,150,249,139,248,129,244,119,237,111,228,103,217,97,203,92,189,89,172,150,150,150,150" title="TLO = 3" alt=""/>
<area shape="poly" coords="198,89,205,108,210,128,211,150,210,172,150,150,150,150" title="TRF = 1" alt=""/>
<area shape="poly" coords="150,51,163,54,176,61,188,73,198,89,150,150,150,150" title="CCN = 1" alt=""/>
</map>

<img id="appChartPages:0:chartForm:barchart" width="400" height="300" src="chartcreatorrequest.jsf?ts=1154617795620&id=appChartPages:0:chartForm:barchart" onclick="alert('bar chart clicked');" usemap="#barImageMap_app_INBOUND" />
<map id="barImageMap_app_INBOUND" name="barImageMap_app_INBOUND">
<area shape="poly" coords="16,127,16,47,28,39,279,39,279,119,267,127,267,127" title="(Contact Rate, ) = 100" alt=""/>
</map>
Also, I'd like to change the format of the tooltips and I'm assuming this is done by changing the format in the ...ToolTipGenerator of the associated chart/dataset/plot object before creating the ChartRenderingInfo. is this correct?

Thanks for any and all help! :P

raindogs
Posts: 1
Joined: Thu Nov 16, 2006 4:04 pm

Post by raindogs » Thu Nov 16, 2006 4:17 pm

HI all,

Thanks a lot for the work on Chart Creator, it's been a real life-saver.

I'm just setting up a basic timesheet chart for the first time. Everything works great except for one simple thing - how do I show the individual data point on the chart? At the moment my x and y are coming out fine and I have a line following all of the points, but I would like to put dots on the chart showing actual data points. Is there a way to do this?

Here's my JSF code:

Code: Select all

<x:chart id="SigTimeChart" datasource="#{fieldsigs.timeDataset}" type="timeseries" background="#e0e0e0" title="Signature Chart" output="png" legend="true" xlabel="Date/Time" ylabel="Signature Value" width="500"></x:chart>

And here's the relevant code from the bean:

Code: Select all

	public XYDataset getTimeDataset(){
		TimeSeries sigs = new TimeSeries( "Signature Reading", Second.class );

	    	Statement stmt = conn.createStatement();
	         res = stmt.executeQuery("select signature, date_created from signature where id= '2'");

	         // load up the timesreies with the query results
	         while (res.next()) {
	        	 sigs.add(new Second(res.getTimestamp("date_created")), res.getDouble("signature"));
		         }
		
		TimeSeriesCollection sigsFinal = new TimeSeriesCollection();
		sigsFinal.addSeries( sigs );
			
		return (XYDataset) sigsFinal;
	}
	

stuartianmac
Posts: 4
Joined: Sun Dec 03, 2006 12:57 am

Post by stuartianmac » Sun Dec 03, 2006 1:09 am

Hi,

I am using chartcreator in IBM implementation JSF in a Portal environment, and I am getting a rather confusing error.

I read that the latest version of chatcreator now utilises a JSF phase listener to generate the charts, but I cannot see the registration of this phase-listener in the example application's faces-config.xml. Also, I read that the FacesServlet and its mappings are no longer required, yet these do appear to be present in the example application.

When I run my portlet on Websphere Portal Server and the code to generate the chart is invoked, it gives the following error:

Code: Select all

[02/12/06 23:46:30:016 GMT]  1ea82a6 PortalServer  W com.ibm.wps.engine.Servlet doGet() Invalid URL '{i'm not allowed URLs}/!ut/p/kcxml/04_Sj9SPykssy0xPLMnMz0vM0Y_QjzKLN4g3cjIGSUGYRvqRGGKGGGKOCBFfj_zcVKB4pDlIwMNdP0Q_0lk_SN9bP0C_IDc0NKLc0MLRUVERAMx1Iig!/chartcreatorrequest.jsf'
[02/12/06 23:46:30:094 GMT]  1ea82a6 PortalServer  W com.ibm.wps.engine.Servlet doGet() class com.ibm.wps.state.nls.exceptions.NlsCannotInterpretCodecException: EJPEI0073E: The input mediator class com.ibm.wps.state.inputmediators.WPInputMediator@305791741 could not interpret codec chartcreatorrequest.jsf for request com.ibm.wps.engine.PortalRequestWrapper@731cc306.
This appears to suggest that it something is directing to chartcreatorrequest.jsf, which is a servlet mapping (*.jsf) to the FacesServlet and would probably have been ok to configure had I been in a servlet environment.

I can see in the ChartListener class that there is some code that is designed to determine whether it is being run in a servlet or portlet environment, but I feel the issue can be cause by one of three things:

1. ChartListener is not used, and thus the environment check is never executed. The old-style servlet method is therefore taking precedence.
2. IBM's portlet implementation is not supported in the environment check code, and the code is thus using servlet method.
3. Something else! I have checked classpath and read up as much as I can, but there is not a lot of documentation surrounding this issue.

If anyone has any ideas about what I can do, then that would be great. I have considered factoring chart generation out to a straight webapp in a totally separate EAR to do the servlet env stuff, but it seems a clunky way to solve this issue, now that I see people on this thread mention that 1.2.0RC1 has portlet support and is tested in IBM env's.

Any feedback would be much appreciated.

Many thanks
Stuart

gio14
Posts: 1
Joined: Mon Dec 04, 2006 11:58 am

Post by gio14 » Mon Dec 04, 2006 12:00 pm

Hi all,
I'm working on JSC (Java Studio Creator 2update1), I need to create some line charts, is there any way to get it work on JSC?? if so, could someone please tell me how to get it work??

thanks

stuartianmac
Posts: 4
Joined: Sun Dec 03, 2006 12:57 am

Post by stuartianmac » Mon Dec 04, 2006 8:01 pm

Referencing my post 3/12/2006, I have engineered chartcreator out completely, and used JFreeChart alone. That way I am able to delegate to a servlet in the portlet WAR referenced in my JSF by url as decreed and portlet encoded in the backing-bean, referencing only a small piece of information in the APPLICATION_SCOPE session in the servlet code. The servlet then does the rest of the work, and writes a JPEG chart to the response stream.

It's a shame I couldn't get chartcreator to work in an IBM portlet environment, as it would have been a cleaner solution, but JFreeChart is far better documented.

Dileep
Posts: 2
Joined: Fri Dec 08, 2006 8:16 pm
Location: MA

Issue with implementing Jfree chart in myfaces portlet

Post by Dileep » Fri Dec 08, 2006 8:26 pm

Hi,

I am working on implementing a JFree chart in my jsf application but facing some issues when I deploy the application in JBoss-Liferay-Tomcat bundle. I use the image tag in my main jsp to point to another jsp(chart.jsp) which contains the API call for JFree chart.
But there is change in context when the request is delegated the chart.jsp, meaning the context switches from portletContext to Servlet Context. I tested this out by printing the request and session types. This way i am not able to access the objects from Session and request and hence not able to generate the chart.

BTW, Stuartianmac can you please let me know how you generated a portlet encoded URL for the servlet in the Backing bean.

Please someone help me out in this!

Thanks,
Dlieep

stuartianmac
Posts: 4
Joined: Sun Dec 03, 2006 12:57 am

Re: Issue with implementing Jfree chart in myfaces portlet

Post by stuartianmac » Fri Dec 08, 2006 10:36 pm

Dileep wrote:Hi,

I am working on implementing a JFree chart in my jsf application but facing some issues when I deploy the application in JBoss-Liferay-Tomcat bundle. I use the image tag in my main jsp to point to another jsp(chart.jsp) which contains the API call for JFree chart.
But there is change in context when the request is delegated the chart.jsp, meaning the context switches from portletContext to Servlet Context. I tested this out by printing the request and session types. This way i am not able to access the objects from Session and request and hence not able to generate the chart.

BTW, Stuartianmac can you please let me know how you generated a portlet encoded URL for the servlet in the Backing bean.

Please someone help me out in this!

Thanks,
Dlieep

Yes you won't really be able to get round this it seems unless you either use a servlet to return a stream of encoded bytes thus we are context-agnostic (what I did to solve the issue), or utilise the session at APPLICATION_SCOPE (portal has access to this), which I guess is can be unsafe.

in a JSR168 portlet jsf URLs can only be referenced by encoding them, in this type of way:

Code: Select all

<%= renderResponse.encodeURL(renderRequest.getContextPath() + "/
	    YourServlet") %>
renderResponse and renderRequest are implicits.

Stuart

Dileep
Posts: 2
Joined: Fri Dec 08, 2006 8:16 pm
Location: MA

Post by Dileep » Tue Dec 12, 2006 12:39 am

Thanks for your reply Stuart.

But I still face the same issue as these RenderRequest and RenderResponse objects are not implicit objects in case of liferay server and they have to be obtained from Http request and response objects respectively which brings me back to the square one.

Here is a code snippet from my main jsp :

<IMG SRC='<%=request.getContextPath()%>/chart.jsp' BORDER=2>

chart.jsp
----------
<% here goes the API call to JFree chart which writes down the image to the servlet output stream %>

But since chart.jsp is in a different context (Servlet) than that of the main jsp (Portlet Context) I am not able to access the data available to the main jsp.

Please let me know if some one has a solution for this.

Thanks

stuartianmac
Posts: 4
Joined: Sun Dec 03, 2006 12:57 am

Post by stuartianmac » Tue Dec 12, 2006 9:47 am

Dileep wrote: I still face the same issue as these RenderRequest and RenderResponse objects are not implicit objects in case of liferay server...
There is a static method on com.liferay.util.Http called encodeURL(String). I know nothing about Liferay, I just found that on a relatively quick Google search. I'm afraid I am unsure as to whether that is the sort of thing you will need.

cozytom
Posts: 4
Joined: Fri Jun 30, 2006 7:42 pm

Newest Release

Post by cozytom » Thu Dec 14, 2006 6:10 pm

cagatay,

It looks like you have done some fixes, since the RC1, in June. Do you have a newer release?

Thanks

netstat
Posts: 1
Joined: Sat Dec 23, 2006 5:29 pm

Post by netstat » Sat Dec 23, 2006 5:34 pm

Dileep wrote:Thanks for your reply Stuart.

But I still face the same issue as these RenderRequest and RenderResponse objects are not implicit objects in case of liferay server and they have to be obtained from Http request and response objects respectively which brings me back to the square one.

Here is a code snippet from my main jsp :

<IMG SRC='<%=request.getContextPath()%>/chart.jsp' BORDER=2>

chart.jsp
----------
<% here goes the API call to JFree chart which writes down the image to the servlet output stream %>

But since chart.jsp is in a different context (Servlet) than that of the main jsp (Portlet Context) I am not able to access the data available to the main jsp.

Please let me know if some one has a solution for this.

Thanks
Check out the polls portlet that is bundled with lifefay. It uses jfreechart. I think you need to include the jfreechart jar in your portlet WEB-INF/lib.

honza
Posts: 3
Joined: Sat Apr 07, 2007 10:26 am

xy chart help

Post by honza » Sat Apr 07, 2007 10:36 am

Hello,

I would like to use this wonderful component in my jsf project. But I am not able to get it work - the xyline type. I have a working page with jFreeChart. But with this component I do not how to set the datasource. I tried to use objects of types: XYSeries and XYSeries[]. It does not work.

Thank you for help.
Jan

Locked