We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Idea of using legends as on/off buttons

Hi,

Here's the  idea, click a legend to turn the referenced chart off ( by changing the isVisible property), click again to turn it on.

I tried it in onLegendTapped and it works.

Though, when a chart is turned off, I hope it's legend change to a customizable color like grey instead of white, and still show it's title, is that possible?


15 Replies 1 reply marked as answer

YG Yuvaraj Gajaraj Syncfusion Team January 25, 2023 02:49 PM UTC

Hi Zhu,


We are validating your query and trying to create a feasible workaround for your requirement, and we need time on this we will update the status in one business day on 27 January 2023. We appreciate your patience until then.


Regards,

Yuvaraj.



ZH Zhu January 26, 2023 11:10 AM UTC

Hi, Yuvaraj,


Great, that sounds good.


Regards,

Zhu



YG Yuvaraj Gajaraj Syncfusion Team January 27, 2023 02:53 PM UTC

Hi Zhu,


Thanks for your patience.


Your requirement can be achieved with the help of the legendItemBuilder property in the legend, which is used to render a custom widget instead of an actual legend. Here we have rendered a custom shape widget with a series color and changed the color of the widget based on the series visibility. We have shared the sample below for your requirement, you can modify the sample as per your requirement.


Screenshot:



Regards,

Yuvaraj.



Attachment: f180145_4c43961f.zip

Marked as answer

ZH Zhu February 2, 2023 02:23 AM UTC

Hi, Yuvaraj,


There's an issue that in legendItemBuilder, the legend text color would change when seriesVisibility is turned off, that works well when background color is white, but not in other colors.

Is there an internal logic doing that? what to do to control the color all by myself?


Best Regards,


Zhu



YG Yuvaraj Gajaraj Syncfusion Team February 2, 2023 01:48 PM UTC

Hi Zhu,


We are checking your query and trying to create a feasible workaround for your requirement, and we need time on this we will update the status in one business day on 3 February 2023. We appreciate your patience until then.



Regards,

Yuvaraj.



YG Yuvaraj Gajaraj Syncfusion Team February 3, 2023 09:55 AM UTC

Hi Zhu,


We have created a sample with the help of the legendItemBuilder property and wrapped the custom legend with GestureDetector and handled the legend icon color and series visibility change in its onTap callback. We have shared the sample below for your reference, you can modify it as per your requirements.


Screenshot:



Regards,

Yuvaraj


Attachment: f180145_c7924872.zip


ZH Zhu February 5, 2023 03:42 AM UTC

Hi, Yuvaraj,


Thanks for the sample, though, seems there's a copy mistake that in attached zip file the main.dart being the one created by flutter automatically.


Regards,

Zhu



YG Yuvaraj Gajaraj Syncfusion Team February 6, 2023 05:57 AM UTC

Hi Zhu,


We apologize for the inconvenience. We have shared the correct sample below for your requirement. Please check and get back to us if you have any further queries.


Regards,

Yuvaraj.


Attachment: f180145_e05b0f0.zip


ZH Zhu February 9, 2023 10:26 AM UTC

Hi, Yuvaraj,


I did a test on the sample provided, it do work, though, it redraws the whole chart each time pressing the legend button, seems not be a perfect solution.

As I think, the internal logic of this feature should be changed to apply to different background colors, is that possible?


Regards,

Zhu



LA Lavanya Anaimuthu Syncfusion Team February 10, 2023 02:20 PM UTC

Hi Zhu,

Currently we are checking the feasible workaround for your requirement and will update the complete details on February 13, 2023. We appreciate your patience until then.

 Regards,

Lavanya A.  



ZH Zhu February 12, 2023 02:19 AM UTC

Hi,  Lavanya A,


That sounds great, thank you.


Regards,

Zhu



YG Yuvaraj Gajaraj Syncfusion Team February 13, 2023 01:59 PM UTC

Hi Zhu,


We are still checking for a feasible workaround for your requirement and will update the further details on February 14, 2023. We appreciate your patience until then.



Regards,

Yuvaraj.




YG Yuvaraj Gajaraj Syncfusion Team February 14, 2023 03:08 PM UTC

Hi Zhu,


We couldn't able to find a feasible solution to update the chart without rebuilding it. In a workaround sample, we are disabling the ability to toggle the legend items by setting toggleSeriesVisibility to false in the legend. This prevents the legend toggle, but we can get the respective series index of the tapped legend in the onLegendTapped callback. Based on that information, we update the legend icon and the visibility of the series by calling setState, which rebuild the chart.


If you have any further queries please get back to us.


Regards,

Yuvaraj.





ZH Zhu February 20, 2023 10:35 AM UTC

Hi, Yuvaraj,


I understand you have to keep compatibility with old versions, that's fine.

Thanks for the help.


Regards,

Zhu



YG Yuvaraj Gajaraj Syncfusion Team February 21, 2023 10:41 AM UTC

Hi Zhu,


Thanks for the update. If you have any further queries please get back to us. We are always happy to assist you.


Regards,

Yuvaraj.


Loader.
Up arrow icon