Home
Intelligence (Analytics)
How to access Optional Y Series Grouping?
djatnieks
I have a line series chart in my report that has the "optional Y Series Grouping" defined and I would like to access this information through javascript.<br />
<br />
Using Birt 2.3.1<br />
<br />
Here is what I have tried in the beforeFactory code:<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
var newxAxis = chart.getBaseAxes()[0];
var newyAxis = chart.getOrthogonalAxes( newxAxis, true)[0]
var newseriesDef = newyAxis.getSeriesDefinitions().get(0)
var runSeries = newseriesDef.getRunTimeSeries();
log("runSeries.size()= " + runSeries.size() );
</pre>
<br />
When this runs, the value for runSeries.size() = 0.<br />
<br />
This is based on code I saw suggested in another post.<br />
<br />
Is this the wrong way to access the Opt. Y Series Grouping information? Is there another way? Is it maybe not possible to access it in beforeFactory?<br />
<br />
Thanks<br />
<br />
dan
Find more posts tagged with
Comments
JasonW
Dan
What script are you doing this in? I set up a line chart with option y series grouping and used your script in the beforeGeneration and it worked fine. You should be able to access the query like:
var newxAxis = chart.getBaseAxes()[0];
var newyAxis = chart.getOrthogonalAxes( newxAxis, true)[0]
var newseriesDef = newyAxis.getSeriesDefinitions().get(0)
var myQuery = newseriesDef.getQuery().getDefinition();
Jason
djatnieks
Jason,<br />
<br />
I am doing this in the beforeFactory script. It looks like I was off a little bit - I got the series definition but was looking at getRunTimeSeries instead of getQuery().getDefinition(). I used your code and that works, thanks.<br />
<br />
But now I am confused - I thought that <br />
newyAxis.getSeriesDefinitions().get(0)<br />
would be the main Y-axis line definition rather than the optional Y series grouping?<br />
<br />
What I am trying to do is to customize the Y axis of a chart with code. I start with a sample chart, then I remove the existing Y axis line series, which is what I thought newyAxis.getSeriesDefinitions().get(0) was doing for me. In fact I have all that working and what I was trying to do now is to add the optional Y series grouping.<br />
<br />
Here's some more details of what I am doing ... any suggestions? Where would I add code to create the optional Y series grouping here?<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
// Get the x axis
var xAxis =cm.getAxes().get(0);
// Get the predefined series definition from the report design and remove it
var yAxis1 = xAxis.getAssociatedAxes().get(0);
yAxis1.getSeriesDefinitions().remove(0);
// Create a new series definition for each new series
var seriesDef = SeriesDefinitionImpl.create();
// Line chart
var ls = LineSeriesImpl.create();
// Create the query.
var qry = QueryImpl.create("row["series1"]" );
// Add the query to the series definition
ls.getDataDefinition().add(qry)
seriesDef.getSeries().add( ls );
// Add the new series definition to the first y axis
yAxis1.getSeriesDefinitions().add( seriesDef );
</pre>
JasonW
Take a look at this image to help clarify:
You are adding your query to the line series not the series definition which is correct. If you add the query to the series definition for the y axis this sets up optional y series grouping:
SeriesDefinition sdGroup = SeriesDefinitionImpl.create( );
Query query = QueryImpl.create( "row["Month"]" );
sdGroup.setQuery( query );
So just create one more query object and add it to the series definition.
djatnieks
Ok, I think I worked it out ...
Starting with a SeriesDefinition, then
getSeries() gets the list of Y axis series
and
getQuery() gets me the optional Y series grouping query.
So, I can get and save the Optional Y Series grouping from the chart with this:
var myQuery = yAxis1.getSeriesDefinitions().get(0).getQuery();
And then after I build the new line series, I can add it with this:
seriesDef.setQuery(myQuery);
JasonW
try the image again in zip
JasonW
That is correct
djatnieks
Jason,
Thanks, I think that makes sense to me now... and thanks for the picture too, that helps a lot!
dan