How to change the series label ina JDBCXYDataset?

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
khipras
Posts: 15
Joined: Mon Feb 07, 2005 6:41 pm
Location: Mexico D.F.
Contact:

How to change the series label ina JDBCXYDataset?

Post by khipras » Tue Feb 08, 2005 5:16 pm

Hi!!

I have some querys that generates a JDBCXYDataset and draw the chars greatly.
The problem is that I Can't modified this SQL instructions to put some like
Select MAX(field1), AVG(field2) from tablename

select MAX(field1) AS `max mem`, AVG(field2) AS `Average range`
from tablename

And so on with so many querys.

In this database I can load the field name label to each query, so I can get the label name for each field, but I don't know how can I put this labelname to every series.

Some tips?

oacis
Posts: 101
Joined: Fri Jan 07, 2005 5:57 am
Location: Australia, Sydney

Post by oacis » Wed Feb 09, 2005 5:57 am

I don't quite understand your question...

Can you, or can you NOT modify the SQL?

This may do the trick - but you say that you cannot (??) modify as such.
select MAX(field1) AS `max mem`, AVG(field2) AS `Average range`
see some urls:

http://www.jfree.org/phpBB2/viewtopic.php?t=11439
http://www.jfree.org/phpBB2/viewtopic.php?t=11413

They may be of help. I have found that it is better to roll your own JDBC driver as eventually you will want total control.

Andrew Lazarus

Inherit and override

Post by Andrew Lazarus » Wed Feb 09, 2005 6:03 am

GetSeriesName

khipras
Posts: 15
Joined: Mon Feb 07, 2005 6:41 pm
Location: Mexico D.F.
Contact:

Re: Inherit and override

Post by khipras » Wed Feb 09, 2005 5:52 pm

Hi thanks, for your response.
First, I can NOT change the sql statement, this is generate by another software.

I load this sql to make the chart. but I wan't to change the series label.

I'll try with GetSeriesName
Andrew Lazarus wrote:GetSeriesName
Some sample code?

thanks..

Andrew Lazarus

as simple as this

Post by Andrew Lazarus » Thu Feb 10, 2005 4:11 pm

Code: Select all

   final static private String[] fieldList = 
new String[] {"price", "slow", "fast",    "modfast", "relperf", "smoothrelperf", "stage"};

   /**
    * getSeriesName
    *
    * @param series int
    * @return String
    */
   public String getSeriesName(int series) {
      return fieldList[series];
   }

khipras
Posts: 15
Joined: Mon Feb 07, 2005 6:41 pm
Location: Mexico D.F.
Contact:

I found a solution

Post by khipras » Thu Feb 10, 2005 10:56 pm

Ok! Andrew thanks for the hint.
The problem is that I use a XYDataset and i'm not sure where to put your suggested code, beacuse my dataset is egenerated by a Query.

I add to the source code of this class next method to solve my problem.

Code: Select all

    /**
     *  Set the legend item labels.
     *
     * @param  itemLabels  The new legendItemLabels value
     * @return             a boolean.
     */
    public boolean setLegendItemLabels(String[] itemLabels) {
        if (itemLabels.length == this.getLegendItemCount()) {
           this.columnNames=(String[]) this.getLegendItemLabels();
            return true;
        } else {
            return false;
        }
    }

I don't know if this was necesary or there exists another easy way to do this.
But I think that if you need make this kind of change, maybe could be add this method or another similar to this class.

Andrew Lazarus

what do you mean "generated by a query"?

Post by Andrew Lazarus » Sun Feb 13, 2005 6:08 pm

If you have your own class implementing XYDataset (or extending any of its implementations) you would just put my code in the class definition as an override.

You make it sound like you have something like

Code: Select all

XYDataset ds = someStaticMathodGivesMeXYDataset();
That makes it harder. In that case you probably have to extend and override something in XYPlot but that's an ugly solution.

khipras
Posts: 15
Joined: Mon Feb 07, 2005 6:41 pm
Location: Mexico D.F.
Contact:

Post by khipras » Mon Feb 14, 2005 10:47 pm

Hi Andrew.
Maybe this was an ugly solution, but I guess that you can tell me another clean way to do this.

How Can I change the Series Name Label from a JDBCXYDataset.?


This new extended method works greatly to make this kind of change to any JDBCXYDataset that I would change.

I can't implementing your suggested code, because seems like to static XYDataset. I'm not sure how to use it in a JDBCXYDataset.

Thanks for you time.

Locked