<p>Hi!</p><p> </p><p>I'm trying to generate reports in a dynamic way. For that purpose I've a <em>.properties</em> file containing several parameters to generate the report according to these parameters. This file looks like this:</p><div><pre class="_prettyXprint">## DATASOURCE PARAMSdb.driverclass = xxxxxxxdb.url = xxxxxxxdb.user = xxxxxxxdb.passwd = xxxxxxx## GENERAL PROPERTIESchart.width = 6,896chart.height = 3,708margin.left = 0,7#G11aparam.title.G11a = Running Projectsparam.subtitle.G11a.absolute = 2005 - 2013(*). Number of Projectsparam.subtitle.G11a.percent = 2005 - 2013(*). Percentage of Projectsparam.ejeY.G11a.absolute = Number of Projectsparam.ejeY.G11a.percent = % of Projectsparam.source.G11a = Analysisparam.footnote.G11a = (*) Only Jan-Oct.param.series.definition.G11a = in_scope;out_scope;totalparam.series.type.G11a = bar;bar;lineparam.series.visibility.G11a = 0;0;1param.series.total.visibility.G11a = 0param.series.type.line.thickness.G11a = 2param.dataset.query.G11a = select * from reports.bws_rep_g11a where type = ':param' order by year#G11bparam.title.G11b = New Projectsparam.subtitle.G11b.absolute = 2005 - 2013(**). Number of Projectsparam.subtitle.G11b.percent = 2005 - 2013(**). Percentage of Projectsparam.ejeY.G11b.absolute = Number of Projectsparam.ejeY.G11b.percent = % of Projectsparam.source.G11b = Analysisparam.footnote.G11b = (*) First clock-time in . (**) Only Jan-Oct.param.series.definition.G11b = in_scope;out_scope;totalparam.series.type.G11b = bar;bar;lineparam.series.visibility.G11b = 0;0;1param.series.total.visibility.G11b = 0param.series.type.line.thickness.G11b = 2param.dataset.query.G11b = select * from reports.bws_rep_G11b where type = ':param' order by year</pre><p>The name followed by '#' character is the report name. I've around 100 reports defined like that.</p><p> </p><p>Then, in the <em>initialize </em>method I read these parameters and set persistent global variables.</p><div><pre class="_prettyXprint">file = new Packages.java.io.FileInputStream("C:/param.properties");repositoryConfig = new Packages.java.util.Properties();repositoryConfig.load(file); width = repositoryConfig.getProperty("chart.width");height = repositoryConfig.getProperty("chart.height");margin_left = repositoryConfig.getProperty("margin.left");title = repositoryConfig.getProperty("param.title.G11d"); subtitle = repositoryConfig.getProperty("param.subtitle.G11d.absolute");...reportContext.setPersistentGlobalVariable("abs_perc", params["param"]); reportContext.setPersistentGlobalVariable("width", width); reportContext.setPersistentGlobalVariable("height", height);reportContext.setPersistentGlobalVariable("margin_left", margin_left);...</pre><p>So, the only thing I would have to change in order to generate different parameters is the report name (p.e. #G11a).</p><p> </p><p>The interesting part is the way I define the (Y) series and chart type.</p><div><pre class="_prettyXprint">..param.series.definition.G11a = in_scope;out_scope;totalparam.series.type.G11a = bar;bar;line..</pre><p>Later, in the <em>beforeFactory </em>method I perform the following script:</p><div><pre class="_prettyXprint">importPackage(Packages.org.eclipse.birt.chart.model.data.impl);importPackage(Packages.org.eclipse.birt.chart.model.component.impl);importPackage(Packages.org.eclipse.birt.chart.model.type.impl);importPackage(Packages.org.eclipse.birt.chart.model.attribute);importPackage(Packages.org.eclipse.birt.chart.script.api)// Get chart handler. Chart name: "my_chart"cht = reportContext.getDesignHandle().findElement("my_chart");mychart = cht.getReportItem().getProperty("chart.instance");//remove bindingscht.removedUnusedColumnBindings();// Margin Master Pagemargin_left = reportContext.getPersistentGlobalVariable('margin_left');reportContext.getReportRunnable().designHandle.getDesignHandle().findMasterPage("Simple MasterPage").setProperty("leftMargin", margin_left+"in" );// Chart sizewidth = reportContext.getPersistentGlobalVariable('width');height = reportContext.getPersistentGlobalVariable('height');cht.setWidth(width);cht.setHeight(height);// Getting global variablesseries = reportContext.getPersistentGlobalVariable('series');series_type = reportContext.getPersistentGlobalVariable('series_type');series_visibility = reportContext.getPersistentGlobalVariable('series_visibility');total_visibility = reportContext.getPersistentGlobalVariable('total_visibility');thickness = reportContext.getPersistentGlobalVariable('thickness');// Convert series into array p.e in_scope;out_scope;totalseries_arr = series.split(";", -1); series_arr_type = series_type.split(";", -1); series_arr_visibility = series_visibility.split(";", -1); //Get the x axisxAxis = mychart.getAxes().get(0);//Get the first y axisyAxis1 = xAxis.getAssociatedAxes().get(0);//Clear all series definitions defined for the second Y-axis.yAxis1.getSeriesDefinitions().clear();//Packages.java.lang.System.out.println ("serie xx: " + xAxis.getSeriesDefinitions()[0].getSeries()[0].getDataDefinition()[0].getDefinition());// Iterate over series definitionfor( idx=0; idx < series_arr.length; idx++ ){ var sdNew = SeriesDefinitionImpl.create(); var chart = null; //Create the query. The row value must correlate with the data set row value var qry = QueryImpl.create("dataSetRow[""+series_arr[idx]+""]"); if (series_arr_type[idx].toUpperCase() == "BAR"){ chart = BarSeriesImpl.create(); if (series_arr_visibility[idx] == 1){ chart.getLabel().setVisible(true); }else{ chart.getLabel().setVisible(false); } chart.setLabelPosition( Position.INSIDE_LITERAL); chart.getDataDefinition().add(qry); chart.setStacked(true);}else if(series_arr_type[idx].toUpperCase() == "LINE"){ var chart = LineSeriesImpl.create(); if (series_arr_visibility[idx] == 1){ chart.getLabel().setVisible(true);}else{ chart.getLabel().setVisible(false);} chart.setLabelPosition( Position.ABOVE_LITERAL); chart.getDataDefinition().add(qry); //Packages.java.lang.System.out.println ("VISISI: " + total_visibility); if (total_visibility == "1"){ chart.getLineAttributes().setVisible(true); chart.setPaletteLineColor(true); var line_attr = chart.getLineAttributes(); // grosor lÃnea - necesario param para que sea visible - "chart.getLineAttributes().setVisible(true);" line_attr.setThickness(thickness); chart.setLineAttributes(line_attr); }else{ chart.getLineAttributes().setVisible(false); } }else if(series_arr_type[idx].toUpperCase() == "AREA"){ var chart = AreaSeriesImpl.create(); if (series_arr_visibility[idx] == 1){ chart.getLabel().setVisible(true); }else{ chart.getLabel().setVisible(false); } chart.setLabelPosition( Position.ABOVE_LITERAL); chart.getDataDefinition().add(qry); chart.setStacked(true); } sdNew.getSeries().add( chart ); //Add the new series definition yAxis1.getSeriesDefinitions().add( sdNew ); }</pre><p>Finally, in the <em>beforeGeneartion </em>(used for fill the series color, by .js script - getColorByName is a .js script containing the logic to set the color according to a received name)<em> </em>and <em>beforeDataSetFilled </em>(used in order to change the series name)<em>:</em></p><pre class="_prettyXprint">/** * Called before generation of chart model to GeneratedChartState. * *
@param chart * Chart *
@param icsc * IChartScriptContext */function beforeGeneration( chart, icsc ){ importPackage(Packages.org.eclipse.birt.chart.model.attribute); importPackage(Packages.org.eclipse.birt.chart.model.attribute.impl); getColorByName = icsc.getExternalContext().getScriptable().getPersistentGlobalVariable("getColorByName"); //Packages.java.lang.System.out.println ("cata1 - cat2: " + cat_1 +" -- "+cat_2 ); var xAxis = chart.getAxes().get(0); var yAxis = xAxis.getAssociatedAxes().get(0); //Load series from parameter param.series.definition.Gxx series = icsc.getExternalContext().getScriptable().getPersistentGlobalVariable('series'); // Convert series into array p.e in_scope;out_scope;total series_arr = series.split(";", -1); for( idx=0; idx < series_arr.length; idx++ ){ var sd = yAxis.getSeriesDefinitions().get(idx); sd.getSeriesPalette().getEntries().clear(); var rgb = getColorByName(series_arr[idx]); sd.getSeriesPalette().getEntries().add( GradientImpl.create( ColorDefinitionImpl.create(rgb[0],rgb[1],rgb[2]), ColorDefinitionImpl.create(rgb[0],rgb[1],rgb[2]), 0, false)); } }function beforeDataSetFilled( series, idsp, icsc ){ importPackage(Packages.java.util); importPackage(Packages.org.eclipse.birt.chart.model.data.impl); importPackage(Packages.org.eclipse.birt.chart.model.component.impl); importPackage(Packages.org.eclipse.birt.chart.model.type.impl); importPackage(Packages.org.eclipse.birt.chart.model.attribute); var chart = icsc.getChartInstance(); var xAxis = chart.getAxes().get(0); var yAxis = xAxis.getAssociatedAxes().get(0); //Set the series name series = icsc.getExternalContext().getScriptable().getPersistentGlobalVariable('series'); // Convert series into array p.e in_scope;out_scope;total series_arr = series.split(";", -1); for( idx=0; idx < series_arr.length; idx++ ){ if (series_arr[idx] != "total"){ var xSerieDef = yAxis.getSeriesDefinitions().get(idx); xSerieDef.getSeries().get(0).setSeriesIdentifier(series_arr[idx]); } }}</pre><p>Up to now, Im able to dinamically set; dataset, datasource, Y series, title, subtilte, colors, etc, but I'm not able yet to dinamically add the category series (X). I would like to have a parameter in the properties for example:</p><pre class="_prettyXprint">param.series.category.G11a = year</pre><p>And then, using script be able to dinamically add it. </p><p>Any idea?</p><p> </p><p>Thanks in advance and excuse the huge amount of code here.</p></div></div></div></div>