Hide the leader lines on Pie Charts when displaying Value or Category Labels
In the formatting options for the Pie Chart widget, under the 'Design' tab, you can choose to display various data labels on the chart. If you select either "Value" or "Category" then these will display outside the Pie Chart and will also display little leader lines (or pointer lines, or whatever you want to call them) that point from the value to the pie slice they belong to.
Is there a script I can use to hide these, while still displays the value and/or category? Here's a mock-up of what I mean:
Jake Raz
Posted 2 years ago·Last reply 2 years ago
7 comments
DRay
·2 years agoHi Jake_Raz.
Thank you for your question. I haven't been able to test this script due to issues with my test environment, but give this a try,
**Explanation:**
-
processresult: This function is called after the data is processed but before it is rendered. It's the right place to make changes to the chart’s configuration.-
labels.template: This controls what is displayed in the labels. Here, it shows both the category and value. You can customize it to your needs.-
labels.distance: This moves the label closer or farther from the center. You should adjust this value based on your label size and chart dimensions.-
labels.connectors.width: Setting this to0effectively hides the leader lines.-
labels.connectors.color: Setting color to "transparent" further ensures that the lines are not visible.-
labels.color: This is optional, allowing you to set the color of the text, which can be handy depending on your chart's background.This script will hide the leader lines effectively while retaining the labels. Customize the parameters further according to your specific visual design preferences. Should you have more complex visualization needs or run into any issues, don’t hesitate to reach out.
Jake Raz
OP2 years agoHmm, I tried using that script but it wouldn't work. On the particular pie chart I was working on, I was using "value" and "percent", so I wasn't quite sure what to put for labels.template. I tried using:
But that didn't seem to work, neither did flipping the order (percent first). I also tried changing the pie chart to display "category" and "value", as in your example, then copy/pasted the script exactly, but it still didn't work. The leader lines still show.
My original pie chart had multiple items in the "Values" section and nothing under "Categories" (left hand sidebar). I wasn't sure if that made a difference, so I tried creating a brand new Pie Chart with only one value and an item in the 'Categories' section. However, the script still didn't work in that instance, either 😔
DRay
·2 years agoWell, thank you for checking. I'll noodle around with it, or find another resource to look into this. I'll keep you posted.
Assaf Hanina
·2 years agoHey Jake_Raz ,
Please try to use the following Widget Script on the Pie Chart to remove the lines while still displaying the values or categories.
Best Regards
Jake Raz
OP2 years agoThanks! That script seemed to work, at least on normal Pie Charts. Appreciate it!
A follow-up question: I have another script that I'm trying to combine this with. It's a script I found in an "old" community post that lets you show the values inside the pie slices (instead of the percentages): https://community-old.sisense.com/hc/en-us/community/posts/221227488-Show-values-inside-pie-chart-instead-of-percentage
Here's the script I'm using:
When I use this script, it shows the values inside the pie slice, as expected, but the leader lines are still showing.
I tried adding your new script to the bottom of the script window. While it hid the leader lines, it also reverted the prior script (note how it reverted back to the percentages inside the pie slices, not the values).
(Note: I also tried pasting your script first and having the pie slice script be second, but that didn't make a difference)
I'm guessing it's due to the two scripts being incompatible with each other. Like, maybe your script is undoing the actions of the first somehow. If so, is there a way to modify either of them to fix this, or combine them in some fashion?
Jake Raz
OP2 years agoNevermind, I think I figured it out. This script seems to successfully combine both functions:
This hides the leader lines while ALSO replacing the percentages inside the pie slices with the raw totals instead.
Assaf Hanina
·2 years agohey Jake_Raz ,
Happy to hear that the issue is resolved and thanks for sharing the script as well.
Unfortunately, the script is not working on my end, Probably a version related issue.
If necessary, the following script positions the values within the Pie chart, and it can be style differently (though not compatible with 'Others').
It requires enabling the values and disabling the percentages. The category is also displayed in the Pie Chart, but it can be toggled off and placed in the Legend instead.
Best Regards