Create an IntervalBarChart similar to GanttChart but still..

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
stfs
Posts: 1
Joined: Thu Feb 05, 2004 6:22 pm

Create an IntervalBarChart similar to GanttChart but still..

Post by stfs » Thu Feb 05, 2004 6:58 pm

Hello.

I've been trying to customize JFreeChart to my specific needs in displaying MP sitting information (when an MP is sitting in parliament and when he is being represented by a substitute).

First, let me describe what I'm trying to achieve. I'm creating a GUI application for the Office of the Icelandic Parliament. I'm currently working on creating a view that will show how MPs have been sitting in parliament in the past. An MP is a person that has been elected to parliament in his constituency and therefore has a specific constituency number. A primary MP is the person that was originally voted into parliament. A secondary MP is a person that relieves a primary MP if the primary MP needs to be excused. When a secondary MP takes a seat in parliament, he represents the constituency and constituency number that the primary MP whom he is relieving originally represented.

So, I want to display this information graphically using JFreeChart in a similar manner as a GanttChart is displayed:

Code: Select all

Jan 20         Jan 25         Jan 30         Feb 4          Feb 9          Feb 14         Feb 19         Feb 24
|--------------|--------------|--------------|--------------|--------------|--------------|--------------|---------|
|                                                                                                                  |
+- First rep. of Foo constituency ---------------------------------------------------------------------------------+
|                                                                                                                  |
|  /=John Doe [primary]===/                            /=John Doe [primary]===/                                    |
|                         /=Doe Johnson [secondary]====/                                                           |
|                                                                             /=Donny Brasco [secondary]====/      |
+------------------------------------------------------------------------------------------------------------------+
+- Second rep. of Foo constituency --------------------------------------------------------------------------------+
|                                                                                                                  |
|  /= Ziggy [primary]===/                 /=Ziggy [primary]========/                    /=Ziggy [primary]===/      |
|                       /=Bill [sec.]=====/                                                                        |
|                                                                  /=Ron [secondary]====/                          |
+------------------------------------------------------------------------------------------------------------------+
(I hope this thing makes it vaguely understandable what I'm trying to achieve).

My problem is basically that I haven't been able to properly do this on my own. I've started trying to create a custom dataset and series classes and my way of doing that is to look at each constituency / number pair as a single series. Each one of these series contains a bunch of SessionSitting elements that represent a single sitting of an MP (the SessionSitting class corresponds in some ways to the Task class for Gantt but not quite. The biggest difference being that the SessionSitting does not have "sub-sittings" to represent many sittings of an MP, instead, the SessionSittingSeries class contains many SessionSitting instances with the same MP reference).

I'm not quite sure if I'm on the right way here. What I'm having the most trouble understanding is the notion of a row and column in the renderer. What is a row and a column in my case? Is each series a column? Each constituency/number pair can have a different number of SessionSitting instances (perhaps the primary MP of that constituency/number never got sick and never had to be substituted) so I'm guessing that row would not be the number of SessionSitting item for a particular SessionSittingSeries.

I'm a bit lost here, so I hope that I've made myself even vaguely understandable. Any help would be greatly appreciated.

chriscmp
Posts: 3
Joined: Mon Mar 24, 2003 7:33 pm

A chart Similiar to Gannt

Post by chriscmp » Fri Feb 06, 2004 7:54 am

I'm trying to do something similiar. One problem with the gantt chart as it sits is that all the data need to be in all the "rows and columns." For example in the icelandic MP setup below, JohnDoe would need to be in both the first and second rep consitutencies otherwise the rows and columns end up being sparse. The way the code is setup right now, When the interval data is sparse, it fails as it's trying to figure out the time extends ( ie smallest and largest times it needs to display ).

I'm seeing :

java.lang.IndexOutOfBoundsException: Index: 11, Size: 11
at java.util.ArrayList.RangeCheck(ArrayList.java:507)
at java.util.ArrayList.get(ArrayList.java:324)
at org.jfree.data.TaskSeries.get(Unknown Source)
at org.jfree.data.TaskSeriesCollection.getStartValue(Unknown Source)
at org.jfree.data.DatasetUtilities.getRangeExtent(Unknown Source)
at org.jfree.chart.plot.HorizontalCategoryPlot.getHorizontalDataRange(Unknown Source)
at org.jfree.chart.axis.HorizontalDateAxis.autoAdjustRange(Unknown Source)
at org.jfree.chart.axis.HorizontalDateAxis.configure(Unknown Source)
at org.jfree.chart.axis.Axis.setPlot(Unknown Source)
at org.jfree.chart.plot.CategoryPlot.(Unknown Source)
at org.jfree.chart.plot.HorizontalCategoryPlot.(Unknown Source)
at org.jfree.chart.ChartFactory.createGanttChart(Unknown Source)


I'm looking now at what can be done to pass in "sparse" data and still have it work.

One way to demo this failure is to change the createGanttDataset1 method within com/jrefinery/chart/demo/DemoDatasetFactory.java so that there are NOT the exact same number of tasks in each Task series ( remove one task for example ). This will cause the failure.

david.gilbert
JFreeChart Project Leader
Posts: 11734
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Post by david.gilbert » Fri Feb 06, 2004 5:28 pm

I think the way to approach this is to create a completely new dataset, plot and renderer. The big limitation with the current Gantt implementation is that the data is constrained to fit into a table structure (that's what a CategoryDataset is, really) with an equal number of rows and columns (that usually works for bar charts, but Gantt charts need to be more flexible).

I've been thinking (loosely) about the following:

EventDataset - similar to an XYDataset with (1) any number of series, (2) each series can have any number of items, (3) the X values are time periods, (4) the Y values are Event objects, where we define a base Event class and a number of subclasses that EventRenderers can recognise and extract information from. An event might represent something simple like an ON/OFF state, but also might represent something more complex like a project task with references to prerequisite tasks and other links.

EventPlot - this has (1) a domain axis that is similar to a CategoryAxis, but it labels individual series from the dataset, and positions the whole series for display (2) a range axis that is a ValueAxis (probably a DateAxis by default, but allow for a NumberAxis just to be general). Typically the domain axis will be on the left hand side of the chart, and the date axis running along the bottom (but PlotOrientation will be used). Each series will extend across the chart as in a Gantt chart.

EventRenderer - a simple renderer might draw colored bars for each event in the series, a more complex renderer might check for subclasses of the Event object, extract information and draw more complex indicators.

These are still vague ideas, but I think it can be made to work.
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Support JFree via the Github sponsorship program

balex
Posts: 2
Joined: Wed Dec 01, 2004 4:50 pm

Same problems with using Gantt chart

Post by balex » Wed Dec 01, 2004 4:53 pm

I have exactly the same problem with using Gantt charts for displaying event or scheduling type data.

Has anyone built the proposed new dataset, plot and renderer to display this type of data?

ev
Posts: 11
Joined: Fri Jan 28, 2005 10:39 am
Location: Stuttgart (DE)

Post by ev » Mon Jan 31, 2005 2:35 pm

Can the problem be solved using addSubtask() for Task(s) and using sutable (new ?) renderer ?

Locked