Refresh chart via calling SetState() the only way to update chart?

Hi

I want to update the chart when I add a plotband, or change CrosshairBehavior. Is the only to refresh the chart to update the new config (for example, new CrosshairBehavior) is by calling setState()?


Thanks and hope to hear from you soon.


1 Reply

YG Yuvaraj Gajaraj Syncfusion Team March 1, 2022 04:20 PM UTC

Hi Peter, 
 
Greetings from Syncfusion. Yes, you need to call setState for the new configuration to take effect in the chart, however we suggest you to wrap the SfCartesianChart widget inside the StatefulBuilder then call the setState inside the StatefulBuilder, it won't reload the entire application. Here we have attached the code snippet below for your reference. 
 
Code snippet: 
StatefulBuilder(builder: (contextsetState) { 
  return Column(children: [ 
    SfCartesianChart( 
       //Other required properties 
       crosshairBehavior_crosshairBehavior, 
    ), 
    ElevatedButton( 
      onPressed: () { 
        setState(() { 
          _crosshairBehavior = CrosshairBehavior( 
             activationModeActivationMode.doubleTap, 
             enabletrue 
           ); 
        }); 
      }, 
      childText('press')) 
  ]);}) 
 
 
  
Regards, 
Yuvaraj. 


Loader.
Up arrow icon