|
|
|
|
|
Re: Axis Markers AddLine and AddRange should support the X Axis Datatype [message #1090780 is a reply to message #1090692] |
Tue, 20 August 2013 12:29   |
Eclipse User |
|
|
|
Ok, I found a solution that works fine for me. It's a mashup of tutorials 
The marker values are stored as persistent variables in a data sets onFetch event.
reportContext.setPersistentGlobalVariable("DOvar", row["DO"]);
reportContext.setPersistentGlobalVariable("DIvar", row["DI"]);
reportContext.setPersistentGlobalVariable("cptvar", row["cpt"]);
in the charts onRender event I do the following:
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.data.impl);
importPackage(Packages.org.eclipse.birt.chart.model.attribute);
importPackage(Packages.org.eclipse.birt.chart.model.attribute.impl);
function beforeGeneration( chart, icsc )
{
/* This script will change the Min and Max value of the X axis based on the value
for the Start and End date parameters.
NB: In order to work, make sure to turn OFF the "Is Category Axis" attribute
in the X-Axis properties screen
Further the DI, cpt and DO markers gets insertet into the chart with values talen from
persistent variables that are set in the Release afterFetchData event.
*/
/* Get the start and end dates from the parameters */
var startDate_p = getPersistentGlobalVariable("DIvar");
var cpt_value = getPersistentGlobalVariable("cptvar");
var endDate_p = getPersistentGlobalVariable("DOvar");
/* Convert the dates from YYYY-MM-DD to DD/MM/YYYY */
startDate = new Date((startDate_p.getMonth() + 1) + "/" + startDate_p.getDate() + "/" + (startDate_p.getYear() + 1900));
cptDate = new Date((cpt_value.getMonth() + 1) + "/" + cpt_value.getDate() + "/" + (cpt_value.getYear() + 1900));
endDate = new Date((endDate_p.getMonth() + 1) + "/" + endDate_p.getDate() + "/" + (endDate_p.getYear() + 1900));
/* Get the X-Axis object */
xAxisArray = chart.getBaseAxes();
/* Set the Min and Max values */
xAxisArray[0].getScale().setMin(DateTimeDataElementImpl.create(startDate));
xAxisArray[0].getScale().setMax(DateTimeDataElementImpl.create(endDate));
var chart = icsc.getChartInstance();
di_ml = MarkerLineImpl.create(xAxisArray[0], DateTimeDataElementImpl.create(startDate));
di_ml.getLabel().getCaption().setValue("DI");
di_ml.getLineAttributes().getColor().set(255,102,0);
cpt_ml = MarkerLineImpl.create(xAxisArray[0], DateTimeDataElementImpl.create(cptDate));
cpt_ml.getLabel().getCaption().setValue("cpt");
cpt_ml.getLineAttributes().getColor().set(89,89,89);
do_ml = MarkerLineImpl.create(xAxisArray[0], DateTimeDataElementImpl.create(endDate));
do_ml.getLabel().getCaption().setValue("DO");
do_ml.getLineAttributes().getColor().set(255,204,0);
}
The trick is to use DateTimeDataElementImpl to isnert the date values 
Thank you!
|
|
|
|
Powered by
FUDForum. Page generated in 0.03170 seconds