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)
how to dynamic set series title
foolcatjr
There are 4 series, I can set the title for each one in the designer, and there is a parameter, what should I do if I want to change the series's title by diffent parameter's value?<br />
For example, the parameter name is <em class='bbc'>title_type</em>, when set <em class='bbc'>title_type=a</em>, I want the title of <strong class='bbc'>series 1</strong> is <strong class='bbc'>"typea"</strong> , when set set <em class='bbc'>title_type=b</em>, I want the title of <strong class='bbc'>series 1</strong> is <strong class='bbc'>"typeb"</strong>
Find more posts tagged with
Comments
mwilliams
Hi foolcatjr,
Is this just something you want for dynamically naming the series' in the legend? If so, you could just change the text in the series labels in the legend itself.
foolcatjr
<blockquote class='ipsBlockquote' data-author="'mwilliams'" data-cid="66218" data-time="1278527272" data-date="07 July 2010 - 11:27 AM"><p>
Hi foolcatjr,<br />
<br />
Is this just something you want for dynamically naming the series' in the legend? If so, you could just change the text in the series labels in the legend itself.<br /></p></blockquote>
<br />
<br />
I mean the "title" value in the designer view, every series was set the title "Series 1""Series 2""Series 3" .... by default.<br />
<br />
I attached 2 pics, want to change the first one to the secend. <br />
<br />
If what you said is what I want, there's another problem, how to change the series label dynamically ? <br />
<br />
Thx
foolcatjr
I tried to set the label's value in <strong class='bbc'>beforeGeneration</strong> function, but it doesn't work.<br />
<br />
<strong class='bbc'>var xAxis = chart.getAxes().get(0);<br />
var yAxis = xAxis.getAssociatedAxes().get(0);<br />
yAxis.getSeriesDefinitions().get(0).getRunTimeSeries().get(0).getLabel().getCaption().setValue("PA");</strong><br />
<br />
nothing happened :wacko: :wacko:
mwilliams
You can change the axis value in the beforeDrawAxisLabel function and you can change the labels in the legend in the beforeDrawLegendItem function, I believe. Let me know if you have questions. I can make a quick example if need be.
foolcatjr
<blockquote class='ipsBlockquote' data-author="'mwilliams'" data-cid="66265" data-time="1278613099" data-date="08 July 2010 - 11:18 AM"><p>
You can change the axis value in the beforeDrawAxisLabel function and you can change the labels in the legend in the beforeDrawLegendItem function, I believe. Let me know if you have questions. I can make a quick example if need be.<br /></p></blockquote>
<br />
well, I didn't describe the problem clearly.<br />
In the beforeDrawLegendItem function, it really can change the label, but that is not I want.<br />
So, I upload a report, you can see the series title "Series 1""Series 2" in the legend area, could you please show me how to change the "Series 1" to any other value by script ?<br />
<br />
Thanks for your attention and help.
mwilliams
If there is no optional grouping set in the chart, the Series titles can be changed in the beforeDrawLegendItem function, but not when there is optional grouping. I'm not exactly sure why this is. I'll look into this and let you know if I find anything.
foolcatjr
<blockquote class='ipsBlockquote' data-author="'mwilliams'" data-cid="66301" data-time="1278686580" data-date="09 July 2010 - 07:43 AM"><p>
If there is no optional grouping set in the chart, the Series titles can be changed in the beforeDrawLegendItem function, but not when there is optional grouping. I'm not exactly sure why this is. I'll look into this and let you know if I find anything.<br /></p></blockquote>
<br />
thanks anyway
mwilliams
Try something like this:<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
function beforeGeneration( chart, 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 xAxis = chart.getAxes().get(0);
var yAxis = xAxis.getAssociatedAxes().get(0);
var xSerieDef = xAxis.getSeriesDefinitions().get(0);
var ySerieDef1 = yAxis.getSeriesDefinitions().get(0);
var ySerieDef2 = yAxis.getSeriesDefinitions().get(1);
ySerieDef1.getSeries().get(0).setSeriesIdentifier("My Series 1");
ySerieDef2.getSeries().get(0).setSeriesIdentifier("My Series 2");
}
</pre>
foolcatjr
<blockquote class='ipsBlockquote' data-author="'mwilliams'" data-cid="66357" data-time="1278963678" data-date="12 July 2010 - 12:41 PM"><p>
Try something like this:<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
function beforeGeneration( chart, 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 xAxis = chart.getAxes().get(0);
var yAxis = xAxis.getAssociatedAxes().get(0);
var xSerieDef = xAxis.getSeriesDefinitions().get(0);
var ySerieDef1 = yAxis.getSeriesDefinitions().get(0);
var ySerieDef2 = yAxis.getSeriesDefinitions().get(1);
ySerieDef1.getSeries().get(0).setSeriesIdentifier("My Series 1");
ySerieDef2.getSeries().get(0).setSeriesIdentifier("My Series 2");
}
</pre></p></blockquote>
<br />
yes, it's perfect. <br />
Thanks a lot.<br />
The BIRT's API is hard to follow ... ,
mwilliams
Not a problem. Have you looked at the documentation? Or is that what is confusing?
djatnieks
Did you find out more about this? I am using Birt 2.5.2 and this is still a problem. Is there a workaround?<br />
<br />
I am creating my own Y series using javascript and am using setSeriesIdentifier() to set the legend labels. If I also call ySeriesDef.setQuery() method to set the optional y-axis grouping, then all the series identifiers seem to have no effect later in beforeDrawLegendItem(), e.g. lerh.getLabel().getCaption().getValue() always returns empty string (or null, not sure which).<br />
<br />
(sorry- in my searching for info on this problem, i thought i was posting to an old thread, but i see it is quite recent)<br />
<br />
<blockquote class='ipsBlockquote' data-author="'mwilliams'" data-cid="66301" data-time="1278686580" data-date="09 July 2010 - 07:43 AM"><p>
If there is no optional grouping set in the chart, the Series titles can be changed in the beforeDrawLegendItem function, but not when there is optional grouping. I'm not exactly sure why this is. I'll look into this and let you know if I find anything.<br /></p></blockquote>
foolcatjr
<blockquote class='ipsBlockquote' data-author="'mwilliams'" data-cid="66388" data-time="1279054484" data-date="13 July 2010 - 01:54 PM"><p>
Not a problem. Have you looked at the documentation? Or is that what is confusing?
<br /></p></blockquote>
<br />
Yes, I read and searched the official documents before post the question.<br />
<br />
The problem is I don't know which method match the property I want to set, or where to write the script.<br />
Take this question for example, there are 3 methods as follow:<br />
java.util.List<Series> getRunTimeSeries() <br />
org.eclipse.emf.common.util.EList getSeries() <br />
org.eclipse.emf.common.util.EList getSeriesDefinitions() <br />
I don't know what's the difference between them, so don't know which to use.<br />
Besides, where to write the script? At first, I tried to write the scripts in beforeDrawSeriesTitle() and beforeDrawLegendItem() and so on, and there's no document to say how to use them.
mwilliams
Hi djatnieks,
Post #9 in this thread should have the answer you're looking for I think.
foolcatjr - Whenever you have a question, feel free to ask in here and hopefully someone else will have done what you're trying to do or we can follow the documentation til we find what works!
djatnieks
Hi again,<br />
<br />
Sorry for not being clear; I was specifically asking about the case where the optional Y-Axis grouping is set. This was mentioned in post #7. In this case the solution listed in #9 does not work.<br />
<br />
<br />
<blockquote class='ipsBlockquote' data-author="'mwilliams'" data-cid="66475" data-time="1279221814" data-date="15 July 2010 - 12:23 PM"><p>
Hi djatnieks,<br />
<br />
Post #9 in this thread should have the answer you're looking for I think.<br />
<br /></p></blockquote>
foolcatjr
<blockquote class='ipsBlockquote' data-author="'mwilliams'" data-cid="66475" data-time="1279221814" data-date="15 July 2010 - 12:23 PM"><p>
Hi djatnieks,<br />
<br />
Post #9 in this thread should have the answer you're looking for I think.<br />
<br />
foolcatjr - Whenever you have a question, feel free to ask in here and hopefully someone else will have done what you're trying to do or we can follow the documentation til we find what works!
<br /></p></blockquote>
<br />
I love this forum, thank you again.<br />
<br />
djatnieks -- the #9 exactly solve the problem in #7, my original question is the same as yours, #9 worked perfect.
actuser9
Hi Michael,<br />
<br />
Using Classic Models database, I have created a chart with in a list that is grouped by "Product Name". I have a requirement to show something like this in the chart legend.<br />
<br />
The series 1 of the bar chart is designed as below. <br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
if (row["Method"] =='Method1')
row["BUYPRICE"]
else
row["MSRP"]
</pre>
<br />
I need to get the series 1 title based on the same logic. But the below script on the chart does not seem to work. <br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
function beforeDrawLegendItem(lerh, bounds, icsc)
{
if( lerh.getLabel().getCaption().getValue().compareToIgnoreCase("Series 1") == 0)
{
if (icsc.getExternalContext().getScriptable().getPersistentGlobalVariable("y_SeriesTitle") == 'Method1' )
{
lerh.getLabel().getCaption().setValue("Buy Price"); }
if( icsc.getExternalContext().getScriptable().getPersistentGlobalVariable("y_SeriesTitle") == 'Method2' )
{
lerh.getLabel().getCaption().setValue("MSRP"); }
}
</pre>
<br />
Any idea what am I missing here. Attached the report for your reference.<br />
<br />
actuser9
Hi,
I am excited to say that I got this to work. Attached the working report.
Thanks for all those who care to share the DevShare content.
mwilliams
Hey. Sorry I wasn't in the designing forum in time to catch your question before you found the answer. Either way, I'm glad you got it working!
actuser9
Sure Michael. Not a problem at all.<br />
<br />
I have a quick question. I need to implement the same logic for the Flash Chart. <br />
<br />
I don't see the equivalent code that could be used for the flash chart to change the series title as below.<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
function beforeDrawLegendItem(lerh, bounds, icsc)
{
if( lerh.getLabel().getCaption().getValue().compareToIgnoreCase("Series 1") == 0)
{
if (icsc.getExternalContext().getScriptable().getPersistentGlobalVariable("chartTitle") == 'Method1' )
{
lerh.getLabel().getCaption().setValue("Buy Price"); }
if( icsc.getExternalContext().getScriptable().getPersistentGlobalVariable("chartTitle") == 'Method2' )
{
lerh.getLabel().getCaption().setValue("MSRP"); }
}
}
</pre>
<br />
How to get "getPersistentGlobalVariable("chartTitle") " into the Flash Chart script? I am not able to find such class for Flash Chart.<br />
<br />
Thanks<br />
UY
mwilliams
Try this code, in a flash chart, exactly like the non flash one, in your example, above:<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
function beforeRendering( flashChart, fcsc )
{
chart = flashChart.getChart();
xAxis = chart.getBaseAxes()[0];
yAxis = chart.getOrthogonalAxes( xAxis, true)[0];
ySerieDef = yAxis.getSeriesDefinitions().get(0);
runSeries = ySerieDef.getRunTimeSeries();
var series = runSeries.get(0);
if (fcsc.getExternalContext().getScriptable().getPersistentGlobalVariable("chartTitle") == 'Method1' )
{
series.setSeriesIdentifier("Buy Price");
}
else if( fcsc.getExternalContext().getScriptable().getPersistentGlobalVariable("chartTitle") == 'Method2' )
{
series.setSeriesIdentifier("MSRP");
}
}
</pre>
actuser9
Cool. That worked perfect. Thanks Michael.
Regards
UY
PascalH
<p>Maybe still anyone on this topic? i have nearly the same problem but dont get it running</p>
PascalH
<p>I am using a Line Chart with several Value Series. One of them looks like</p>
<p><b>if</b>(row["Beschriftung"]=="Variante2") {</p>
<p>row["xy"]</p>
<p>}</p>
<p><b>else </b><b>if</b> (row["Beschriftung"]=="Variante1"){</p>
<p>row["zw"]</p>
<p>}</p>
<p>Depending on a paramater Input letz call it ID my dataset results in Variante1 or Variante2.</p>
<p> </p>
<p>Now my Problem is i want depending on the ID my LegendItems to be changed, That means i.e. if ID=1 i need set1 of legenditems if ID=2 i need another Set. </p>
<p>I tried the Scripting like Actuser did but as i see he address the globalPersistentVariable(y-seriestitle) which doesnt help for me.</p>
<p>my next try looks like that but i dont know how to use the ySerieDef in my if statement. Means depending on the Series Definition that is based on the Expression listed above i want to change the legendItem describtion.</p>
<p>The Process looks like : param["ID"] -> the series field with computes based on this input -> change seriesTitle based on the computed result</p>
<p><b>function </b>afterDataSetFilled( series, dataSet, icsc )</p>
<p>{</p>
<p><b>var</b> chart = icsc.getChartInstance();</p>
<p>importPackage(Packages.java.util);</p>
<p>importPackage(Packages.org.eclipse.birt.chart.model.data.impl);</p>
<p>importPackage(Packages.org.eclipse.birt.chart.model.component.impl);</p>
<p>importPackage(Packages.org.eclipse.birt.chart.model.type.impl);</p>
<p>importPackage(Packages.org.eclipse.birt.chart.model.attribute);</p>
<p><b>var </b>xAxis = chart.getAxes().get(0);</p>
<p><b>var</b> yAxis = xAxis.getAssociatedAxes().get(0);</p>
<p><b>var</b> xSerieDef = xAxis.getSeriesDefinitions().get(0);</p>
<p><b>var</b> ySerieDef1 = yAxis.getSeriesDefinitions().get(4);</p>
<p><b>if</b>(){</p>
<p>ySerieDef1.getSeries().get(0).setSeriesIdentifier("test1");}</p>
<p><b>else </b><b>if</b> ( ) {</p>
<p>ySerieDef1.getSeries().get(0).setSeriesIdentifier("test2");}</p>
<p><b>else{</b></p>
<p>ySerieDef1.getSeries().get(0).setSeriesIdentifier("Test3");}</p>
<p>}</p>
mwilliams
<p>You can check the parameter value in your chart script with:</p>
<p> </p>
<p></p><pre class="_prettyXprint _linenums:0">icsc.getExternalContext().getScriptable().getParameterValue("ID");
</pre>
<p> </p>
<p>Based on that value, you can change your series names or just the labels in the legend.</p>
PascalH
<p>that helped thanks alot</p>
mwilliams
<p>You're welcome. Let us know whenever you have questions.
</p>
babbarbhangoo
<p>Hi MWilliams,</p>
<p> </p>
<p>I am trying to set the title of the y-axis series at run time. This is because the names need to come from a parameter value which i cannot put directly in chart UI.</p>
<p>Meaning the legend should display the names set during run time. My chart has two y axis series and a secondary y axis. Secondary y-axis label is constant and doesn't need to change but the two y axis series titles need to be changed.</p>
<p> </p>
<p>As displayed in the screenshot I am getting the default series titles in legend - "Series 1" and "Series 2" but I need the dates to be displayed.</p>
<p> </p>
<p>I tried the code in post #9 and the code for beforeDrawLegendItem but it is not working. </p>
<p>The code in post #9 does not give me any errors when I put it in chart script but it is also not making any change to legend labels. </p>
<p>If I put code in beforeDrawLegendItem I get some error.</p>
<p>I am using Birt 4.4.2.</p>
<p> </p>
<p>Any help is highly appreciated.</p>
<p> </p>
<p>Thanks in advance!</p>
<p> </p>
<p>Edit: Attached sample code file</p>