Update Gantt Chart

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
Ericode
Posts: 4
Joined: Sat Jan 13, 2018 10:04 pm
antibot: No, of course not.

Update Gantt Chart

Post by Ericode » Tue Jan 16, 2018 7:02 am

I have a gantt chart and when I try to update the chart it appends the left hand side. My ArrayList has the correct data inside and it gets renamed properly but when I try to refresh the chart it appends the data. I posted images and the code I have for my update method below.


Before Update:
Image

After Update:
Image

Code: Select all

/* Global Variables
    static IntervalCategoryDataset dataset;
    static JFreeChart chart;
    static TaskSeriesCollection collection;
*/
static void updateDataset() {
        collection.removeAll();
        DateFormat format = new SimpleDateFormat("MM dd yyyy", Locale.ENGLISH);

        for (int i = 0; i < Demo.people.size(); i++) {
            TaskSeries s1 = new TaskSeries(Demo.people.get(i).getName());
            s1.add(new Task(Demo.people.get(i).getName(),
                    new SimpleTimePeriod(java.sql.Date.valueOf(Demo.people.get(i).getStartDate()),
                            java.sql.Date.valueOf(Demo.people.get(i).getEndDate()))));
            collection.add(s1);
        }

        dataset = collection;
    }
Edit:
When I do collection.getSeriesCount() it returns the proper number of series, in this case 2 but 3 is being displayed and I am not sure why.

Ericode
Posts: 4
Joined: Sat Jan 13, 2018 10:04 pm
antibot: No, of course not.

Re: Update Gantt Chart

Post by Ericode » Thu Jan 18, 2018 3:41 am

I have the code below defined and when I call collection.removeAll() it clears the data but not the keys. Why is this and how do I clear the keys?

Code: Select all

TaskSeriesCollection collection
Edit: I fixed it. For anyone else who has trouble, you need to use collection.getColumnKeys().clear() as removeAll() just removes the data.

Locked