views:

1152

answers:

1

I am trying to create a gradient fill for a series in an area chart that I am building through the BIRT chart API, but the book "Integrating and Extending BIRT" and the Interwebs seem curiously silent about how to get it to work. It seems no matter what I do, I always get a flat color from the default palette. I've tried using SeriesDefinition.getSeriesPalette().update(Gradient) and even creating my own Palette with the gradient fill in it and setting that on the SeriesDefinition, but to no avail. I've also noticed that if I do not perform a shift() on the Palette, even if it's shift(0), which the Javadocs claim will do nothing, I get NullPointerException when I try to generate the chart:

Caused by: java.lang.NullPointerException
at org.eclipse.birt.chart.render.Area.renderDataPoints(Area.java:521)
at org.eclipse.birt.chart.render.Line.renderSeries(Line.java:570)
at org.eclipse.birt.chart.render.AxesRenderer.renderPlot(AxesRenderer.java:2181)
at org.eclipse.birt.chart.render.AxesRenderer.render(AxesRenderer.java:314)
at org.eclipse.birt.chart.factory.Generator.render(Generator.java:1368)
... 108 more

Here's the latest (non-working) code that I've tried:

Gradient gradient = FillUtil.createDefaultGradient(BirtReportBuilder.COLOR_WHITE);
gradient.setStartColor(ColorDefinitionImpl.WHITE());
gradient.setEndColor(ColorDefinitionImpl.create(76, 116, 131));
gradient.setDirection(90);
SeriesDefinition sdY = SeriesDefinitionImpl.create();
sdY.getQuery().setDefinition("\"Quantity\"");
Palette pal = PaletteImpl.create(gradient);
pal.shift(0);
sdY.setSeriesPalette(pal);
sdY.getSeries().add(as1);
yAxisPrimary.getSeriesDefinitions().add(sdY);

So what's the magic incantation to get the BIRT charting API to use my Gradient as the area fill?

+1  A: 

This code works for me, I get a ugly coloured serie...

sdY.getSeriesPalette().update(GradientImpl.create(ColorDefinitionImpl.create(255,255,255), ColorDefinitionImpl.create(200,0,0,150), 90, false));

Hope it will help you ;p

Ar3s
Yeah, that looks like that does the trick. However, we gave up on BIRT and moved to a different package! :-)
Robert J. Walker
Awh ? Can I ask you why you gave up on it ? I don't want to be nosy or something but I am doing an internship in a french company where I'll have to evaluate Birt in the end so any opinion is welcome ! ^^By the way if I can go on asking you things, have you created any interactive reports out of Java code only ? I am facing some very puzzling problems on this subject :/
Ar3s
The main motivating factor for dumping BIRT was the extreme difficulty in overriding default drawing behavior beyond simple things like color, given that many of the relevant methods were final. Ultimately, we went with Jasper; it uses JFreeChart for charting, which is much more flexible in terms of customizing chart drawing.
Robert J. Walker