Forum Discussion

Jake_Raz's avatar
07-09-2024
Solved

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:

 

  • Hey 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.

     

    widget.on('processresult', function(w, args) {
        args.result.series.forEach(function(series) {
            series.dataLabels = {
                enabled: true,
                connectorWidth: 0,  // Set the width of the line (connector) to 0
                style: {
                    textOutline: 'none'  // Remove text outline if needed
                }
            };
        });
    });

     

    Best Regards

7 Replies

  • Hi 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, 

    javascript
    widget.on('processresult', function(se, ev) {
        var options = ev.result.seriesDefaults.labels;
        options.template = "#= category #: #= value #";
        options.distance = -30; // Adjusts how close the labels are to the edges of the pie slices
        options.color = "#fff"; // Optional: changes labels color, modify as needed
    
        // Disable connectors (leader lines)
        options.connectors = {
            width: 0,
            color: "transparent"
        };
    });

    **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 to 0 effectively 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. 

    • Hmm, 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:

       

          options.template = "#= value #: #= percent #";

       

      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's avatar
        DRay
        Admin

        Well, thank you for checking. I'll noodle around with it, or find another resource to look into this. I'll keep you posted.