Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
PUBLIC CLOUD
PRIVATE CLOUD
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Intelligence (Analytics)
charts - how to use row values in series title
birtslash
hi all<br />
<br />
i wonder if there is a way for using dataSetRow values as series title in a chart.<br />
<br />
on the 3rd tab ("format chart") in the properties panel of my chart i can modify the <strong class='bbc'>series titles</strong>. i can use localized labels, but i would like to use an expression like <br />
<em class='bbc'>"from <VALUEOF>row[SOURCE]</VALUEOF> to <VALUEOF>row[TARGET]</VALUEOF>"</em>.<br />
<br />
the only solution i found so far is to do it programmatically via scripting this way:<br />
<em class='bbc'>yAxis.getSeriesDefinitions().get(0).getSeries().get(0).setSeriesIdentifier("my new series name");</em><br />
...but i hope there must be more convenient way to do that.<br />
<br />
if the only way to do it is by scripting,... how can i access the table/dataset data within the script? <br />
<br />
thanks for any hints in advance<br />
bartek
Find more posts tagged with
Comments
kclark
Hi birtslash! The only way to do what you're trying to do is by scripting. You can always put in a request for an <a class='bbc_url' href='
https://bugs.eclipse.org/bugs/enter_bug.cgi?product=BIRT'>enhancement</a>
;
birtslash
<blockquote class='ipsBlockquote' data-author="'kclark'" data-cid="112040" data-time="1354642788" data-date="04 December 2012 - 10:39 AM"><p>
Hi birtslash! The only way to do what you're trying to do is by scripting. You can always put in a request for an <a class='bbc_url' href='
https://bugs.eclipse.org/bugs/enter_bug.cgi?product=BIRT'>enhancement</a><br
/></p></blockquote>
<br />
ok. thank you for the quick answer. <br />
could you please give me some hints how to do it.<br />
<br />
basically i've got a linechart and on the y-axis i use 4 series.<br />
i try to set the seriesidentifier in the <em class='bbc'>onRender()</em> section of the chart script.<br />
<br />
here i inserted the following code:<br />
<br />
<sub class='bbc'>function beforeDataSetFilled( series, idsp, icsc ) {<br />
<br />
var xAxis = chart.getAxes().get(0);<br />
var yAxis = xAxis.getAssociatedAxes().get(0);<br />
var xSerieDef = xAxis.getSeriesDefinitions().get(0);<br />
var ySerieDef = yAxis.getSeriesDefinitions().get(0);<br />
<br />
if (series.getSeriesIdentifier() == "actual_series_name_1") {<br />
series.setSeriesIdentifier("my_new_series_name_1");<br />
ySerieDef.getSeries().get(0).setSeriesIdentifier("my_new_series_name_1");<br />
}<br />
else if (series.getSeriesIdentifier() == "actual_series_name_2") {<br />
series.setSeriesIdentifier("my_new_series_name_2");<br />
ySerieDef.getSeries().get(0).setSeriesIdentifier("my_new_series_name_2");<br />
}<br />
}</sub><br />
<br />
i can see (debug log) the code is executed for each of the 4 series - i get the seriesidentifiers displayed.<br />
i would expect now, the series get renamed as desired and that the legend items for these series get renamed as well. the result is that only the first serie is renamed which i can see in the legend, it seems the other series remain unmodified. <br />
what am i doing wrong?
birtslash
well, i found the solution by myself (see below). setting the series ids is enough, the legend labels are set accordingly.<br />
<br />
<sub class='bbc'><br />
function beforeGeneration( chart, icsc ) {<br />
<br />
importPackage(Packages.java.util);<br />
importPackage(Packages.org.eclipse.birt.chart.model.data.impl);<br />
importPackage(Packages.org.eclipse.birt.chart.model.component.impl);<br />
importPackage(Packages.org.eclipse.birt.chart.model.type.impl);<br />
importPackage(Packages.org.eclipse.birt.chart.model.attribute); <br />
<br />
var xAxis = chart.getAxes().get(0);<br />
var yAxis = xAxis.getAssociatedAxes().get(0);<br />
<br />
// set identifiers for series 1 to 4<br />
yAxis.getSeriesDefinitions().get(0).getSeries().get(1).setSeriesIdentifier( "new_id_1" );<br />
yAxis.getSeriesDefinitions().get(1).getSeries().get(1).setSeriesIdentifier( "new_id_2" );<br />
yAxis.getSeriesDefinitions().get(2).getSeries().get(1).setSeriesIdentifier( "new_id_3" );<br />
yAxis.getSeriesDefinitions().get(3).getSeries().get(1).setSeriesIdentifier( "new_id_4" );<br />
}<br />
</sub><br />
<br />
i think, if you want to change only the legend titles, i've found the following solution which tackles it<br />
<br />
<sub class='bbc'>function beforeDrawLegendItem ( lerh, bounds, icsc ) {<br />
<br />
var caption = lerh.getLabel().getCaption();<br />
<br />
if ( caption.getValue().compareToIgnoreCase("current_legend_title_1") == 0 ) {<br />
caption.setValue( "new_legend_title_1" ); <br />
}<br />
else if ( caption.getValue().compareToIgnoreCase("current_legent_title_2") == 0 ) {<br />
caption.setValue( "new_legend_title_2" ); <br />
}<br />
}</sub><br />
<br />
regards<br />
bartek