Jump to content
Software FX Community

Creating Chart using beans.


Wilfred

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.

 

try{

//gets context path

FacesContext facesContext = FacesContext.getCurrentInstance();

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

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

 

ChartServer chart1 = new ChartServer();

System.

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++)

{

chart1.getSeries().getItem(i).setLegend(java.lang.Integer.toString(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));

}

chart1.closeData(COD.VALUES);

 

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

chart1.setAngleX((

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

chart1.setView3D(

true);chart1.setChart3D(true);chart1.setGallery(Gallery.SURFACE);

 

//General Cosmetic Settings for Gallery type, Colors

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

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

series.setAlternateColor(

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

 

chart1.getUserLegendBoxObj().setAutoContourLabels(true);

//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();

mySurface.setShowBorders(true);

 

chart1.setImgMap(ImgMap.TITLE_TIP);

chart1.setSmoothFlags(SmoothFlags.

FILL | SmoothFlags.BORDER);dealchart = chart1;

}

catch (Exception e) {

e.printStackTrace();

}

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.

chart1.getHtmlTag("450","280","SVG");

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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...