[b]isaiaspf ,
Na verdade fiz como você sugeriu, mesmo assim dá o erro acima.
Revi tudo várias vezes…e nada.
Segue os códigos:
[/b]
Servlet:
package codigo;
import java.io.Serializable;
import java.util.Date;
import java.util.Map;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jfree.data.category.CategoryDataset;
import org.jfree.data.category.DefaultCategoryDataset;
import de.laures.cewolf.DatasetProduceException;
import de.laures.cewolf.DatasetProducer;
import de.laures.cewolf.links.CategoryItemLinkGenerator;
import de.laures.cewolf.tooltips.CategoryToolTipGenerator;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class PageViewCountData extends HttpServlet implements DatasetProducer, CategoryToolTipGenerator, CategoryItemLinkGenerator, Serializable {
private static final Log log = LogFactory.getLog(PageViewCountData.class);
// These values would normally not be hard coded but produced by
// some kind of data source like a database or a file
private String[] categories = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"};
private String[] seriesNames = {"Equação Afim"};
private float a;
private float b;
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
// processRequest(request, response);
a = Float.parseFloat(request.getParameter("a"));
b = Float.parseFloat(request.getParameter("b"));
response.sendRedirect("grafico.jsp");
}
public Object produceDataset(Map params) throws DatasetProduceException {
log.debug("producing data.");
DefaultCategoryDataset dataset = new DefaultCategoryDataset() {
/**
* @see java.lang.Object#finalize()
*/
protected void finalize() throws Throwable {
super.finalize();
log.debug(this + " finalized.");
}
};
for (int series = 0; series < seriesNames.length; series++) {
for (int i = 0; i < categories.length; i++) {// i aqui equivale ao meu x da equação afim
final int y = (int) ((a * i) + b);
dataset.addValue(y, seriesNames[series], categories[i]);
}
}
return dataset;
}
/**
* This producer's data is invalidated after 5 seconds. By this method the
* producer can influence Cewolf's caching behaviour the way it wants to.
*/
public boolean hasExpired(Map params, Date since) {
log.debug(getClass().getName() + "hasExpired()");
return (System.currentTimeMillis() - since.getTime()) > 5000;
}
/**
* Returns a unique ID for this DatasetProducer
*/
public String getProducerId() {
return "PageViewCountData DatasetProducer";
}
/**
* Returns a link target for a special data item.
*/
public String generateLink(Object data, int series, Object category) {
return seriesNames[series];
}
/**
* @see java.lang.Object#finalize()
*/
protected void finalize() throws Throwable {
super.finalize();
log.debug(this + " finalized.");
}
/**
* @see org.jfree.chart.tooltips.CategoryToolTipGenerator#generateToolTip(CategoryDataset, int, int)
*/
public String generateToolTip(CategoryDataset arg0, int series, int arg2) {
return seriesNames[series];
}
}
Formulário:
<%--
Document : formulario
Created on : 08/07/2011, 11:34:34
Author : studant
--%>
<%@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">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>formulario</title>
</head>
<body>
<form action="pageViewCountData" method="post">
<center <h1>Formulário</h1><br/><p>Entre com os seguintes valores da equação y=ax+b<p/><table>
<tr>
<td>a:</td>
<td><input type="text" name="a" size="20"></td>
</tr>
<tr>
<td>b:</td>
<td><input type="text" name="b" size="20" maxlength="20"></td>
</tr>
<tr>
<td></td>
<td></td>
</tr>
<tr>
<td><input type="submit" name="Enviar" value="Enviar"></td>
<td><input type="reset" name="reset" value="Limpar" /></td>
</tr>
</table></center>
</body>
</html>
JSP que apresenta o gráfico:
<%--
Document : grafico
Created on : 07/07/2011, 19:12:58
Author :studant
--%>
<%@page import="codigo.PageViewCountData"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib uri='/WEB-INF/cewolf.tld' prefix='cewolf' %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<h1>Teste com Gráfico de linha!</h1>
<jsp:useBean id="pageViews" class="codigo.PageViewCountData"/>
<cewolf:chart
id="line"
title="Equação Afim y=a*x+b"
type="line"
xaxislabel="x"
yaxislabel="y">
<cewolf:data>
<cewolf:producer id="pageViews"/>
</cewolf:data>
</cewolf:chart>
<p>
<cewolf:img chartid="line" renderer="cewolf" width="400" height="300"/>
</p>
</body>
</html>
XML:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<servlet>
<servlet-name>CewolfServlet</servlet-name>
<servlet-class>de.laures.cewolf.CewolfRenderer</servlet-class>
<!-- sets storage implementation -->
<init-param>
<param-name>storage</param-name>
<param-value>de.laures.cewolf.storage.TransientSessionStorage</param-value>
</init-param>
<!-- sets overlib.js location relative to webapp -->
<init-param>
<param-name>overliburl</param-name>
<param-value>etc/overlib.js</param-value>
</init-param>
<!-- turn on or off debugging logging -->
<init-param>
<param-name>debug</param-name>
<param-value>true</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>CewolfServlet</servlet-name>
<url-pattern>/cewolf/*</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>1</session-timeout>
</session-config>
<mime-mapping>
<extension>css</extension>
<mime-type>text/css</mime-type>
</mime-mapping>
<welcome-file-list>
<welcome-file>
index.jsp
</welcome-file>
<welcome-file>
index.jsp
</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>pageViewCountDataServlet</servlet-name>
<servlet-class>Cewolf21.codigo.PageViewCountData</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>pageViewCountDataServlet</servlet-name>
<url-pattern>/pageViewCountData</url-pattern>
</servlet-mapping>
<!-- resource-ref>
<description>
Resource reference to a factory for java.sql.Connection
instances that may be used for talking to a particular
database that is configured in the server.xml file.
</description>
<resource-ref-name>
jdbc/testdb
</resource-ref-name>
<res-type>
javax.sql.DataSource
</res-type>
<res-auth>
Container
</res-auth>
</resource-ref -->
</web-app>
Obrigada mesmo.