Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
THRUST SERVICES & TOOLS
CLOUD EDITIONS
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Intelligence (Analytics)
Dynamic x-axis markers from dataset values
paqman
Hello all,<br />
<br />
I've been looking all over the internet for a way to create x-axis markers using values from a dataset (create 1 marker for each value) but have only found partial solutions. I am at the point where I have static x-axis markers - in my chart, within the onRender script:<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>function beforeGeneration( chart, icsc )
{
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);
var reportContext = icsc.getExternalContext().getScriptable();
var dates = new Array();
dates[0] = new Date(2011,1,12);
dates[1] = new Date(2011,2,15);
var chart = icsc.getChartInstance();
var xaxis = chart.getPrimaryBaseAxes()[0];
var new_ml;
for (x in dates) {
new_ml = MarkerLineImpl.create(xaxis, DateTimeDataElementImpl.create(dates[x]));
new_ml.setLabelAnchor(Anchor.NORTH_WEST_LITERAL);
xaxis.getMarkerLines().add(new_ml);
}
}</pre>
<br />
When rendering the chart, I see two markers as expected. All the searching I've done tells me that I need to get the dataset values into a global variable and then read the values back - I have yet to find a way to do this. <br />
<br />
Any help or suggestions would be greatly appreciated. Thanks!!<br />
<br />
David
Find more posts tagged with
Comments
pricher
David,
You are right: you need to use global variables since the data set is not available to you on the onRender event of the chart.
So, to write a value from a dataset to a global variable, you can use the following syntax:
reportContext.setPersistentGlobalVariable("g_compIdxList", this.getRowData().getColumnValue("CompIdxColor"))
To read it back in the onRender method of the chart, use:
var myVar = icsc.getExternalContext().getScriptable().getPersistentGlobalVariable("g_compIdxList")
Hope this helps,
P.
paqman
Thanks for the reply! That will require 1 variable for each marker I want to add, correct?