Home » Archived » BIRT » Gantt chart: cannot have several entries in a serie
Gantt chart: cannot have several entries in a serie [message #724547] |
Mon, 12 September 2011 15:11 |
Missing name Missing name Messages: 57 Registered: September 2009 |
Member |
|
|
Hello,
I'm trying to generate a Gantt chart programmatically:
The chart has two axes:
- vertical axis (base axis): Name of my elements
- horizontal axis (that is the orthogonal axis to be filled with dates): dates
I create a chart, and a GanttSerie like this:
GanttDataSet phase1 = GanttDataSetImpl.create( new GanttEntry[]{
new GanttEntry( new CDateTime( 2009, 1, 1), new CDateTime( 2009, 1,15),"Name" )});
GanttSeries seriePhase1 = (GanttSeries) GanttSeriesImpl.create( );
taskPhase1.setDataSet( phase1);
SeriesDefinition sdY = SeriesDefinitionImpl.create( );
sdY.getSeriesPalette( ).shift( 2 );
sdY.getSeries( ).add( taskPhase1 );
xAxisPrimary.getSeriesDefinitions( ).add( sdY );
All is OK.
I would like to add GanttEntry in my DataSett "phase1":
GanttDataSet phase1 = GanttDataSetImpl.create( new GanttEntry[]{
new GanttEntry( new CDateTime( 2009, 1, 1), new CDateTime( 2009, 1,15), "Name" ),
new GanttEntry( new CDateTime( 2009, 1, 17), new CDateTime( 2009, 1,23),"Name2")
});
It generates an exception:
org.eclipse.birt.chart.exception.ChartException
at org.eclipse.birt.chart.factory.Generator.render(Generator.java:1306)
at ganttreport.ChartCanvas.drawToCachedImage(ChartCanvas.java:135)
at ganttreport.ChartCanvas$1.paintControl(ChartCanvas.java:66)
at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:229)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1258)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1282)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1267)
at org.eclipse.swt.widgets.Control.gtk_expose_event(Control.java:2961)
at org.eclipse.swt.widgets.Composite.gtk_expose_event(Composite.java:701)
at org.eclipse.swt.widgets.Canvas.gtk_expose_event(Canvas.java:167)
at org.eclipse.swt.widgets.Widget.windowProc(Widget.java:1739)
at org.eclipse.swt.widgets.Control.windowProc(Control.java:5016)
at org.eclipse.swt.widgets.Display.windowProc(Display.java:4408)
at org.eclipse.swt.internal.gtk.OS._gtk_main_do_event(Native Method)
at org.eclipse.swt.internal.gtk.OS.gtk_main_do_event(OS.java:8394)
at org.eclipse.swt.widgets.Display.eventProc(Display.java:1245)
at org.eclipse.swt.internal.gtk.OS._g_main_context_iteration(Native Method)
at org.eclipse.swt.internal.gtk.OS.g_main_context_iteration(OS.java:2258)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3207)
at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2696)
at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2660)
at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2494)
at org.eclipse.ui.internal.Workbench$7.run(Workbench.java:674)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:667)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
at ganttreport.Application.start(Application.java:20)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:344)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:616)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:622)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:577)
at org.eclipse.equinox.launcher.Main.run(Main.java:1410)
at org.eclipse.equinox.launcher.Main.main(Main.java:1386)
Caused by: java.lang.NullPointerException
at org.eclipse.birt.chart.extension.render.Gantt.renderSeries(Gantt.java:133)
at org.eclipse.birt.chart.render.AxesRenderer.renderPlot(AxesRenderer.java:2284)
at org.eclipse.birt.chart.render.AxesRenderer.render(AxesRenderer.java:335)
at org.eclipse.birt.chart.factory.Generator.render(Generator.java:1301)
... 40 more
I don't understand why I could not add entry in the dataset.
Have you got an idea ?
Thanks in advance.
[Updated on: Mon, 12 September 2011 15:15] Report message to a moderator
|
|
|
Re: Gantt chart: cannot have several entry in a serie [message #724585 is a reply to message #724547] |
Mon, 12 September 2011 15:25 |
|
Can you try this one from the chart examples view?
package org.eclipse.birt.chart.examples.view.models;
import org.eclipse.birt.chart.extension.datafeed.GanttEntry;
import org.eclipse.birt.chart.model.Chart;
import org.eclipse.birt.chart.model.ChartWithAxes;
import org.eclipse.birt.chart.model.attribute.AttributeFactory;
import org.eclipse.birt.chart.model.attribute.AxisType;
import org.eclipse.birt.chart.model.attribute.DateFormatDetail;
import org.eclipse.birt.chart.model.attribute.DateFormatSpecifier;
import org.eclipse.birt.chart.model.attribute.DateFormatType;
import org.eclipse.birt.chart.model.attribute.IntersectionType;
import org.eclipse.birt.chart.model.attribute.LegendItemType;
import org.eclipse.birt.chart.model.attribute.Orientation;
import org.eclipse.birt.chart.model.attribute.TickStyle;
import org.eclipse.birt.chart.model.attribute.impl.ColorDefinitionImpl;
import org.eclipse.birt.chart.model.component.Axis;
import org.eclipse.birt.chart.model.component.Series;
import org.eclipse.birt.chart.model.component.impl.SeriesImpl;
import org.eclipse.birt.chart.model.data.BaseSampleData;
import org.eclipse.birt.chart.model.data.DataFactory;
import org.eclipse.birt.chart.model.data.GanttDataSet;
import org.eclipse.birt.chart.model.data.NumberDataSet;
import org.eclipse.birt.chart.model.data.OrthogonalSampleData;
import org.eclipse.birt.chart.model.data.SampleData;
import org.eclipse.birt.chart.model.data.SeriesDefinition;
import org.eclipse.birt.chart.model.data.impl.DateTimeDataElementImpl;
import org.eclipse.birt.chart.model.data.impl.GanttDataSetImpl;
import org.eclipse.birt.chart.model.data.impl.NumberDataSetImpl;
import org.eclipse.birt.chart.model.data.impl.SeriesDefinitionImpl;
import org.eclipse.birt.chart.model.impl.ChartWithAxesImpl;
import org.eclipse.birt.chart.model.layout.Legend;
import org.eclipse.birt.chart.model.layout.Plot;
import org.eclipse.birt.chart.model.type.GanttSeries;
import org.eclipse.birt.chart.model.type.impl.GanttSeriesImpl;
import org.eclipse.birt.chart.util.CDateTime;
/**
*
*/
public class Gantt
{
public final static Chart createGantt( )
{
ChartWithAxes cwaGantt = ChartWithAxesImpl.create( );
cwaGantt.setType( "Gantt Chart" ); //$NON-NLS-1$
cwaGantt.setSubType( "Standard Gantt Chart" ); //$NON-NLS-1$
cwaGantt.setOrientation( Orientation.HORIZONTAL_LITERAL );
// Plot
cwaGantt.getBlock( ).setBackground( ColorDefinitionImpl.WHITE( ) );
cwaGantt.getBlock( ).getOutline( ).setVisible( true );
Plot p = cwaGantt.getPlot( );
p.getClientArea( ).setBackground( ColorDefinitionImpl.create( 255,
255,
225 ) );
// Title
cwaGantt.getTitle( ).getLabel( ).getCaption( ).setValue( "Gantt Chart"
); //$NON-NLS-1$
// Legend
Legend lg = cwaGantt.getLegend( );
lg.setItemType( LegendItemType.CATEGORIES_LITERAL );
// X-Axis
Axis xAxisPrimary = cwaGantt.getPrimaryBaseAxes( )[0];
xAxisPrimary.setCategoryAxis( true );
xAxisPrimary.getMajorGrid( ).setTickStyle( TickStyle.BELOW_LITERAL );
xAxisPrimary.getOrigin( ).setType( IntersectionType.MIN_LITERAL );
// Y-Axis
Axis yAxisPrimary = cwaGantt.getPrimaryOrthogonalAxis( xAxisPrimary );
yAxisPrimary.setType( AxisType.DATE_TIME_LITERAL );
yAxisPrimary.getMajorGrid( ).setTickStyle( TickStyle.LEFT_LITERAL );
yAxisPrimary.getScale( ).setMin( DateTimeDataElementImpl.create( new
CDateTime(2008,1,1) ) );
yAxisPrimary.getScale( ).setMax( DateTimeDataElementImpl.create( new
CDateTime(2009,1,1) ) );
DateFormatSpecifier dfs =
AttributeFactory.eINSTANCE.createDateFormatSpecifier( );
dfs.setDetail( DateFormatDetail.DATE_LITERAL );
dfs.setType( DateFormatType.MEDIUM_LITERAL );
yAxisPrimary.setFormatSpecifier( dfs );
// Data Set
NumberDataSet categoryValues = NumberDataSetImpl.create( new double[]{
1, 2, 3
} );
GanttDataSet phase1 = GanttDataSetImpl.create( new GanttEntry[]{
new GanttEntry( new CDateTime( 2008, 1, 9 ),
new CDateTime( 2008, 6, 9 ),
"Task A" ), //$NON-NLS-1$
new GanttEntry( new CDateTime( 2008, 3, 9 ),
new CDateTime( 2008, 8, 9 ),
"Task B" ), //$NON-NLS-1$
new GanttEntry( new CDateTime( 2008, 5, 24 ),
new CDateTime( 2008, 9, 9 ),
"Task C" ) //$NON-NLS-1$
} );
GanttDataSet phase2 = GanttDataSetImpl.create( new GanttEntry[]{
new GanttEntry( new CDateTime( 2008, 6, 12 ),
new CDateTime( 2008, 9, 23 ),
"Task A" ), //$NON-NLS-1$
new GanttEntry( new CDateTime( 2008, 8, 9 ),
new CDateTime( 2008, 8, 9 ),
"Task B" ), //$NON-NLS-1$
new GanttEntry( new CDateTime( 2008, 9, 9 ),
new CDateTime( 2008, 12, 9 ),
"Task C" ) //$NON-NLS-1$
} );
SampleData sd = DataFactory.eINSTANCE.createSampleData( );
BaseSampleData sdBase = DataFactory.eINSTANCE.createBaseSampleData( );
sdBase.setDataSetRepresentation( "" );//$NON-NLS-1$
sd.getBaseSampleData( ).add( sdBase );
OrthogonalSampleData sdOrthogonal1 =
DataFactory.eINSTANCE.createOrthogonalSampleData( );
sdOrthogonal1.setDataSetRepresentation( "" );//$NON-NLS-1$
sdOrthogonal1.setSeriesDefinitionIndex( 0 );
sd.getOrthogonalSampleData( ).add( sdOrthogonal1 );
cwaGantt.setSampleData( sd );
// X-Series
Series seCategory = SeriesImpl.create( );
seCategory.setDataSet( categoryValues );
SeriesDefinition sdX = SeriesDefinitionImpl.create( );
sdX.getSeriesPalette( ).shift( 0 );
xAxisPrimary.getSeriesDefinitions( ).add( sdX );
sdX.getSeries( ).add( seCategory );
// Y-Series
GanttSeries taskPhase1 = (GanttSeries) GanttSeriesImpl.create( );
taskPhase1.setDataSet( phase1 );
taskPhase1.getLabel( ).setVisible( false );
GanttSeries taskPhase2 = (GanttSeries) GanttSeriesImpl.create( );
taskPhase2.setDataSet( phase2 );
taskPhase2.getLabel( ).setVisible( false );
SeriesDefinition sdY = SeriesDefinitionImpl.create( );
sdY.getSeriesPalette( ).shift( 0 );
yAxisPrimary.getSeriesDefinitions( ).add( sdY );
sdY.getSeries( ).add( taskPhase1 );
sdY.getSeries( ).add( taskPhase2 );
return cwaGantt;
}
}
Jason
On 9/12/2011 11:11 AM, val.dupin wrote:
> Hello,
>
> I'm trying to generate a Gantt chart programmatically: The chart has two
> axes:
>
> vertical axis (base axis): Name of my elements
> horizontal axis (that is the orthogonal axis to be filled with dates):
> dates
>
>
>
>
> I create a chart, and a GanttSerie like this:
>
> GanttDataSet phase1 = GanttDataSetImpl.create( new GanttEntry[]{
> new GanttEntry( new CDateTime( 2009, 1, 1), new CDateTime( 2009,
> 1,15),"Name" )});
>
> GanttSeries seriePhase1 = (GanttSeries) GanttSeriesImpl.create( );
> taskPhase1.setDataSet( phase1);
>
> SeriesDefinition sdY = SeriesDefinitionImpl.create( );
> sdY.getSeriesPalette( ).shift( 2 );
> sdY.getSeries( ).add( taskPhase1 );
>
> xAxisPrimary.getSeriesDefinitions( ).add( sdY );
>
> All is OK.
>
> I would like to add GanttEntry in my DataSett "phase1":
> GanttDataSet phase1 = GanttDataSetImpl.create( new GanttEntry[]{
> new GanttEntry( new CDateTime( 2009, 1, 1), new CDateTime( 2009, 1,15),
> "Name" ), new GanttEntry( new CDateTime( 2009, 1, 17), new CDateTime(
> 2009, 1,23),"Name2")
> });
>
> It generates an exception:
> org.eclipse.birt.chart.exception.ChartException
> at org.eclipse.birt.chart.factory.Generator.render(Generator.java:1306)
> at ganttreport.ChartCanvas.drawToCachedImage(ChartCanvas.java:135)
> at ganttreport.ChartCanvas$1.paintControl(ChartCanvas.java:66)
> at
> org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:229)
> at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
> at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1258)
> at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1282)
> at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1267)
> at org.eclipse.swt.widgets.Control.gtk_expose_event(Control.java:2961)
> at org.eclipse.swt.widgets.Composite.gtk_expose_event(Composite.java:701)
> at org.eclipse.swt.widgets.Canvas.gtk_expose_event(Canvas.java:167)
> at org.eclipse.swt.widgets.Widget.windowProc(Widget.java:1739)
> at org.eclipse.swt.widgets.Control.windowProc(Control.java:5016)
> at org.eclipse.swt.widgets.Display.windowProc(Display.java:4408)
> at org.eclipse.swt.internal.gtk.OS._gtk_main_do_event(Native Method)
> at org.eclipse.swt.internal.gtk.OS.gtk_main_do_event(OS.java:8394)
> at org.eclipse.swt.widgets.Display.eventProc(Display.java:1245)
> at org.eclipse.swt.internal.gtk.OS._g_main_context_iteration(Native Method)
> at org.eclipse.swt.internal.gtk.OS.g_main_context_iteration(OS.java:2258)
> at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3207)
> at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2696)
> at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2660)
> at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2494)
> at org.eclipse.ui.internal.Workbench$7.run(Workbench.java:674)
> at
> org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
>
> at
> org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:667)
> at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
> at ganttreport.Application.start(Application.java:20)
> at
> org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
>
> at
> org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
>
> at
> org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
>
> at
> org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:344)
>
> at
> org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
>
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
>
> at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>
> at java.lang.reflect.Method.invoke(Method.java:616)
> at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:622)
> at org.eclipse.equinox.launcher.Main.basicRun(Main.java:577)
> at org.eclipse.equinox.launcher.Main.run(Main.java:1410)
> at org.eclipse.equinox.launcher.Main.main(Main.java:1386)
> Caused by: java.lang.NullPointerException
> at
> org.eclipse.birt.chart.extension.render.Gantt.renderSeries(Gantt.java:133)
> at
> org.eclipse.birt.chart.render.AxesRenderer.renderPlot(AxesRenderer.java:2284)
>
> at org.eclipse.birt.chart.render.AxesRenderer.render(AxesRenderer.java:335)
> at org.eclipse.birt.chart.factory.Generator.render(Generator.java:1301)
> ... 40 more
>
> I don't understand why I could not add entry in the dataset.
>
> Have you got an idea ?
>
> Thanks in advance.
>
|
|
| |
Re: Gantt chart: cannot have several entry in a serie [message #725012 is a reply to message #724806] |
Tue, 13 September 2011 18:03 |
|
You do not need them. This is generally for the chart builder gui to
display something before using real data. BTW there are other examples
in the chart examples view that you can look at as well.
Jason
On 9/13/2011 4:35 AM, val.dupin wrote:
> Hi Jason,
> Thanks a lot, it works fine.
> I had an exception because the dataset for x axis (called
> categoryValues) has to contains the same number of elements as
> GanttEntry in the y-axis (phase1 for example).
>
> So, I have another question:
> In your source code, there are SampleData and OrthogonalSampleData. What
> is it ? is it sample data existing in the API (like CITIES...) ? When I
> execute your example, they are not displayed in the gantt chart ?
>
> Thank you very much.
|
|
| |
Goto Forum:
Current Time: Wed Sep 25 21:30:31 GMT 2024
Powered by FUDForum. Page generated in 0.03384 seconds
|