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.
RrugemaliraAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Siva Prasanna KumarPrincipal Solutions ArchitectCommented:
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.
0
RrugemaliraAuthor Commented:
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;
  }
}
   
0
Siva Prasanna KumarPrincipal Solutions ArchitectCommented:
>> hbDataset.addValue(i, result.getInt(1), result.getString(2));

change it to.

 hbDataset.addValue(new Integer(i), result.getString(1), result.getString(2));

It must work now you need to make required changes whicle getting back the data from DefaultCategoryDataset.

Thank You.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Adwait ChitaleyCommented:
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.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JSP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.