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)
color group of pie chart slices
mh10
Hi,
Pie chart is showing data 1,3,4,2,7,9,10,20,
I am looking to show one particular color to slices which has Less than 5 values.
Any suggestions/ Example?
Thanks
Find more posts tagged with
Comments
mwilliams
Hi mh10,
So, you want it to show the slices of values 7, 9, 10, 20, and "5 or less"? If so, you can do this in the chart editor under "Format Chart" in the "Category Series" section. You can set a minimum slice value and name that slice. So, if you want to do 5 or less in one slice, you'd choose value, enter 5 as the minimum, and then name the slice "5 or less" or whatever you want.
Hope this helps.
mh10
Hi Michael,<br />
<br />
with your suggestion, setting minimum values 5 will get same color for values less than 5 (in my case 1,3,4,2) , they will represented by one single slice. And in Legend there will be one symbol of that color for all those values less than 5.<br />
<br />
but, i want to keep legend entries for these values which are less than 5. <br />
so i cannot set minimum values to 5.<br />
<br />
<br />
Any suggestions/ script?<br />
<br />
<br />
<blockquote class='ipsBlockquote' data-author="mwilliams"><p>Hi mh10,<br />
<br />
So, you want it to show the slices of values 7, 9, 10, 20, and "5 or less"? If so, you can do this in the chart editor under "Format Chart" in the "Category Series" section. You can set a minimum slice value and name that slice. So, if you want to do 5 or less in one slice, you'd choose value, enter 5 as the minimum, and then name the slice "5 or less" or whatever you want.<br />
<br />
Hope this helps.</p></blockquote>
mwilliams
mh10,
Ok, I understand what you're looking for now. The following script in the chart script section should do it for the chart.
function beforeDrawDataPoint( dph, fill, icsc )
{
if (dph.getOrthogonalValue() < 4){
fill.set(255,0,0);
}
}
Changing the legend will require a little more work probably. If you need help with that, just let me know.
mh10
I tried this script but it is changing color on pie chart only, not the related legend items. <br />
<br />
i am expecting, to change color in legend items also.<br />
<br />
<br />
<br />
Any suggestions?<br />
<br />
<br />
<blockquote class='ipsBlockquote' data-author="mwilliams"><p>mh10,<br />
<br />
Ok, I understand what you're looking for now. The following script in the chart script section should do it for the chart.<br />
<br />
function beforeDrawDataPoint( dph, fill, icsc )<br />
{<br />
if (dph.getOrthogonalValue() < 4){<br />
fill.set(255,0,0);<br />
}<br />
}<br />
<br />
Changing the legend will require a little more work probably. If you need help with that, just let me know.</p></blockquote>
mwilliams
mh10,<br />
<br />
You would have to color the legend separately with a couple more steps as I said in my last post. Something like this should do it for you:<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
function beforeDrawDataPoint( dph, fill, icsc )
{
if (dph.getOrthogonalValue() <= 5){
fill.set(255,0,0);
icsc.getExternalContext().getScriptable().setPersistentGlobalVariable(dph.getBaseDisplayValue(), "yes");
}
else{
icsc.getExternalContext().getScriptable().setPersistentGlobalVariable(dph.getBaseDisplayValue(), "no");
}
}
function beforeDrawLegendItem( lerh, bounds, icsc )
{
if (icsc.getExternalContext().getScriptable().getPersistentGlobalVariable(lerh.getLabel().getCaption().getValue()) == "yes"){
lerh.getFill().set(255,0,0);
}
}
</pre>
<br />
Let me know if you have any questions.
mh10
I copied and pasted your given script but it is still only changing color on pie chart, but not the related legend items.<br />
<br />
if pie chart slice is red then its related legend item should be red also<br />
<br />
I am using birt 2.3.2<br />
<br />
Any suggestions/ EXAMPLE?<br />
<br />
<br />
<br />
<blockquote class='ipsBlockquote' data-author="mwilliams"><p>mh10,<br />
<br />
You would have to color the legend separately with a couple more steps as I said in my last post. Something like this should do it for you:<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
function beforeDrawDataPoint( dph, fill, icsc )
{
if (dph.getOrthogonalValue() <= 5){
fill.set(255,0,0);
icsc.getExternalContext().getScriptable().setPersistentGlobalVariable(dph.getBaseDisplayValue(), "yes");
}
else{
icsc.getExternalContext().getScriptable().setPersistentGlobalVariable(dph.getBaseDisplayValue(), "no");
}
}
function beforeDrawLegendItem( lerh, bounds, icsc )
{
if (icsc.getExternalContext().getScriptable().getPersistentGlobalVariable(lerh.getLabel().getCaption().getValue()) == "yes"){
lerh.getFill().set(255,0,0);
}
}
</pre>
<br />
Let me know if you have any questions.</p></blockquote>
mwilliams
mh10,
The script:
function beforeDrawLegendItem( lerh, bounds, icsc )
{
if (icsc.getExternalContext().getScriptable().getPersistentGlobalVariable(lerh.getLabel().getCaption().getValue()) == "yes"){
lerh.getFill().set(255,0,0);
}
}
that I posted in the last post should do that if you use all the new code that was posted. I just did this in 2.3.2. Is it not working for you?
mh10
Right, now it is working.<br />
<br />
Thanks Michael.<br />
<br />
<br />
<br />
<blockquote class='ipsBlockquote' data-author="mwilliams"><p>mh10,<br />
<br />
The script:<br />
<br />
function beforeDrawLegendItem( lerh, bounds, icsc )<br />
{<br />
if (icsc.getExternalContext().getScriptable().getPersistentGlobalVariable(lerh.getLabel().getCaption().getValue()) == "yes"){<br />
lerh.getFill().set(255,0,0);<br />
}<br />
}<br />
<br />
that I posted in the last post should do that if you use all the new code that was posted. I just did this in 2.3.2. Is it not working for you?</p></blockquote>
mwilliams
No problem. Glad I could help.
mh10
i have one more concern related to this.<br />
<br />
i am looking to to show only Legend of graph with this changed legend item color, and want to hide pie chart Series.<br />
<br />
but with your script and Hiding pie chart Series, the legend item colors are not changing.<br />
<br />
<br />
Any suggestions?<br />
<br />
<br />
<br />
<br />
<blockquote class='ipsBlockquote' data-author="mwilliams"><p>No problem. Glad I could help.</p></blockquote>
mwilliams
mh10,
I'm not sure I'm understanding this correctly. Is there any way you can make a sample report with the sample database that I can run that shows this? Thanks.
mh10
Attached is the sample chart report, in which i have changed color of CUSTOMERS.CUSTOMERNUMBER < 170 values to red; in script. With Series 1 visible.<br />
<br />
Now, deselect Series 1, and run the report it doesn't change the color to Red for values less than 170.<br />
<br />
<br />
<br />
<br />
<blockquote class='ipsBlockquote' data-author="mwilliams"><p>mh10,<br />
<br />
I'm not sure I'm understanding this correctly. Is there any way you can make a sample report with the sample database that I can run that shows this? Thanks.</p></blockquote>
mwilliams
mh10,
Ok, I see what you're getting. What is the reason for only showing the legend and not the chart?
mwilliams
mh10,
I'm not sure of another way right now to associate the values in the plot with the labels in the legend if you're not showing the plot. The only way I can think of to get what you're looking for would be to set the PGV's outside the chart in either a table or your dataSet. If I think of anything else, I'll let you know.
mh10
This is the workaround i am looking for one particular scenario.<br />
<br />
in a chart when we set Minimum values/ percentage, all values below that values represented by one slice on pie chart , and there will be one related legend symbol for that symbol<br />
<br />
Here, i want to show some minimum values with one slice, but in legend i want to show all those minimum values too. (not the one common symbol)<br />
<br />
so i created one chart in which i set minimum value ( e.g. 5) with label OTHER, so i got one common slice for expected values, and hide legend in this chart.<br />
and right below this chart i created other chart with same previous chart settings except no minimum values setting, and then i hide Series to show Legend. Now this Legend will have all the values. <br />
<br />
and to show this Legend belongs to first chart, i want to give same color of OTHER common slice of 1st chart to all the legend symbol of 2nd chart which has values < 5.<br />
<br />
<br />
but with above attached example report, i am not getting this<br />
<br />
<br />
any suggestions? <br />
<br />
<br />
<blockquote class='ipsBlockquote' data-author="mwilliams"><p>mh10,<br />
<br />
Ok, I see what you're getting. What is the reason for only showing the legend and not the chart?</p></blockquote>
mh10
Any suggestions?
mwilliams
mh10,
If you look above your last 2 posts, you'll see my suggestion on how to achieve this. See the attached report design. I set the PGV's in the dataSet rather than in the chart.
mh10
Hi Michael,<br />
AS you mentioned, set the PGV's in the dataSet rather than in the chart.<br />
can you tell me what exactly you did?<br />
<br />
<br />
THanks<br />
<br />
<br />
<blockquote class='ipsBlockquote' data-author="mwilliams"><p>mh10,<br />
<br />
If you look above your last 2 posts, you'll see my suggestion on how to achieve this. See the attached report design. I set the PGV's in the dataSet rather than in the chart.</p></blockquote>
mwilliams
mh10,
If you look in the script of the dataSet, I checked for the "Customer Number" values associated with each "First Name" and set the PGV to "yes" or "no" for each name, just like what was done in the chart script. Then, when the "legend item" script is called, it reads in the PGV's the same as it did before and changes the color if the value for that PGV is "yes".
Hope this helps. Let me know if you have any other questions.