Dear david,
iI observed that JDBCPieDataset ,by default takes two columns(one field name,the other its value) of sevevrel Rows.
But what if we need to draw a graph for a single row and severel columns ?
I have written a small variant of the said class for my convenience and it worked fine.
I would like to know whether this is the only way or is there any other simple solution than extending the JDBCPieDataset and overriding 'executeQuery ' method.
Wishing you good,
MJ
Correction to JDBCPieDataset
Re: Correction to JDBCPieDataset
There is a simple solution: don't use teh JDBCPieDataset. Use the DefaultPieDataset and populate it by yourself.MasterJ wrote:Dear I would like to know whether this is the only way or is there any other simple solution than extending the JDBCPieDataset and overriding 'executeQuery ' method.
This may easy for a single graph!
Hello Angel,
This may easy for a single graph!
But what if we don't know how many columns we would have in the row ,and the type of data in them.
I'm using these graphs in a WebApp. So I cannot write so many servlets for each graph; and what I did is I generated a Template like servlet which takes the type of the graph, title , domain axis label , range axis label,and the SQL Query . So that generating graphs in JSP/jspx pages was very easy.
What I'm trying to tell you is Is there i any way to do this or Should I post my Class which is a subclass of JDBCPieDataset)here in this forum.so that others can benefit from it?
Thanks anyway for your response,
MJ
This may easy for a single graph!
But what if we don't know how many columns we would have in the row ,and the type of data in them.
I'm using these graphs in a WebApp. So I cannot write so many servlets for each graph; and what I did is I generated a Template like servlet which takes the type of the graph, title , domain axis label , range axis label,and the SQL Query . So that generating graphs in JSP/jspx pages was very easy.
What I'm trying to tell you is Is there i any way to do this or Should I post my Class which is a subclass of JDBCPieDataset)here in this forum.so that others can benefit from it?
Thanks anyway for your response,
MJ
Master Java
Re: This may easy for a single graph!
I don't understand your problem. You can do all with the DefaultPieDataset what you can do with JDBCPieDataset. You don't have to write a servlet for each graph.MasterJ wrote:Hello Angel,
This may easy for a single graph!
But what if we don't know how many columns we would have in the row ,and the type of data in them.
I'm using these graphs in a WebApp. So I cannot write so many servlets for each graph; and what I did is I generated a Template like servlet which takes the type of the graph, title , domain axis label , range axis label,and the SQL Query . So that generating graphs in JSP/jspx pages was very easy.
Posting your source code is never a bad idea!MasterJ wrote: What I'm trying to tell you is Is there i any way to do this or Should I post my Class which is a subclass of JDBCPieDataset)here in this forum.so that others can benefit from it?
Simplicity
The beauty of JDBCPieDataset is that I only pas the Query to an in instance of JDBCPieDataset and it does the rest. Is that possible with DefaultPieDataset ?
Thanks for your interest in this,
MJ
Thanks for your interest in this,
MJ
Master Java
-
- JFreeChart Project Leader
- Posts: 11734
- Joined: Fri Mar 14, 2003 10:29 am
- antibot: No, of course not.
- Contact:
The problem with JDBCPieDataset is that it will read data in one format only. Whereas if you write your own (JDBC) code to read the database, then populate a DefaultPieDataset from that, you can handle as many different table/query formats as you want.
David Gilbert
JFreeChart Project Leader
Read my blog
Support JFree via the Github sponsorship program
JFreeChart Project Leader


My Suggestion!
Dear David,
Thanks for your reply.
I prefer the automatic behaviour of JDBCPieDataset to Manually setting values after we ourselves retrieving the values from the dtabase.
Or May be I didn't understand what you are saying, anyway,
I would like to suggest you to make this change to the execute query method in the next version ,if possible.
It makes work a lot easier.
the code is as below:
public void executeQuery(Connection con, String query,int type) throws SQLException {
Statement statement = null;
ResultSet resultSet = null;
if(type==2){
try {
statement = con.createStatement();
statement.setFetchSize(1);
resultSet = statement.executeQuery(query);
ResultSetMetaData metaData = resultSet.getMetaData();
int columnCount = metaData.getColumnCount();
if (!resultSet.next())
throw new SQLException(
"Sorry, You Must Supply a Single row of Numerical Data" );
int count=1;
double value = Double.NaN;
while (count<=columnCount) {
Comparable key = metaData.getColumnName(count);
int columnType = metaData.getColumnType(count);
switch (columnType) {
case Types.NUMERIC:
case Types.REAL:
case Types.INTEGER:
case Types.DOUBLE:
case Types.FLOAT:
case Types.DECIMAL:
case Types.BIGINT:
value = resultSet.getDouble(count);
setValue(key, value);
count++;
break;
case Types.DATE:
case Types.TIME:
case Types.TIMESTAMP:
Timestamp date = resultSet.getTimestamp(count);
value = date.getTime();
setValue(key, value);
count++;
break;
default:
System.err.println(
"JDBCCustomPieDataSet - unknown data type"
);
break;
}
}
fireDatasetChanged();
}
}
// and here we may write the original behaviour of the JDBCPieDataset;
finally {
if (resultSet != null) {
try {
resultSet.close();
}
catch (Exception e) {
System.err.println("JDBCCustomPieDataSet: swallowing exception.");
}
}
if (statement != null) {
try {
statement.close();
}
catch (Exception e) {
System.err.println("JDBCCustomPieDataSet: swallowing exception.");
}
}
}
}
Won't it work?
I thought It would be nice to share what I have to be useful for me.
I'll be happy if it is useful for atleast one person.
Thaking you,
MJ
Thanks for your reply.
I prefer the automatic behaviour of JDBCPieDataset to Manually setting values after we ourselves retrieving the values from the dtabase.
Or May be I didn't understand what you are saying, anyway,
I would like to suggest you to make this change to the execute query method in the next version ,if possible.
It makes work a lot easier.
the code is as below:
public void executeQuery(Connection con, String query,int type) throws SQLException {
Statement statement = null;
ResultSet resultSet = null;
if(type==2){
try {
statement = con.createStatement();
statement.setFetchSize(1);
resultSet = statement.executeQuery(query);
ResultSetMetaData metaData = resultSet.getMetaData();
int columnCount = metaData.getColumnCount();
if (!resultSet.next())
throw new SQLException(
"Sorry, You Must Supply a Single row of Numerical Data" );
int count=1;
double value = Double.NaN;
while (count<=columnCount) {
Comparable key = metaData.getColumnName(count);
int columnType = metaData.getColumnType(count);
switch (columnType) {
case Types.NUMERIC:
case Types.REAL:
case Types.INTEGER:
case Types.DOUBLE:
case Types.FLOAT:
case Types.DECIMAL:
case Types.BIGINT:
value = resultSet.getDouble(count);
setValue(key, value);
count++;
break;
case Types.DATE:
case Types.TIME:
case Types.TIMESTAMP:
Timestamp date = resultSet.getTimestamp(count);
value = date.getTime();
setValue(key, value);
count++;
break;
default:
System.err.println(
"JDBCCustomPieDataSet - unknown data type"
);
break;
}
}
fireDatasetChanged();
}
}
// and here we may write the original behaviour of the JDBCPieDataset;
finally {
if (resultSet != null) {
try {
resultSet.close();
}
catch (Exception e) {
System.err.println("JDBCCustomPieDataSet: swallowing exception.");
}
}
if (statement != null) {
try {
statement.close();
}
catch (Exception e) {
System.err.println("JDBCCustomPieDataSet: swallowing exception.");
}
}
}
}
Won't it work?
I thought It would be nice to share what I have to be useful for me.
I'll be happy if it is useful for atleast one person.
Thaking you,
MJ
Master Java