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

Programmatic legend toggle cartesianToggle

Hello,

I have a chart with many series, which can be toggled on and off by tapping the corresponding legend entry. I would like to toggle less important of them off programmatically on start-up using my own configuration. I don't want to program the whole legend by my own. I like the standard legend and only want to have it in the state, as I have clicked on a couple of legend entries. There is a function cartesianToggle() in common/utils/helper.dart which seems to be the thing, I'm looking for, but it needs the internal state object to be passed in. Is there any possibility to achieve the goal?

Regards,

Werner


3 Replies 1 reply marked as answer

LA Lavanya Anaimuthu Syncfusion Team February 9, 2023 12:31 PM UTC

Hi Werner Kolov,


You can programmatically control the visibility of the legend by using the isVisible property, which is available in the chart series class. This property can be used to toggle the visibility of a series. When the legend is enabled for a series, the visibility of its corresponding legend item will also be collapsed. Please refer to the code snippet below for more information.

SfCartesianChart(

              legend: Legend(isVisible: true, position: LegendPosition.top),

              series: <ChartSeries<_SalesData, String>>[

                LineSeries<_SalesData, String>(

                  dataSource: data,

                  xValueMapper: (_SalesData sales, _) => sales.year,

                  yValueMapper: (_SalesData sales, _) => sales.size,

                  name: 'Line Series',

                  isVisible: false                 

                ),

              ],

            ),


Regards,

Lavanya A.


Marked as answer

WK Werner Kolov February 9, 2023 02:01 PM UTC

Thank you very much!



LA Lavanya Anaimuthu Syncfusion Team February 10, 2023 08:33 AM UTC

Hi Werner Kolov,


Most Welcome. Kindly get back to us if you have further queries. We are always happy to assist you.


Regards,

Lavanya A.


Loader.
Up arrow icon