GanttChart - Swap between schedules?

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
slepax
Posts: 1
Joined: Fri Oct 17, 2014 3:40 am
antibot: No, of course not.

GanttChart - Swap between schedules?

Post by slepax » Fri Oct 17, 2014 3:54 am

Hello all,

I've started playing a bit with JFreeChart trying to create a switchable Gantt chart. I have two schedules, that I would like to switch between using a JComboBox (say Schedule 1 and Schedule 2). These schedule are for different task items, and this is where thing go wrong for me.

So what I have done is to create a master dataset (TaskSeriesCollection) and provide it to the createGanttChart factory method. Then every time I want to swap between schedules I remove all the TaskSeries from the collection and add the ones from the other schedule.

This works fine except that the list of tasks shown on the Y-Axis is from both schedules, while I want it to show only the tasks relevant for the TaskSeries showing. So in the example below after the removeAll and Add, the Y-Axis is showing tasks 1-6, rather than just 4-6.

So ..

Question 1
Is there anyway that I can ask the chart to clear the labels on the X-Axis and start fresh everytime I switch to a different TaskSeries?

Question 2
Another problem (which is only a problem for me) is that when I switch schedules the timespan changes based on that specific schedule, is there a way to fix" the X-Axis so it will cover both schedules all the time? (i.e. 1/Apr - 12/Apr)

Many Thanks!

PS - Thanks for making such a great product and also making it available for free!!!!!!!!!

Code: Select all

TaskSeries s1 = new TaskSeries("Schedule1");
s1.add(new Task("Task1", new SimpleTimePeriod(date(1, Calendar.APRIL, 2001), date(5, Calendar.APRIL, 2001))));
s1.add(new Task("Task2", new SimpleTimePeriod(date(6, Calendar.APRIL, 2001), date(7, Calendar.APRIL, 2001))));
s1.add(new Task("Task3", new SimpleTimePeriod(date(8, Calendar.APRIL, 2001), date(12, Calendar.APRIL, 2001))));

TaskSeries s2 = new TaskSeries("Schedule2");
s2.add(new Task("Task4", new SimpleTimePeriod(date(1, Calendar.APRIL, 2001), date(4, Calendar.APRIL, 2001))));
s2.add(new Task("Task5", new SimpleTimePeriod(date(5, Calendar.APRIL, 2001), date(9, Calendar.APRIL, 2001))));
s2.add(new Task("Task6", new SimpleTimePeriod(date(10, Calendar.APRIL, 2001), date(12, Calendar.APRIL, 2001))));

TaskSeriesCollection dataset = new TaskSeriesCollection();
dataset.add(s1);

// chart title, domain axis label, range axis label, data, include legend, tooltips, urls
JFreeChart chart = ChartFactory.createGanttChart("Gantt Chart Demo", "Task", "Date", dataset, true, true, false);

dataset.removeAll();
dataset.add(s2);

skyhook
Posts: 8
Joined: Tue Mar 03, 2015 2:34 pm
antibot: No, of course not.

Re: GanttChart - Swap between schedules?

Post by skyhook » Wed Mar 04, 2015 1:19 pm

Hi,

Question 1

- i am using chart.getCategoryPlot().clearRangeMarkers();

Question 2

- i am using chart.getCategoryPlot().getRangeAxis().setRange(start, end)

M.

Locked