Getting Started with Blazor Smith Chart in Blazor Web App
15 Jul 202616 minutes to read
This section briefly explains how to include the Blazor Smith Chart component in your Blazor Web App using Visual Studio, Visual Studio Code, and the .NET CLI.
Create a new Blazor Web App
Create a Blazor Web App using Visual Studio via Microsoft Templates or the Blazor Extension. For detailed instructions, refer to the Blazor Web App Getting Started documentation.
Run the following command to create a new Blazor Web App.
dotnet new blazor -o BlazorWebApp --interactivity Auto
cd BlazorWebApp
cd BlazorWebApp.ClientAlternatively, create a Blazor Web App using Visual Studio Code via Microsoft Templates, the Blazor Extension, or the C# Dev Kit extension.
Run the following command to create a new Blazor Web App.
dotnet new blazor -o BlazorWebApp --interactivity Auto
cd BlazorWebApp
cd BlazorWebApp.ClientNOTE
Configure the appropriate Interactive render mode and Interactivity location while creating a Blazor Web App. For detailed information, refer to the interactive render mode documentation.
Install the required Blazor package
Install the Syncfusion.Blazor.SmithChart NuGet package. All Syncfusion Blazor packages are available on nuget.org. See the NuGet packages topic for details. If using the WebAssembly or Auto render modes in the Blazor Web App, install this package in the .Client project.
- Go to Tools → NuGet Package Manager → Manage NuGet Packages for Solution.
- Search the required NuGet package (
Syncfusion.Blazor.SmithChart) and install it.
Alternatively, you can install the same package using the Package Manager Console with the following command.
Install-Package Syncfusion.Blazor.SmithChart -Version 34.1.29Open the terminal and run the following command.
dotnet add package Syncfusion.Blazor.SmithChart -v 34.1.29Open the command prompt and run the following command.
dotnet add package Syncfusion.Blazor.SmithChart -v 34.1.29Add import namespaces
After the package is installed, open the ~/_Imports.razor file in the .Client project and import the Syncfusion.Blazor and Syncfusion.Blazor.Charts namespaces.
@using Syncfusion.Blazor
@using Syncfusion.Blazor.ChartsRegister the Blazor service
Open the Program.cs file in Blazor Web App and register the Blazor service. If the Interactive Render Mode is set to WebAssembly or Auto, register the Blazor service in Program.cs files of both the server and client projects in your Blazor Web App.
....
using Syncfusion.Blazor;
....
builder.Services.AddSyncfusionBlazor();
....Add script resource
The script can be accessed from NuGet through Static Web Assets. Include the script references in the App.razor file.
<script src="_content/Syncfusion.Blazor.Core/scripts/syncfusion-blazor.min.js" type="text/javascript"></script>Add Blazor Smith Chart component
Open a Razor file located in the ~/Pages/*.razor (for example, Home.razor) and add the Blazor Smith Chart component inside the .Client project razor file.
NOTE
If the interactivity location is set to
Per page/componentin the Web App, define a render mode at the top of the razor file. (For example,InteractiveServer,InteractiveWebAssemblyorInteractiveAuto). If the Interactivity is set toGlobalwithAutoorWebAssembly, the render mode is automatically configured in theApp.razorfile by default.
@rendermode InteractiveAuto
@using Syncfusion.Blazor.Charts
<SfSmithchart>
</SfSmithchart>Adding series to Blazor Smith Chart
Smith Chart series can be added in two ways. Use either Points or Datasource in the SmithChartSeries.
If you add using Datasource property, additionally you need to specify data source mapping fields using Reactance and Resistance properties.
If you are using Points, you don’t need to specify mapping fields as like in DataSource. But the Points collection should be SmithChartPoint type and define Resistance and Reactance properties mandatorily.
The following sample demonstrates adding two series to Smith Chart in both ways.
- First series
Transmission1showsDataSourcebound series. - Second series
Transmission2showsPointsbound series.
@using Syncfusion.Blazor.Charts
<SfSmithChart>
<SmithChartSeriesCollection>
<SmithChartSeries Name="Transmission1"
Reactance="Reactance"
Resistance="Resistance"
DataSource="@FirstTransmissionSeries">
</SmithChartSeries>
<SmithChartSeries Name="Transmission2"
Points="@SecondTransmissionSeries">
</SmithChartSeries>
</SmithChartSeriesCollection>
</SfSmithChart>
@code {
public class SmithDataSource
{
public double Resistance { get; set; }
public double Reactance { get; set; }
};
public List<SmithDataSource> FirstTransmissionSeries = new List<SmithDataSource> {
new SmithDataSource { Resistance= 10, Reactance= 25 },
new SmithDataSource { Resistance= 8, Reactance= 6 },
new SmithDataSource { Resistance= 6, Reactance= 4.5 },
new SmithDataSource { Resistance= 4.5, Reactance= 2 },
new SmithDataSource { Resistance= 3.5, Reactance= 1.6 },
new SmithDataSource { Resistance= 2.5, Reactance= 1.3 },
new SmithDataSource { Resistance= 2, Reactance= 1.2 },
new SmithDataSource { Resistance= 1.5, Reactance= 1 },
new SmithDataSource { Resistance= 1, Reactance= 0.8 },
new SmithDataSource { Resistance= 0.5, Reactance= 0.4 },
new SmithDataSource { Resistance= 0.3, Reactance= 0.2 },
new SmithDataSource { Resistance= 0.001, Reactance= 0.15 }
};
public List<SmithChartPoint> SecondTransmissionSeries = new List<SmithChartPoint> {
new SmithChartPoint { Resistance= 20, Reactance= -50 },
new SmithChartPoint { Resistance= 10, Reactance= -10 },
new SmithChartPoint { Resistance= 9, Reactance= -4.5 },
new SmithChartPoint { Resistance= 8, Reactance= -3.5 },
new SmithChartPoint { Resistance= 7, Reactance= -2.5 },
new SmithChartPoint { Resistance= 6, Reactance= -1.5 },
new SmithChartPoint { Resistance= 5, Reactance= -1 },
new SmithChartPoint { Resistance= 4.5, Reactance= -0.5 },
new SmithChartPoint { Resistance= 2, Reactance= 0.5 },
new SmithChartPoint { Resistance= 1.5, Reactance= 0.4 },
new SmithChartPoint { Resistance= 1, Reactance= 0.4 },
new SmithChartPoint { Resistance= 0.5, Reactance= 0.2 },
new SmithChartPoint { Resistance= 0.3, Reactance= 0.1 },
new SmithChartPoint { Resistance= 0.001, Reactance= 0.05 }
};
}Run the application
Press Ctrl+F5 (Windows) or ⌘+F5 (macOS) to launch the application. The Blazor Smith Chart component will render in your default web browser.
Open the terminal and navigate to the main project folder (for example, BlazorWebApp) and run the following command.
cd ..
cd BlazorWebApp
dotnet runOpen the command prompt and navigate to the main project folder (for example, BlazorWebApp) and run the following command.
cd ..
cd BlazorWebApp
dotnet run
NOTE
Adding Title
Title can be added to the Smith Chart to provide quick information to the users about the context of the rendered component. Add a title by using the Text property in the SmithChartTitle.
@using Syncfusion.Blazor.Charts
<SfSmithChart>
<SmithChartTitle Text="Impedance Transmission">
</SmithChartTitle>
<SmithChartSeriesCollection>
<SmithChartSeries Name="Transmission1"
Reactance="Reactance"
Resistance="Resistance"
DataSource="@FirstTransmissionSeries">
</SmithChartSeries>
<SmithChartSeries Name="Transmission2"
Points="@SecondTransmissionSeries">
</SmithChartSeries>
</SmithChartSeriesCollection>
</SfSmithChart>NOTE
Refer to the code block to know about the property value of
FirstTransmissionSeriesandSecondTransmissionSeries.
Enable Marker
To display marker for particular series, set the Visible property to true in the SmithChartSeriesMarker.
@using Syncfusion.Blazor.Charts
<SfSmithChart>
<SmithChartTitle Text="Impedance Transmission">
</SmithChartTitle>
<SmithChartSeriesCollection>
<SmithChartSeries Name="Transmission1"
Reactance="Reactance"
Resistance="Resistance"
DataSource="@FirstTransmissionSeries">
<SmithChartSeriesMarker Visible="true"></SmithChartSeriesMarker>
</SmithChartSeries>
<SmithChartSeries Name="Transmission2"
Points="@SecondTransmissionSeries">
</SmithChartSeries>
</SmithChartSeriesCollection>
</SfSmithChart>NOTE
Refer to the code block to know about the property value of
FirstTransmissionSeriesandSecondTransmissionSeries.
Enable Data Label
To display data label for particular marker series, set the Visible property to true in the SmithChartSeriesDatalabel.
@using Syncfusion.Blazor.Charts
<SfSmithChart>
<SmithChartTitle Text="Impedance Transmission">
</SmithChartTitle>
<SmithChartSeriesCollection>
<SmithChartSeries Name="Transmission1"
Reactance="Reactance"
Resistance="Resistance"
DataSource="@FirstTransmissionSeries">
<SmithChartSeriesMarker Visible="true">
<SmithChartSeriesDatalabel Visible="true">
</SmithChartSeriesDatalabel>
</SmithChartSeriesMarker>
</SmithChartSeries>
<SmithChartSeries Name="Transmission2" Points="@SecondTransmissionSeries">
</SmithChartSeries>
</SmithChartSeriesCollection>
</SfSmithChart>NOTE
Refer to the code block to know the property value of
FirstTransmissionSeriesandSecondTransmissionSeries.
Enable Legend
Use legend for the Smith Chart by setting the Visible property to true in the SmithChartLegendSettings. The legend name can be changed by using the Name property in the SmithChartSeries.
@using Syncfusion.Blazor.Charts
<SfSmithChart>
<SmithChartLegendSettings Visible="true"></SmithChartLegendSettings>
<SmithChartTitle Text="Impedance Transmission"></SmithChartTitle>
<SmithChartSeriesCollection>
<SmithChartSeries Name="Transmission1"
Reactance="Reactance"
Resistance="Resistance"
DataSource="@FirstTransmissionSeries">
<SmithChartSeriesMarker Visible="true">
<SmithChartSeriesDatalabel Visible="true">
</SmithChartSeriesDatalabel>
</SmithChartSeriesMarker>
</SmithChartSeries>
<SmithChartSeries Name="Transmission2" Points="@SecondTransmissionSeries">
</SmithChartSeries>
</SmithChartSeriesCollection>
</SfSmithChart>NOTE
Refer to the code block to know the property value of the
FirstTransmissionSeriesand theSecondTransmissionSeries.
Enable Tooltip
When space constraints prevents from displaying information using data labels, the tooltip comes in handy. The tooltip can be enabled by setting the Visible property to true in the SmithChartSeriesTooltip.
@using Syncfusion.Blazor.Charts
<SfSmithChart>
<SmithChartLegendSettings Visible="true"></SmithChartLegendSettings>
<SmithChartTitle Text="Impedance Transmission"></SmithChartTitle>
<SmithChartSeriesCollection>
<SmithChartSeries Name="Transmission1"
Reactance="Reactance"
Resistance="Resistance"
DataSource="@FirstTransmissionSeries">
<SmithChartSeriesMarker Visible="true">
<SmithChartSeriesDatalabel Visible="true">
</SmithChartSeriesDatalabel>
</SmithChartSeriesMarker>
<SmithChartSeriesTooltip Visible="true">
</SmithChartSeriesTooltip>
</SmithChartSeries>
<SmithChartSeries Name="Transmission2" Points="@SecondTransmissionSeries">
</SmithChartSeries>
</SmithChartSeriesCollection>
</SfSmithChart>NOTE
Refer to the code block to know about the property value of the
FirstTransmissionSeriesand theSecondTransmissionSeries.