Link to home
Start Free TrialLog in
Avatar of Rrugemalira
Rrugemalira

asked on

CEWOLF and jfreeChart: DefaultCategoryDataset method addValue()

EVEN THOUGH I HAVE THE FOLLOWING DECLARED:

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;

AND THE JAR FILES IN THE CORRECT DIRECTORY
root /web/WEB-INF/lib

DefaultCategoryDataset hbDataset = new DefaultCategoryDataset();
i = 0;
for (i = 0; i < TOTAL_COUNT; i++) {
         hbDataset.addValue(i, numInGroup[i], numZD[i]);
}
 return hbDataset;

GIVES THE FOLLOWING ERROR:

cannot find symbol
symbol: method addValue(int, int, java.lang.String)
location: class org.jfree.data.category.DefaultCategoryDataset

Kindly help identify where the problem lies.
Avatar of Siva Prasanna Kumar
Siva Prasanna Kumar
Flag of India image

yes because  there is a  parameter type Mismatch.

void addValue(double value, java.lang.Comparable rowKey, java.lang.Comparable columnKey)

void addValue(java.lang.Number value, java.lang.Comparable rowKey, java.lang.Comparable columnKey)

are the only avilable methods in the class org.jfree.data.category.DefaultCategoryDataset

I think you need to make the required changes to the types.

Thank You.
Avatar of Rrugemalira
Rrugemalira

ASKER

Hello shivaspk,
I still get the same error:
cannot find symbol
symbol: method addValue(int, int, java.lang.String)
location: class org.jfree.data.category.DefaultCategoryDataset
for the line
            hbDataset.addValue(i, result.getInt(1), result.getString(2));

Below is the class

/*
 * SectorCharts.java
 * Created on April 26, 2006, 1:21 PM
 *
 */
import java.io.*;
import java.net.*;
import java.util.*;
import java.sql.*;
import javax.sql.*;
import javax.naming.*;
import java.util.Date;
import java.util.Map;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import java.io.Serializable;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

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;

/**
 *
 * This class produces a Dataset containing sector counts for provinces.
 *
 * @author mwijage
 *
 */
public class SectorCharts implements DatasetProducer, Serializable {

  public Object produceDataset(Map params) throws DatasetProduceException {
    try {
           Connection conn = DriverManager.getConnection(
               "jdbc:mysql://localhost/farmsDB","mwijage", "kabale123");
          String sql =  new String("SELECT count(*), secteur FROM address GROUP BY secteur");
          PreparedStatement ps = conn.prepareStatement(sql);
          ResultSet result = null;
          result = ps.executeQuery();
          DefaultCategoryDataset hbDataset = new DefaultCategoryDataset();
          int i=0;
          while (result.next()) {
            hbDataset.addValue(i, result.getInt(1), result.getString(2));
            i++;
          }
          result.close();
          ps.close();
          conn.close();
          return hbDataset;
   }
     catch (SQLException se) {
     throw new RuntimeException(se);
     }
  }
  /**
   *
   * Returns a unique ID for this DatasetProducer
   */
  public String getProducerId() {
      return "PageViewSecteurData DatasetProducer";
  }
 
  /**
   *  Checks whether curent chart image has expired.
   *
   * @param  params  Parameters passed in Request
   * @param  since   Date used for determining expiration
   * @return         Boolean indicating if Dataset has expired
   */    
  public boolean hasExpired(Map params, java.util.Date since) {
      return false;
  }
}
   
ASKER CERTIFIED SOLUTION
Avatar of Siva Prasanna Kumar
Siva Prasanna Kumar
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
hi,
problem occured in the database connection for the context.xml file

This is the java file for the connection.
1. DBDataProvider.java


package uk.co.vsj.graph1;
import de.laures.cewolf.DatasetProduceException;
import de.laures.cewolf.DatasetProducer;
import java.io.Serializable;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Date;
import java.util.Map;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;
import javax.sql.DataSource;
import org.jfree.data.general.DefaultPieDataset;
//import sun.jdbc.odbc.ee.DataSource;

public class DBDataProvider implements DatasetProducer,Serializable {
     
      private DataSource dbsrc = null;

 
      public void setDatasource(DataSource indb) {
             dbsrc  = indb;
               
        }

public Object produceDataset(Map arg0)throws DatasetProduceException {
      DefaultPieDataset dataset =new DefaultPieDataset();
      Connection conn = null;
      PreparedStatement salesquery = null;
        System.out.println("After Prepare Statement=====>");
      ResultSet res = null;
      try {
            conn = dbsrc.getConnection();
            salesquery = conn.prepareStatement("select location, sum(copies) as sold from sales group by location order by location");
            res = salesquery.executeQuery();
            while(res.next()) {
                  // JDBC columns starts at 1
                  String location =res.getString(1);
                  double sold = res.getDouble(2);
                  dataset.setValue(location, sold);
            }
            } catch (SQLException e) {
                  e.printStackTrace();
            }
      return dataset;
}
 
    public boolean hasExpired(Map arg0, Date arg1) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public String getProducerId() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public void DBDataProvider() {
     
        }
       
     
        }
 
   
   

    2.This is also jsp page

graphdb.jsp

<%@ page language="java"contentType="text/html;charset=ISO-8859-1"pageEncoding="ISO-8859-1"%>
<%@taglib uri='/WEB-INF/cewolf.tld'prefix='cewolf' %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="sql"uri="http://java.sun.com/jsp/jstl/sql" %>
<!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=ISO-8859-1">
            <title>
                  VSJ Database Sourced Data Sample
            </title>
            <sql:setDataSource
      dataSource="jdbc/vsjdb" var="vsjdb" />
      </head>
      <body>
            <jsp:useBean id="dbdata" class="uk.co.vsj.graph1.DBDataProvider" />
            <jsp:setProperty name="dbdata"property="datasource"value="${vsjdb}" />
            <cewolf:chart
                  id="dbchart"
                  type="pie"
title="VSJ Database Sourced Data Sample">
                        <cewolf:data>
                              <cewolf:producer id="dbdata"/>
                        </cewolf:data>
            </cewolf:chart>
            <p/>
            <cewolf:img chartid="dbchart"
                  renderer="cewolf"
                  width="640" height="480"/>
            <p/>
      </body>
</html>


problem occured in the database connection.