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)
Pie chart. Add series item value to legend item
tamoler
Hi. I need to hide value series label on pie chart & add the value and percentage into legend item. How can i do that? i found how can i change legend item text. smth like:
function beforeDrawLegendItem( lerh, bounds, icsc )
{
var x = lerh.getLabel().getCaption().getValue();
lerh.getLabel().getCaption().setValue(x);
}
But i cant find how can i get value series label value...
Help me plz...
Find more posts tagged with
Comments
kclark
You can use a script like this to get the value of each label then add it to an array. Then you can change the label in your legend to match by looping back through that array. Make sure to hide the leader lines or you'll have lines with no label.<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>var test = new Array();
var i = 0;
var j = 0;
function beforeDrawLegendItem( lerh, bounds, icsc )
{
lerh.getLabel().getCaption().setValue(test[j]);
j++;
}
function beforeDrawDataPointLabel( dph, label, icsc )
{
test[i] = label.getCaption().getValue();
label.getCaption().setValue("");
i++;
}
</pre>
<br />
I've attached an example report, let me know if you have any questions.
actuser9
Hi kclark,
The solution looks good. I am looking for something similar but based on the data set result. I have attached a report with a bar chart. The first series "series1" should pull the first row value of the "Legend" column in the data set as its legend name which is "One" and the second series as "Two" etc.
Alternatively, "Legend" column values can be split across three columns and can be used but is it possible to get the legend name based on the data set single column "Legend?
actuser9
Hi,
Any suggestions on possible solutions for this issue?
Thanks
UY
actuser9
Hi,
Is the possible solution for this issue would be to convert the column data into rows? Any other suggestions?
Thanks
UY
kclark
I've added "legend" to the optional y series grouping to get the following to get the following
actuser9
Thank you Clark. But the attached legend output is what I am looking for. In the chart, the colors of the series and bar width remain the same.
Regards,
UY
kclark
I've attached an example of how I got this working. In your scripted dataset I added the legend values to a PGV array like this<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
i = 0;
var array = new java.util.ArrayList();
sourcedata = new Array( new Array(5),
new Array(5),
new Array(5),
new Array(5),
new Array(5));
sourcedata[0][0] = "Item1";
sourcedata[0][1] = 25;
sourcedata[0][2] = 10;
sourcedata[0][3] = 15;
sourcedata[0][4] = "One";
array.add(sourcedata[0][4]);
sourcedata[1][0] = "Item2";
sourcedata[1][1] = 35;
sourcedata[1][2] = 15;
sourcedata[1][3] = 10;
sourcedata[1][4] = "Two";
array.add(sourcedata[1][4]);
sourcedata[2][0] = "Item3";
sourcedata[2][1] = 15;
sourcedata[2][2] = 25;
sourcedata[2][3] = 10;
sourcedata[2][4] = "Three";
array.add(sourcedata[2][4]);
reportContext.setPersistentGlobalVariable("array", array);
</pre>
<br />
I can then call thoes values back in the beforeDrawLegendItem like this<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
var i = 0;
function beforeDrawLegendItem( lerh, bounds, icsc )
{
var myarray = icsc.getExternalContext().getScriptable().getPersistentGlobalVariable("array");
lerh.getLabel().getCaption().setValue(myarray.get(i));
i++;
}
</pre>
<br />
Which gives me this output<br />
<br />
actuser9
Thanks kclark. This seems to be working exactly the way I was expecting to work. I am trying to implement this into my report which has some additional logic to hide the series based on the data set values. Will keep you posted on how that works in combination with this logic.
Thanks a ton.
Regards,
UY