Swiff Chart Generator offers you the ability to rapidly incorporate dynamic charts into your JSP pages. To do so, you simply have to install Swiff Chart Generator on your Web Application Server machine and publish along with your JSP pages the complementary Jar archive named SwiffChart.jar installed with the product.
To insert a dynamic chart into a JSP page, follow the steps below:
<%@ page import="com.globfx.swiffchart.SwiffChart" %>see code sample
String installation_dir= "C:\\Program Files\\GlobFX\\Swiff Chart Generator 4"; SwiffChart chart= new SwiffChart(installation_dir);see code sample
String web_root= "C:\\tomcat\\webapps\\ROOT"; chart.SetServletInfo(request,response); chart.SetDocumentRoot(web_root);see code sample
Important Note: Make sure that all the steps detailed above are fully completed before running your JSP page. If these parameters are not set with the correct values, the chart generation will fail. Furthermore, the chart object should be released with the Release() method after use.
The following JSP sample code illustrates the use of Swiff Chart Generator in a JSP page. This code is cross-platform, only the various pathnames must be modified.
<%@ page import="com.globfx.swiffchart.SwiffChart" %> <% // Prior to any chart object instanciation, you must specify the full pathname of Swiff Chart Generator // installation directory as well as the full pathname of the Web Application Server root directory. String installation_dir= "C:\\Program Files\\GlobFX\\Swiff Chart Generator 4"; String web_root= "C:\\tomcat\\webapps\\ROOT"; // Create a new Swiff Chart object SwiffChart chart= new SwiffChart(installation_dir); // JSP Init chart.SetServletInfo(request,response); chart.SetDocumentRoot(web_root); String sep= ";"; boolean ignoremultseparators= true; chart.SetSeparators(sep, ignoremultseparators); // Fill the categories String categories= "Q1" + sep + "Q2" + sep + "Q3" + sep + "Q4"; chart.SetCategoriesFromString(categories); // Fill the first series named "Sales Y1" String series1= "12" + sep + "11" + sep + "6" + sep + "9"; chart.SetSeriesValuesFromString(0, series1); chart.SetSeriesCaption(0, "Sales Y1"); // Fill the second series named "Sales Y2" String series2= "23" + sep + "12" + sep + "8" + sep + "11"; chart.SetSeriesValuesFromString(1, series2); chart.SetSeriesCaption(1, "Sales Y2"); // Set the chart title chart.SetTitle("Financial Results"); chart.SetSubtitle("(Values in M$ - Year to year results)"); // Apply a Column style // The chart type is stored in the style file (*.scs) // Here the selected style is the predefined column style "SanFrancisco" chart.LoadStyle( "column/SanFrancisco" ); chart.SetLooping( false ); String chart_res= chart.GetHTMLTag(); // Release the chart object chart.Release(); %> <H1>Column Chart</H1> <br><% out.println(chart_res); %>
What you will obtain
The SwiffChart.jar archive is located in the Swiff Chart Generator installation directory:
<install dir>/resources/java/SwiffChart.jarwhere <install dir> is Swiff Chart Generator installation directory, usually C:/Program Files/GlobFX/Swiff Chart Generator 4/ on windows and /usr/local/SwiffChart for Unix.