How to disable series visibility on initial rendering in Blazor Charts?
This article explains how to disable series visibility on initial rendering.
Disabling Series Visibility by Default
Blazor Charts provides an option to disable chart series visibility at initial load using its Visible property.
This can be achieved by specifying the Visible property as false for the required series to be disabled and assigning a Name for the disabled series to view it in the legend. Then, by toggling the legend, the series visibility can be changed.
The code example below demonstrates how to disable series visibility by default.
Index.razor:
@using Syncfusion.Blazor.Charts
<SfChart>
<ChartPrimaryXAxis ValueType="Syncfusion.Blazor.Charts.ValueType.Category"></ChartPrimaryXAxis>
<ChartSeriesCollection>
<ChartSeries Name="Gold" Fill="#E94649" Visible="false" DataSource="@MedalDetails" XName="X" YName="YValue" Type="Syncfusion.Blazor.Charts.ChartSeriesType.Column">
</ChartSeries>
<ChartSeries Name="Silver" Fill="#F6B53F" DataSource="@MedalDetails" XName="X" YName="YValue1" Type="Syncfusion.Blazor.Charts.ChartSeriesType.Column">
</ChartSeries>
</ChartSeriesCollection>
</SfChart>
@code{
public class ChartData
{
public string X { get; set; }
public double YValue { get; set; }
public double YValue1 { get; set; }
}
public List<ChartData> MedalDetails = new List<ChartData>
{
new ChartData { X= "USA", YValue= 46, YValue1=56 },
new ChartData { X= "GBR", YValue= 27, YValue1=17 },
new ChartData { X= "CHN", YValue= 26, YValue1=36 },
new ChartData { X= "UK", YValue= 56, YValue1=16 },
new ChartData { X= "AUS", YValue= 12, YValue1=46 },
new ChartData { X= "IND", YValue= 26, YValue1=16 },
new ChartData { X= "DEN", YValue= 26, YValue1=12 },
new ChartData { X= "MEX", YValue= 34, YValue1=32},
};
}
The following screenshot illustrates the output of the code snippet.
Output:
Live Sample for Disabling Series
Conclusion:
We hope you enjoyed learning how to disable series visibility on initial rendering in the Blazor Chart component.
You can refer to our Blazor Chart feature tour page to learn about its other groundbreaking features, documentation, and how to quickly get started with configuration specifications. You can also explore our Blazor Chart example to understand how to create and manipulate data.
For current customers, our Blazor components are available on the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to evaluate our Blazor Charts and other Blazor components.
If you have any questions or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, support portal, or feedback portal. We are always happy to assist you!