Trigger callback function when legend toggle is clicked

Hello,

I understand that clicking on the legend of the chart data can set the visibility of the data in the chart. I'd like to try to make this clearer to the user by updating the legend shape to something else when it is toggled on / off. So for example, I have two data sources, When they are both visible, the legend and chart  would look like this:If I were to click on the legend of one of the data sources to toggle one of them to set the visibility off, it would look like this:


I'm essentially trying to change the legend shape depending on if the data is visible or not, which would require a callback placed on the chart series. Is there a solution for this?

Thank you,

John


3 Replies

SB Swetha Babu Syncfusion Team May 23, 2022 08:26 AM UTC

Hi John,


Greetings from Syncfusion.


We can change the shape of the legend while clicking by using the LegendShape argument in OnLegendClick event in Chart component. When we click on the legend, the OnLegendClick event gets fired. However, we have created a simple blazor application to demonstrate the same and it can be downloaded from the below link.


Sample link: https://www.syncfusion.com/downloads/support/directtrac/general/ze/LegendClick1703269145


Code Snippet:


<SfChart Title="Crude Steel Production Annual Growth">

        <ChartEvents OnLegendClick="clickLegend"></ChartEvents>       

    </SfChart>

 

void clickLegend(LegendClickEventArgs args)

    {

        // Code here

    }


Kindly, revert us if you have any concerns.


Regards,

Swetha



JT John T May 23, 2022 08:47 AM UTC

Hi Swetha,


I was unaware of this LegendClick property, thank you, I will try this.


On a related note, I know the chartshapes use a preset list of shapes defined by an enum. Is there any way to use a custom shape instead?


thank you,

John



SB Swetha Babu Syncfusion Team May 24, 2022 06:36 AM UTC

Hi John,


As of now, we do not have support to render the custom shape in the Legend. However, we have considered this as an improvement and logged a feature request for the same. The feature will be available in any of our upcoming releases. Please find the below feedback link to keep track of the reported scenario.


Feedback link: https://www.syncfusion.com/feedback/28550/template-support-for-chart-legend


We are closing this ticket for now. Please get back to us if you have any concerns.


Regards,

Swetha


Loader.
Up arrow icon