954,600 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

How to use JFreechart with JSP

Hi All,

I am using JSP and servlet technology for making graphs.

Below please find my jsps,

Display.jsp

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
 
<%@ page  import="java.awt.*" %>
<%@ page  import="java.io.*" %>
<%@ page  import="org.jfree.chart.*" %>
<%@ page  import="org.jfree.chart.axis.*" %>
<%@ page  import="org.jfree.chart.entity.*" %>
<%@ page  import="org.jfree.chart.labels.*" %>
<%@ page  import="org.jfree.chart.plot.*" %>
<%@ page  import="org.jfree.chart.renderer.CategoryItemRenderer" %>
<%@ page  import="org.jfree.chart.urls.*" %>
<%@ page  import="org.jfree.data.*" %>
<%@ page  import="org.jfree.data.CategoryDataset" %>
 
<%
  final double[][] data = new double[][]{{210, 300, 320, 265, 299},{200, 304, 201, 201, 340}};
 
 final CategoryDataset dataset = DatasetUtilities.createCategoryDataset("Team ", "", data);
 
 final JFreeChart chart = ChartFactory.createAreaChart("Area Chart", "", "Value", dataset, PlotOrientation.VERTICAL,true, true, false);
 
 final CategoryPlot plot = chart.getCategoryPlot();
 plot.setForegroundAlpha(0.5f);
 
 chart.setBackgroundPaint(new Color(249, 231, 236));
 
 try {
  final ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());
 
  //String sname = request.getRealPath("/");
	
	
	//sname = sname.concat("web/areachart.png");
	//out.println(sname);
	//file = new File(sname);
  
 //final File file1 = new File(sname);
 File file1 = new File("../webapps/jspGraphFunction/web/areachart.png");
 
 ChartUtilities.saveChartAsPNG(file1, chart, 600, 400, info);
  } catch (Exception e) {
  out.println(e);
  }
 
%>
 
<html>
  <head>
  <meta http-equiv="Content-Type" 
   content="text/html; charset=UTF-8">
  <title>JSP Page</title>
  </head>
  <body>
  <!-- <IMG SRC="areachart.png" WIDTH="600" HEIGHT="400" BORDER="0" 
   USEMAP="#chart">-->
   <IMG SRC="web/areachart.png" WIDTH="600" HEIGHT="400" BORDER="0" 
   USEMAP="#chart">
  </body>
</html>

Now its giving the below error for the bolded statement in the code:The method createAreaChart(String, String, String, CategoryDataset, PlotOrientation,
boolean, boolean, boolean) in the type ChartFactory is not applicable for the arguments
(String, String, String, CategoryDataset, PlotOrientation, boolean, boolean, boolean)

On net only this way of using the jfreechart is given

I have included the two jars Jfreechart... and jcommon in my lib folder.

Pls suggest,

Chandan

cmaheshwari16
Newbie Poster
18 posts since Sep 2010
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: