Hello,
I have a chart that refreshes every minute to get new data, however I'm running into a problem when the chart refreshes it resets the legend visibilities.
For example I have this code that set the visibility property to false on Silver and Bronze chart series. If I click on the legend icon, the chart will be visible. However after the chart refreshes with
_chartObj.RefreshAsync();
then the chart gets rendered with visibility property to false. Is there a way to keep track of the visibility property and save the chart series visibility even when chart is rerendered?
<SfChart Title="Olympic Medals">
<ChartPrimaryXAxis ValueType="Syncfusion.Blazor.Charts.ValueType.Category"/>
<ChartSeriesCollection>
<ChartSeries DataSource="@MedalDetails" Name="Gold" XName="Country" Width="2" Opacity="1" YName="Gold" Type="ChartSeriesType.Column"/>
<ChartSeries DataSource="@MedalDetails" Name="Silver" XName="Country" Width="2" Opacity="1" YName="Silver" Type="ChartSeriesType.Column" Visible="false"/>
<ChartSeries DataSource="@MedalDetails" Name="Bronze" XName="Country" Width="2" Opacity="1" YName="Bronze" Type="ChartSeriesType.Column" Visible="false" />
</ChartSeriesCollection>
<ChartLegendSettings Visible="true"/>
</SfChart>
Hi Pavel,
Greetings from Syncfusion.
We suggest you to update the required chart properties using chart refresh method as per below snippet. We have prepared sample based on your requirement. In an attached sample, we have changed the visibility of chart series to achieve your required scenario.
<SfChart @ref="chartInstance"> <ChartSeriesCollection> //... <ChartSeries Visible="@series2"/> </ChartSeriesCollection> </SfChart> { series2 = true; await chartInstance.Refresh(); } } |
Kindly revert us if you have any concerns.
Regards,
Durga Gopalakrishnan.
Is there a way to track clicks on the legend?
Hi Pavel,
You can get the clicked legend item using OnLegendClick event. Please check with the below snippet and documentation link.
<SfChart> <ChartEvents OnLegendClick="LegendClickEvent"></ChartEvents> </SfChart> @code { public void LegendClickEvent(LegendClickEventArgs args) { } } |
Please revert us if you have any concerns.
Regards,
Durga Gopalakrishnan.