Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

CEWOLF and jfreeChart: DefaultCategoryDataset method addValue()

Posted on 2006-04-26
4
Medium Priority
?
1,628 Views
Last Modified: 2008-01-09
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.
0
Comment
Question by:Rrugemalira
  • 2
4 Comments
 
LVL 23

Expert Comment

by:Siva Prasanna Kumar
ID: 16545982
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
 

Author Comment

by:Rrugemalira
ID: 16547934
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
 
LVL 23

Accepted Solution

by:
Siva Prasanna Kumar earned 2000 total points
ID: 16555611
>> 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
 

Expert Comment

by:Adwait Chitaley
ID: 26078006
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

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Will the future of mobile app development include the same trends as those most relevant today? Find out by checking out the 7 trends of the future.
LinkedIn blogging is great for networking, building up an audience, and expanding your influence as well. However, if you want to achieve these results, you need to work really hard to make your post worth liking and sharing. Here are 4 tips that ca…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question