Remove series in DefaultStatisticalCategoryDataset

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
Filoche
Posts: 26
Joined: Sat Jul 28, 2007 7:23 pm

Remove series in DefaultStatisticalCategoryDataset

Post by Filoche » Tue Aug 14, 2007 7:19 pm

Hi all.

How can I remove all serie in a DefaultStatisticalCategoryDataset.

This method add data in result (wich is a DefaultStatisticalCategoryDataset). Thus I cant figure how to remove or clear the "result" variable.

[MODERATOR EDIT: please place code in code tags]

Code: Select all

public void CreateCategoryLineSerie(String serie, String xValues[], double yValues[], double stdev[], Boolean flag)
{
    for( int x = 0; x < xValues.length; x++ )		
    {
        if (flag == true)
            result.add(yValues[x], stdev[x], serie, xValues[x].substring(8));
        else result.add(yValues[x], 0, serie, xValues[x].substring(8));
    }
}

Filoche
Posts: 26
Joined: Sat Jul 28, 2007 7:23 pm

Post by Filoche » Mon Aug 20, 2007 6:21 pm

Hi there.

I'm still trying to find a way to clear a DefaultStatisticalCategoryDataset. So I can remove all series in it and add new series.

Tx for any tips.

Priya Shivapura
Posts: 59
Joined: Fri Feb 23, 2007 7:41 am

Post by Priya Shivapura » Mon Aug 20, 2007 7:38 pm

Hello,

You will have to extend DefaultStatisticalCategoryDataset and add one or all of the following methods as per your requirement.

Code: Select all

public void removeRow(int rowIndex);
public void removeRow(Comparable rowKey);
public void removeColumn(int columnIndex);
public void removeColumn(Comparable columnKey) 
DefaultCategoryDataset.java implements the above methods. You can take a look at that for reference.

Regards,
Priya

Filoche
Posts: 26
Joined: Sat Jul 28, 2007 7:23 pm

Post by Filoche » Tue Aug 21, 2007 5:58 am

Tx thats a good idea.

But how can I access to the data form my extending class ? They are set to private in DefaultStatisticalCategoryDataset.

Maybe I miss something.

Best regards.

Priya Shivapura
Posts: 59
Joined: Fri Feb 23, 2007 7:41 am

Post by Priya Shivapura » Tue Aug 21, 2007 6:43 pm

If you need to remove all the series, then you call

Code: Select all

removeRow(..)
for each series. This will remove all the series. Then you could call

add(....)

to add the new data.

Regards,
Priya

Filoche
Posts: 26
Joined: Sat Jul 28, 2007 7:23 pm

Post by Filoche » Thu Aug 23, 2007 3:47 pm

Hi.

My code so far is :

[MODERATOR EDIT: please place code in code tags]

Code: Select all

public class ExtendedDefaultStatisticalCategoryDataset extends DefaultStatisticalCategoryDataset 
{
    public void removeRow(int rowIndex)
    {
        //Here will be my code	
    }
}
But the data is added in a KeyedObjects2D structure in DefaultStatisticalCategoryDataset. I dont have acces to this private attribute. Does it means I have to define a KeyedObjects2D in my extended class ?

Best regards and your help is greatly appreciated.
Phil

Priya Shivapura
Posts: 59
Joined: Fri Feb 23, 2007 7:41 am

Post by Priya Shivapura » Thu Aug 23, 2007 7:12 pm

Ok, I now see the problem. For some reason I thought that the data member was protected.

In this case you will need to create your own copy of the DefaultStatisticalCategoryDataset with the new additional remove methods. You will have to use this new class instead of the one in JFreecharts.

Regards,
Priya

Filoche
Posts: 26
Joined: Sat Jul 28, 2007 7:23 pm

Post by Filoche » Thu Aug 23, 2007 7:38 pm

Hi sire.

That's exaclty what I did this morning. Works like a charm now.

Thank again for your support and have a ncie day.

Phil

Locked