|
Re: Dynamic (Y) Series insertion at runtime in chart [message #494184 is a reply to message #494089] |
Thu, 29 October 2009 13:53 |
|
Maurizio,
Look at this post:
http://birtworld.blogspot.com/2008/10/dynamically-adding-ser ies-to-birt-chart.html
Jason
Maurizio Bellemo wrote:
> Hi all,
>
> I was trying to create a BIRT chart about business revenues.
>
> I have the following column in my DB table:
>
> - year
> - business unit
> - revenues
>
> Unfortunately, the business units I get in my 'select' clause are not
> known a priori. I would like one chart with
>
> - year as x-axis
> - revenue as y-axis
>
> The chart should represent each business unit with one line to be easily
> compared. This should be done at runtime.
>
> I thought a good way of doing it is via JavaScript. Could you please
> suggest me anything??
>
> Thanks
> Bye
> Maurizio
|
|
|
Re: Dynamic (Y) Series insertion at runtime in chart [message #715683 is a reply to message #494184] |
Mon, 15 August 2011 07:37 |
Johannes.Koshy Messages: 30 Registered: July 2011 |
Member |
|
|
Dear Jason, i have a Similiar Problem:
Iam Trying to Add Series to my Report dynamically.
When the User clicks on the Chart, a Dialog Shows in my RCP App,
for him to Choose Diffrent Data Sets, when selected, following code is called
private void manageSelection() {
if (selectedResources.length > 0) {
mdp.setResourceName(selectedResources[0]);
ExtendedItemHandle eih = (ExtendedItemHandle) design
.getDesignHandle().getModuleHandle()
.findElement((String) arguments[1]);
ChartWithAxes chart = null;
try {
chart = (ChartWithAxes) eih.getReportItem().getProperty(
"chart.instance");
} catch (ExtendedElementException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Axis yAxis = chart.getAxes().get(0).getAssociatedAxes().get(0);
NumberDataSet[] datasets = new NumberDataSet[selectedResources.length];
for (int i = 1; i < selectedResources.length; i++) {
mdp.retrieveData(selectedResources[i]);
NumberDataSet orthoValuesDataSet1 = NumberDataSetImpl
.create(mdp.getValues().toArray());
AreaSeries as1 = (AreaSeries) AreaSeriesImpl.create();
as1.setSeriesIdentifier(selectedResources[i]);
as1.setDataSet(orthoValuesDataSet1);
as1.setTranslucent(true);
as1.getLineAttributes().setColor(ColorDefinitionImpl.BLACK());
as1.getLabel().setVisible(true);
SeriesDefinition sdY = SeriesDefinitionImpl.create();
sdY.getSeriesPalette().shift(1);
yAxis.getSeriesDefinitions().add(sdY);
sdY.getSeries().add(as1);
}
}
}
The First DataSet will be Handled by the Report Itself(As a Scripted Data Source, and the same Instance of mdp), the Rest iam trying to add manually.
After this method is invoked, i compile the report and show it again.
This code works fine when i only select one Source, but when i 2 sources, nothing happens and selecting a single source stops also to work.
There is also no Exception.
Iam quite puzzled again :/.
Another Question I have:
When i Have Two DataSets, with MeasuringPoints(Time,Value) from 8-22 o-clock but not with sync.
Time Values...for example 8:00,:8:03,... and 8:01,8:04...
How would i plot these in an Line/Area or Similar Chart, since they dont have the same cat.
Do I have to Manually merge the Category and Fill up the DataSets with Interpolations?
Or is there a way Birt could Handle it?
thank you for your time and help
|
|
|
Re: Dynamic (Y) Series insertion at runtime in chart [message #715819 is a reply to message #715683] |
Mon, 15 August 2011 16:37 |
|
Johannes,
On the first question. If you are modifying a report that contains a
chart you need to create QueryImpl not a DataSetImpl.
For example:
Axis yAxis = cm.getAxes().get(0).getAssociatedAxes().get(0);
AreaSeries as1 = (AreaSeries) AreaSeriesImpl.create();
as1.setSeriesIdentifier("test1");
Query yQ = QueryImpl.create( "row[\"QUANTITYORDERED\"]" );
as1.getDataDefinition( ).add( yQ );
as1.setTranslucent(true);
as1.getLineAttributes().setColor(ColorDefinitionImpl.BLACK());
as1.getLabel().setVisible(true);
SeriesDefinition sdY = SeriesDefinitionImpl.create();
sdY.getSeriesPalette().shift(1);
yAxis.getSeriesDefinitions().add(sdY);
sdY.getSeries().add(as1);
the row value you use in the query must be a bound column to the chart.
For example if use code to create an add a chart you can create the
binding after that like:
Chart c = createChart();
extendedItemHandle.getReportItem().setProperty(
"chart.instance", c );
reportDesignHandle.getBody().add(extendedItemHandle);
cs1 = StructureFactory.createComputedColumn( );
cs1.setName( "PRODUCTCODE" );
cs1.setExpression( "dataSetRow[\"PRODUCTCODE\"]");
cs1.setDataType( "string" );
cs1.setAggregateOn(null);
cs2 = StructureFactory.createComputedColumn( );
cs2.setName( "QUANTITYORDERED" );
cs2.setExpression( "dataSetRow[\"QUANTITYORDERED\"]");
cs2.setDataType( "integer" );
extendedItemHandle.addColumnBinding(cs1, true);
extendedItemHandle.addColumnBinding(cs2, true);
In the beforegeneration script there is a way to throw away the series
values that the BIRT engine generates and replace them with your own and
if that is what you are trying take a look at the attached example, but
generally charts use data coming from datasets that are bound to the
chart report item. You can set the script on a chart just by putting it
all in a string and calling setScript like:
mychart
.setScript("function beforeGeneration( cm, icsc )"
+ "{importPackage(Packages.org.eclipse.birt.chart.model.attribute); "
+ "
importPackage(Packages.org.eclipse.birt.chart.model.attribute.impl); "
+ " cm.getLegend().getOutline( ).setStyle(
LineStyle.DASH_DOTTED_LITERAL );"
+ " cm.getLegend().getOutline( ).setColor(
ColorDefinitionImpl.GREEN() );"
+ " cm.getLegend().getOutline( ).setVisible( true );} ");
Keep in mind that all series have to have the same number of points so
you would have to do the interpolation yourself.
Jason
On 8/15/2011 3:37 AM, Johannes.Koshy wrote:
> Dear Jason, i have a Similiar Problem:
> Iam Trying to Add Series to my Report dynamically.
> When the User clicks on the Chart, a Dialog Shows in my RCP App,
> for him to Choose Diffrent Data Sets, when selected, following code is
> called
> private void manageSelection() {
> if (selectedResources.length > 0) {
> mdp.setResourceName(selectedResources[0]);
> ExtendedItemHandle eih = (ExtendedItemHandle) design
> .getDesignHandle().getModuleHandle()
> .findElement((String) arguments[1]);
> ChartWithAxes chart = null;
> try {
> chart = (ChartWithAxes) eih.getReportItem().getProperty(
> "chart.instance");
> } catch (ExtendedElementException e) {
> // TODO Auto-generated catch block
> e.printStackTrace();
> }
> Axis yAxis = chart.getAxes().get(0).getAssociatedAxes().get(0);
> NumberDataSet[] datasets = new NumberDataSet[selectedResources.length];
>
> for (int i = 1; i < selectedResources.length; i++) {
> mdp.retrieveData(selectedResources[i]);
>
> NumberDataSet orthoValuesDataSet1 = NumberDataSetImpl
> .create(mdp.getValues().toArray());
>
> AreaSeries as1 = (AreaSeries) AreaSeriesImpl.create();
> as1.setSeriesIdentifier(selectedResources[i]);
> as1.setDataSet(orthoValuesDataSet1);
> as1.setTranslucent(true);
> as1.getLineAttributes().setColor(ColorDefinitionImpl.BLACK());
> as1.getLabel().setVisible(true);
>
> SeriesDefinition sdY = SeriesDefinitionImpl.create();
> sdY.getSeriesPalette().shift(1);
> yAxis.getSeriesDefinitions().add(sdY);
> sdY.getSeries().add(as1);
> }
> }
>
> }
> The First DataSet will be Handled by the Report Itself(As a Scripted
> Data Source, and the same Instance of mdp), the Rest iam trying to add
> manually.
> After this method is invoked, i compile the report and show it again.
> This code works fine when i only select one Source, but when i 2
> sources, nothing happens and selecting a single source stops also to work.
> There is also no Exception.
>
> Iam quite puzzled again :/.
>
> Another Question I have:
> When i Have Two DataSets, with MeasuringPoints(Time,Value) from 8-22
> o-clock but not with sync.
> Time Values...for example 8:00,:8:03,... and 8:01,8:04...
> How would i plot these in an Line/Area or Similar Chart, since they dont
> have the same cat.
>
> Do I have to Manually merge the Category and Fill up the DataSets with
> Interpolations?
> Or is there a way Birt could Handle it?
>
> thank you for your time and help
>
|
|
|
|
Powered by
FUDForum. Page generated in 0.03727 seconds