Jump to content
Software FX Community

Creating Chart using beans.


Recommended Posts

Hi i am acutally tring to create and display an image using a session bean.

Here is the code of the method responsable of creating the image.



//gets context path

FacesContext facesContext = FacesContext.getCurrentInstance();

ServletContext servletContext = (ServletContext) facesContext.getExternalContext().getContext();

String docBase = servletContext.getRealPath(".");


ChartServer chart1 = new ChartServer();


out.println("getChart() "+docBase + File.separator+"data"+File.separator+"samples.cfx"); chart1.importChart(FileFormat.XML, docBase + File.separator+"data"+File.separator+"samples.cfx");


chart1.openData(COD.VALUES,20,20);for(int i=0; i < 20; i++)



for(int j = 0; j < 20; j++)

chart1.getValue().setItem(i, j, ((java.lang.Math.sin((i * 2 * 3.1416) / 19) * java.lang.Math.cos(((j + 5) * 2 * 3.1416) / 19)) * 100));




//3D Settingschart1.setView3DDepth((short) 60);


short) 20);chart1.setAngleY((short) 35);




//General Cosmetic Settings for Gallery type, Colors

SeriesAttributes series = chart1.getSeries().getItem(0);

series.setColor(new java.awt.Color(15, 213, 239));


new java.awt.Color(1, 128, 1));series.setBorderEffect(BorderEffect.DARK);



//You should use SetContourLabels to specify the range of values to appear on the user legend

//Make sure that you set this property after you have passed your data and set your colors


Surface mySurface = (Surface) chart1.getGalleryObj();





FILL | SmoothFlags.BORDER);dealchart = chart1;


catch (Exception e) {



System.out.println(dealchart.getHtmlTag());return dealchart.getHtmlTag();




No matter what i do the response by this methos is always "IMAGE" . I am not really sure where should where to locate the temp folder where the image is supposed to be stored. I am using a .ear application . The image is not being created. What it is wrong ?





Link to comment
Share on other sites

No, it is not ok to use an empty constructor.  ChartServer needs the Context, Request and Response objects to properly function on an application server.  Since it seems you are using JSF, you can get all that from the FacesContext, something like this:

javax.faces.context.FacesContext context = javax.faces.context.FacesContext.getCurrentInstance();

javax.faces.context.ExternalContext extCtx = context.getExternalContext();

ChartServer chart1 = new ChartServer((javax.servlet.ServletContext)extCtx.getContext(), (javax.servlet.http.HttpServletRequest)extCtx.getRequest(), (javax.servlet.http.HttpServletResponse)extCtx.getResponse());

Chart FX uses ChartFX.Internet.config file to determin where is the temp folder.  Plese review the section "Getting Started../Instalaltion and Activation" in the documentation for more detail.

 Finally, calling getHtmlTag with no parameter will give you a 200x200 PNG image, use the parameters if you want something else, i.e.


Furthermore, if you are doing JSF, take a look to the Chart FX JSF conmponent, the are severl samples included with the product.


Link to comment
Share on other sites


This topic is now archived and is closed to further replies.

  • Create New...