UNABLE TO DISPLAY XYChart/Line Graph USING DBase VALUES

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
vazzdoin
Posts: 1
Joined: Fri Sep 17, 2010 6:29 am
antibot: No, of course not.

UNABLE TO DISPLAY XYChart/Line Graph USING DBase VALUES

Post by vazzdoin » Fri Sep 17, 2010 7:00 am

Hi. I am new to the CeWolf-JfreeChart Library. I am using this library to display a line graph/xy chart through jsp on my web based application. However i've tried it many ways, i am still unable to get the graph display. The code i've used is given below.
JSP file

Code: Select all

<form name="argusLine" >
<jsp:useBean id="dbdata" class="graph.argusLinegraph"/>
<jsp:setProperty name="dbdata" property="datasource" value="${testdb}" />
<cewolf:chart id="line" title="Page View Statistics" type="line" xaxislabel="Page" yaxislabel="Views">
    <cewolf:data>
        <cewolf:producer id="dbdata" usecache="true" />
    </cewolf:data>
</cewolf:chart>
<p>
<cewolf:img chartid="line" renderer="cewolf" width="400" height="300"/>
			<br><br><br>
		<table align="center" style="width: auto;" >
		<tr>
			<th style="text-align: center;font-size: 15px;"><input type="submit" name="submit" value=" OK "></th>
		</tr>
		</table>
		</form>
And the Servlet page which rettrieves the values from database and pass them back to the JSP graph to display is :

Code: Select all

package graph;

import org.apache.batik.svggen.font.Font;
import org.jfree.data.*;

import java.awt.Color;
import java.awt.GradientPaint;
import java.io.*;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.Date;

import de.laures.cewolf.*;
import java.io.Serializable;
import org.jfree.chart.*;
import org.jfree.chart.axis.CategoryAxis;
import org.jfree.chart.axis.CategoryLabelPositions;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.labels.StandardCategoryToolTipGenerator;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.IntervalMarker;
import org.jfree.chart.renderer.category.BarRenderer;
import org.jfree.data.general.*;
import org.jfree.data.category.*;
import org.jfree.ui.Layer;
import org.jfree.ui.RectangleAnchor;
import org.jfree.ui.TextAnchor;

import de.laures.cewolf.cpp.SeriesPaintProcessor;
import javax.servlet.*;

import com.sun.org.apache.bcel.internal.generic.DADD;

import java.sql.*;

import javax.sql.*;
import javax.naming.*;
import java.io.File;
import org.w3c.dom.*;
//import graph.DateBean;



public class argusLinegraph implements DatasetProducer,Serializable
{
	private DataSource dbsrc = null;
       int count42=0;
       String date=null;
       String Errormsg="No Data Avaiable";
    
    public void setDatasource(DataSource indb) 
    {
		dbsrc = indb;
	}
	public String getProducerId() 
	{
		return "graph.dbdata";
	}
	public Object produceDataset(Map arg0)throws DatasetProduceException 
	{
		DefaultCategoryDataset dataset = new DefaultCategoryDataset();

		Connection conn = null;
		PreparedStatement salesquery = null;
		ResultSet res,rs,rs1 = null;
		
    	try 
    	{
    		conn = dbsrc.getConnection();
    		Statement st = conn.createStatement();
    		String query="select distinct dst_port from argus where from_unixtime(start_sec) >= date_sub(now(), interval 18 DAY)";
    		System.out.println(query);
    		st = conn.createStatement();
    		rs1 = st.executeQuery(query);
    		while(rs1.next()) 
    		{
    			String qry1 = "select count(*),max(TIME(from_unixtime(start_sec))) from argus where dst_port="+rs1.getString(1)+" and from_unixtime(start_sec) >= date_sub(now(), interval 16 DAY) group by dst_port";
    			System.out.println(qry1);
    			Statement st1 = conn.createStatement();
    			ResultSet rs_port = st1.executeQuery(qry1);
    			while(rs_port.next())
    			{
    				String port = rs_port.getString(1);
    				int p = Integer.parseInt(port);
    				count42 = rs_port.getInt(1);
    				String ab = Integer.toString(count42);
    				date = rs_port.getString(2);
        			System.out.println(p+","+date+","+count42);
    				dataset.addValue(p, date, ab);
    			}
    		}
    	}
    	catch(Exception e)
    	{
    		e.printStackTrace();
    	}
        return dataset;
    }
	public boolean hasExpired(Map arg0, Date arg1) 
	{
		return false;
	}
}
There are two queries above in the sevlet. The first query brings out the distinct ports from the Database(DB) and the second query then retrieves two values based on those distinct ports, first the number of counts of each distinct port and second the recent date on which that port was used. And all these three values are passed to the dataset by using dataset.addValue().

Now the graph gets generated and all the queries get executed and the Application runs well, but in the end the graph is not plotted i.e. no line appears on the graph or the graph is empty.
please suggest me solution if there is any problem in the code. Thanks.

Locked