JSF Chart Creator Component Based on JFreeChart

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
Rasman
Posts: 5
Joined: Thu Sep 22, 2005 3:35 pm

MyFaces Integration

Post by Rasman » Thu Oct 27, 2005 10:38 am

Hi

I have tried new version and not been able to resolve the issues with the MyFaces integration.

Would appreciate any help, suggestions etc.

As a workaround I am currently using Cewolf's tag library for displaying the charts in my JSF app.

Cheers
Seamus

Maha

Post by Maha » Thu Oct 27, 2005 5:44 pm

Hi,
I am not using myFaces. But the issue is resolved: There needs to be an entry for the managed bean in faces-config.xml.
Also, does the current version support overlaid charts?

Thanks,
Maha

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

Post by cagatay_civici » Thu Oct 27, 2005 7:08 pm

Hi Maha,
can you post your solution so we can all see it, you said about an entry for the managed bean in the faces-config, can you post the entry example, is it the entry of the component or the backing bean of the page? So the problem is not related with the myFaces:) The component supports 10 charts but no overlaid charts. Can you show me an example of an overlaid chart, let me see if it is possible to support:)

shaggy

Two charts on one page

Post by shaggy » Mon Oct 31, 2005 5:59 pm

Hi, first of all thanks a lot for developing this very useful component !!

I have question: Is it somehow possible to display two different charts on one page? I've tried this:

<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<%@ taglib uri="/WEB-INF/tld/chartCreator.tld" prefix="c" %>


<html>
<f:view>
<c:chartCreator id="charter1"
title="Chart 1"
datasource="#{dataSource.categorySource}"
type="stackedbar"
is3d="true"
background="white"></c:chartCreator>

<c:chartCreator id="charter2"
title="Chart 2"
datasource="#{dataSource.pieSource}"
type="pie"
is3d="true"
background="white"></c:chartCreator>

</f:view>
</html>


The problem is that the second chart is displayed twice..
Any advice??

Cheers

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

Post by cagatay_civici » Mon Oct 31, 2005 7:30 pm

Hi shaggy,

I have tried two charts on a single page and as you said, the last chart is displayed, and the others are overwritten. The img is created by a chart servlet which looks at the session to get the attributes. Since the last chart's configuration is at the session, the servlet gives the same chart. I don't know if I can take care of this situtation but I will give it a try, thanks for reporting this:)

Çağatay Çivici
www.jroller.com/page/cagataycivici

georgc
Posts: 1
Joined: Thu Nov 03, 2005 5:24 pm

cagatay great initial component but I improved it a little

Post by georgc » Thu Nov 03, 2005 5:34 pm

I've been watching this post mainly because it always comes up when you search for jsf chart. cagatay you should really consider open source this project. I had to reverse engineer it to add stuff.... Sorry... anyway I rewrote how it passes parameters to your servlet in order to be able to display more then one chart in a page... I can send you java files if need be here is what I did.

In UICharter.java

Code: Select all

String id = (String)getAttributes().get("id");
        Object datasource = getAttributes().get("datasource");
        if(datasource != null)
            session.put(id, datasource);
		String title = (String)getAttributes().get("title");
		String type = (String)getAttributes().get("type");
		String width = (String)getAttributes().get("width");
		String height = (String)getAttributes().get("height");
		String background = (String)getAttributes().get("background");
		String xAxisLabel = (String)getAttributes().get("xAxisLabel");
		String yAxisLabel = (String)getAttributes().get("yAxisLabel");
		String orientation = (String)getAttributes().get("orientation");
            
        writer.write("<IMG SRC=\"" + projectName + "/servlet/ChartWriter?id="+id+"&title="+title+"&height="+height+"&width="+width+"&type="+type+"&orientation="+orientation+"&background="+background+"\" BORDER=1 WIDTH=" + width + " HEIGHT=" + height + "/>");
Then in doGet in ChartWriter servlet to get the values back...

Code: Select all

   HttpSession session = request.getSession();
  		String title = request.getParameter("title");
		String sWidth = request.getParameter("width");
		String sHeight = request.getParameter("height");
		String type = request.getParameter("type");
		String background = request.getParameter("background");
		String xAxisLabel = request.getParameter("xAxisLabel");
		String yAxisLabel = request.getParameter("yAxisLabel");
		String orientation = request.getParameter("orientation");
		String id = request.getParameter("id");
	   Object datasource = session.getAttribute(id);
		session.removeAttribute(id);
This allows as many charts as you want on a page as long as you define unique id's...
Anyway sorry about reversein your code but I figured I could help. I also made a few other enhancements to allow xydataset/time chart creation... post a reply if you have any questions.

Again great job so far hope this helps.
-Chris

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

Post by cagatay_civici » Thu Nov 03, 2005 11:15 pm

Hi Chris,

Actually you read my mind, in order to resolve this issue I've thought of a way that uses the request param instead of session param, the question annoying me was passing the datasource in the servlet url, I see that you solved this problem by giving a unique id to the session variable, what I think? Great solution :) Another thing is I am very very busy now, my time is shared by my job and another JSF component called "JSF Client Side Validators", JSF has no client side validations support so I have implemented a series of validator components to validate at client side. Since we have the solution now thanks to you Chris, I will change the code and add some new charts in the new version, which will come soon because I am almost finished with the validator components I mentioned. I think next week I will distribute the "open source" new version of "JSF Chart Creator".

Thanks for participating in the development,

Çagatay Çivici

Guest

Re: File "/WEB-INF/tld/chartCreator.tld" not found

Post by Guest » Fri Nov 04, 2005 10:01 am

satishbytes wrote:Hello cagatay_civici,

i am eagerly waiting to get this graph done...but the problem goes so..

javax.servlet.ServletException: java.lang.ClassNotFoundException: chartcreator.ChartWriter
javax.faces.webapp.FacesServlet.service(FacesServlet.java:125)


I got the above problem when i tried to acces the linechart.jsp file which containing the below code

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Code: Select all

<%@ page language="java" %>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<%@taglib uri="/WEB-INF/tld/chartCreator.tld" prefix="c" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
	
	
	<f:view>
	 	<c:chartCreator id="charter1" title="EXAMPLE CHART"
			       datasource="#{DBMgrChartcreator.source}"
			       type="line"
			       orientation="VERTICAL" 
                               background="white">
        </c:chartCreator>
	</f:view>
and my java bean is here




Code: Select all

import org.jfree.*;
import org.jfree.data.category.DefaultCategoryDataset;
import org.jfree.data.general.DefaultKeyedValueDataset;


public class DBMgrChartcreator  
{
	public DefaultCategoryDataset getChartcretor() throws Exception
	{
        String series1 = "A";
        String series2 = "B";
        String series3 = "C";
        //column keys...
        String category1 = "1990";
        String category2 = "1995";
        String category3 = "2000";
        String category4 = "2005";

		DefaultCategoryDataset source = new DefaultCategoryDataset();
		
		source.addValue(1 , series1, category1);
        source.addValue(2 , series1, category2);
        source.addValue(2.3 , series1, category3);
        source.addValue(3.2 , series1, category4);
        
        source.addValue(2.1 , series2, category1);
        source.addValue(3.5 , series2, category2);
        source.addValue(2 , series2, category3);
        source.addValue(4.5 , series2, category4);
        
        source.addValue(6 , series3, category1);
        source.addValue(4 , series3, category2);
        source.addValue(2 , series3, category3);
        source.addValue(5.3 , series3, category4);
       
        return source;
	}

}

i declared the bean in faces-config.xml file and also the component as u mentioned in the documentation...

even added the below code to web.xml file




Code: Select all

 <servlet>
        <servlet-name>ChartWriter</servlet-name>
        <servlet-class>chartcreator.ChartWriter</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>ChartWriter</servlet-name>
        <url-pattern>/servlet/ChartWriter</url-pattern>
    </servlet-mapping> 
 

and copied the all of the jars to lib and also to classpath..

its not serlvet project but its an EJB project... and i get the above error... saying it cant find the class chartcreater
javax.faces.FacesException: java.lang.ClassNotFoundException: chartcreator.ChartWriter

and even the tag is also not detected..

thanku verymuch for providing these kind of tags for free...

looking forward...
Satish, Germany.
xxx
PS: early response is appreciated..

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

Post by cagatay_civici » Fri Nov 04, 2005 10:37 am

Hi Satish,

Eveything seems fine and I have no idea where the problem occurs. Since the class is not found and the tag is not recognized there may be a problem that the jar files are not correctly referenced, because both of them are in the jar file.

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

Post by cagatay_civici » Sat Nov 12, 2005 1:43 pm

Hi everybody,

The new version of the JSF Chart Creator is coming soon, here are some new features;

* The component now supports a total of "27" charts.
* Anti-aliasing feature is added to the component.
* The bug that prevents more than one chart to be displayed is corrected. Now the users can display any number of charts.

I will distribute the component on my blog soon when I am finished with the testing;

Guest

Post by Guest » Sat Nov 12, 2005 7:35 pm

Hi again,

The new version 1.1 is out now, here is the supported chart list;

Pie Charts
3D Pie Charts
Bar Charts
Stacked Bar Charts
3D Bar Charts
3D Stacked Bar Charts
Area Charts
Stacked Area Charts
Line Charts
3D Line Charts
Waterfall Charts
Time Series Charts
XYLine Charts
Polar Charts
Ring Charts
Scatter Charts
XYArea Charts
XYStep Area Chart
XYStep Charts
Bubble Charts
Candle Stick Charts
Gantt Charts
Box and Whisker Charts
High and Low Charts
Histogram Charts
Signal Charts
Wind Charts

The new version also supports antialiasing and the more than one chart display issue is corrected. The new version can be found at;

http://www.jroller.com/page/cagataycivi ... rt_creator

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

Post by cagatay_civici » Sat Nov 26, 2005 12:07 pm

I don't know why but the link is not working; indeed it works,

You need to copy and paste the url the address bar, strangely direct click from the post does not work.

Leonardo_graf

Chartcreator 1.1 works on WL 8.1.4 with JSF 1_1_01

Post by Leonardo_graf » Tue Dec 13, 2005 10:22 pm

Hello

Just for your information, I tried the component V 1.1 on WebLogic 8.1 SP4 with the JSF Reference Implementation from Sun (V 1.1.01).

Everything seems to work fine.

Regards, Leo

lin

chartCreator not found

Post by lin » Wed Dec 14, 2005 2:13 am

Hello cagatay_civici,

My applicaiton is running under WSAD 5.1.2 and I have followed all the instructions on the doc, copy the three jars files under WEB-INF/lib and I have created the Managed Bean.
But the application just doesn't work.

your help is highly appreciated

Thanks

Lin

here is the error msg


WebGroup E SRVE0026E: [Servlet Error]-[Expression Error: Named Object: 'chartCreator' not found.]: javax.faces.FacesException: Expression Error: Named Object: 'chartCreator' not found.

here is my simple JSP file.

<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<%@ taglib uri="/WEB-INF/tld/chartCreator.tld" prefix="c" %>


<f:view>

<c:chartCreator id="charter1" title="EXAMPLE CHART"
datasource="#{helloBean.pieSource}" type="pie" is3d="yes"
background="white"></c:chartCreator>


</f:view>

JoeyBlow
Posts: 2
Joined: Tue Dec 20, 2005 12:34 am

Post by JoeyBlow » Wed Dec 21, 2005 10:16 pm

Hi,

Could you clarify whether this component is Open Source or not? The source doesn't appear to be available though SourceForge.

Thanks,
JB.

Locked