Blazor Graph - Quick Getting Started Guide
What is Blazor Graph?
Blazor Graph (aka. Blazor Charts) is a well-crafted charting component to visualize data. It contains a rich gallery of 30+ charts and graphs, ranging from line to financial that cater to all charting scenarios. Its high performance helps render large amounts of data quickly. It also comes with features such as zooming, panning, tooltip, crosshair, trackball, highlight, and selection.
In this knowledge base, we are going to provide details about how to include a Blazor Graph Component in your Blazor Server-Side application. You can refer to our Getting Started with Blazor Server-Side Graph documentation page for configuration specifications.
Importing Syncfusion Blazor component in the application
- Install the Syncfusion.Blazor NuGet package to the application by using the NuGet Package Manager.
- You can add the client-side resources through CDN or from NuGet package in the HEAD element of the ~/Pages/_Host.cshtml page.
<head> <link href="_content/Syncfusion.Blazor/styles/bootstrap4.css" rel="stylesheet" /> <script src="https://github.com/Daddoon/Blazor.Polyfill/releases/download/3.0.1/ blazor.polyfill.min.js"></script> </head>
Adding component package to the application
Open **~/_Imports.razor file and import the Syncfusion.Blazor.**
@using Syncfusion.Blazor
@using Syncfusion.Blazor.Charts
Add SyncfusionBlazor service in Startup.cs
Open the Startup.cs file and add services required by Syncfusion components using service.AddSyncfusionBlazor() method. Add this method in the ConfigureServices function as follows.
using Syncfusion.Blazor;
namespace BlazorApplication
{
public class Startup
{
....
....
public void ConfigureServices(IServiceCollection services)
{
....
....
services.AddSyncfusionBlazor();
}
}
}
On Chart initial loading, we gather text measure information for rendering purposes. Since its size exceeds the default SignalR buffer size 32 KB, the server will be disconnected. So you need to add the following service to increase the buffer size to 64 KB over the SignalR connection.
using Syncfusion.Blazor;
namespace BlazorApplication
{
public class Startup
{
....
....
public void ConfigureServices(IServiceCollection services)
{
....
....
services.AddSyncfusionBlazor();
services.AddSignalR(e => {
e.MaximumReceiveMessageSize = 65536;
});
}
}
}
To enable custom client side resource loading from CRG or CDN. You need to disable resource loading by AddSyncfusionBlazor(true) and load the scripts in the HEAD element of the ~/Pages/_Host.cshtml page.
<head>
<script src="https://cdn.syncfusion.com/blazor/18.1.36-beta/dist/syncfusion-blazor.min.js"></script>
</head>s
Adding Chart component to the application
Now, add the Syncfusion Blazor components in any web page (razor) in the Pages folder. For example, the Chart component is added in the ~/Pages/Index.razor page.
Adding the lodash script is mandatory since we have used it in our chart’s interactive features. The absence of the script will result in console errors.
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.20/lodash.min.js" integrity="sha512-90vH1Z83AJY9DmlWa8WkjkV79yfS2n2Oxhsi2dZbIv0nC4E6m5AbH8Nh156kkM7JePmqD6tcZsfad1ueoaovww==" crossorigin="anonymous"></script>
</head>
in the HEAD element of the ~/Pages/_Host.cshtml page for server side blazor application, in the HEAD element of the ~/wwwroot/index.html for wasm application.
<SfChart></SfChart>
Run the application
After successful compilation of your application, the Syncfusion Blazor chart component will render in the web browser.
Populate Chart with Data
To bind data for the Chart component, you can assign a IEnumerable object to the DataSource property. The list data source can also be provided as an instance of the DataManager.
public class SalesInfo
{
public string Month { get; set; }
public double SalesValue { get; set; }
}
public List<SalesInfo> Sales = new List<SalesInfo>
{
new SalesInfo { Month = "Jan", SalesValue = 35 },
….
}
Now map the field Month and Sales in the data to the XName and YName properties of the series, then set the data to DataSource property. As we are going to view the data in column chart, set the Type of the chart as Column.
@using Syncfusion.Blazor.Charts
<SfChart>
….
</SfChart>
@code {
public class SalesInfo
{
public string Month { get; set;}
public double SalesValue { get; set;}
}
public List<SalesInfo> Sales = new List<SalesInfo>
{
…..
Add Chart and Axis Titles
You can add a title using Title property to the chart and an axis to provide quick information to the user about the data plotted in the chart.
@using Syncfusion.Blazor.Charts
<SfChart Width="60%" Title="Sales Analysis">
<ChartPrimaryXAxis Title="Month" ValueType="Syncfusion.Blazor.Charts.ValueType.Category"></ChartPrimaryXAxis>
<ChartPrimaryYAxis Title="Sales in Dollar"></ChartPrimaryYAxis>
<ChartSeriesCollection>
<ChartSeries DataSource="@Sales" XName="Month" YName="SalesValue" Type="ChartSeriesType.Column">
</ChartSeries>
</ChartSeriesCollection>
</SfChart>
@code {
public class SalesInfo
{
….
Add Data Label
You can add data labels to improve the readability of the chart. This can be achieved by setting the Visible property to true in the DataLabel.
@using Syncfusion.Blazor.Charts
<SfChart Width="60%" Title="Sales Analysis">
<ChartPrimaryXAxis Title="Month" ValueType="Syncfusion.Blazor.Charts.ValueType.Category"></ChartPrimaryXAxis>
<ChartPrimaryYAxis Title="Sales in Dollar"></ChartPrimaryYAxis>
<ChartSeriesCollection>
<ChartSeries DataSource="@Sales" XName="Month" YName="SalesValue" Type="ChartSeriesType.Column">
<ChartMarker>
<ChartDataLabel Visible="true"></ChartDataLabel>
</ChartMarker>
</ChartSeries>
</ChartSeriesCollection>
</SfChart>
@code {
public class SalesInfo
{
…..
Enable Tooltip
The tooltip is useful when you cannot display information by using the data labels due to space constraints. You can enable tooltip by setting the Enable property as true in TooltipSettings.
@using Syncfusion.Blazor.Charts
<SfChart Width="60%" Title="Sales Analysis">
<ChartPrimaryXAxis Title="Month" ValueType="Syncfusion.Blazor.Charts.ValueType.Category"></ChartPrimaryXAxis>
<ChartPrimaryYAxis Title="Sales in Dollar"></ChartPrimaryYAxis>
<ChartTooltipSettings Enable="true"></ChartTooltipSettings>
<ChartSeriesCollection>
<ChartSeries DataSource="@Sales" XName="Month" YName="SalesValue" Type="ChartSeriesType.Column">
</ChartSeries>
</ChartSeriesCollection>
</SfChart>
@code {
public class SalesInfo
{
……
Enable Legend
You can use legend for the chart by setting the Visible property to true in LegendSettings. The name of the legend can be set by using Name property in the series.
@using Syncfusion.Blazor.Charts
<SfChart Width="60%" Title="Sales Analysis">
<ChartPrimaryXAxis Title="Month" ValueType="Syncfusion.Blazor.Charts.ValueType.Category"></ChartPrimaryXAxis>
<ChartPrimaryYAxis Title="Sales in Dollar"></ChartPrimaryYAxis>
<ChartLegendSettings Visible="true"></ChartLegendSettings>
<ChartSeriesCollection>
<ChartSeries DataSource="@Sales" Name="Sales" XName="Month" YName="SalesValue" Type="ChartSeriesType.Column">
</ChartSeries>
</ChartSeriesCollection>
</SfChart>
@code {
public class SalesInfo
{
public string Month { get; set;}
public double SalesValue { get; set;}
}
public List<SalesInfo> Sales = new List<SalesInfo>
{
new SalesInfo { Month = "Jan", SalesValue = 35 },
new SalesInfo { Month = "Feb", SalesValue = 28 },
new SalesInfo { Month = "Mar", SalesValue = 34 },
new SalesInfo { Month = "Apr", SalesValue = 32 },
new SalesInfo { Month = "May", SalesValue = 40 },
new SalesInfo { Month = "Jun", SalesValue = 32 },
new SalesInfo { Month = "Jul", SalesValue = 35 }
};
}
Why should you choose Syncfusion Blazor Graph Component?
- Supports 30+ Chart types and elegant animation.
- Blazing fast load time and rich UI interaction in both server-side and client-side (WebAssembly) Blazor apps.
- Supports both rendering SVG and Canvas (for fast rendering).
- Flexible data binding with support to use data sources such as Web API, OData, Entity Framework, and more.
- One of the best Blazor Graph in the market that offers feature-rich UI to interact with the software.
- Simple configuration and API.
- Supports all modern browsers.
- Mobile-touch friendly and responsive.
- Extensive demos, documentation and videos to learn quickly and get started with Blazor Graph Component.
What is the price for Syncfusion Blazor Graph?
We do not sell the Blazor Graph separately. It is only available for purchase as part of the Syncfusion Blazor suite, which contains over 70 native Blazor components, including the Charts. A single developer license for the Syncfusion Essential Studio® for Blazor suite costs $995.00 USD, including one year of support and updates. On top of this, we might be able to offer additional discounts based on currently active promotions. Please contact our sales team today to see if you qualify for any additional discounts.
Where can I find the Syncfusion Blazor Graph demo?
You can find our Blazor Graph demo here.
Can I purchase the Syncfusion Blazor Graph component separately?
No, our 70 Blazor components, including Graph, are not sold individually, only as a single package. However, we have competitively priced the product, so it only costs a little bit more than what some other vendors charge for their charts alone. We have also found that, in our experience, our customers usually start off using one of our products and then expand to several products quickly, so we felt it was best to offer all 70+ Blazor components for a flat fee of $995/developer. On top of this, we might be able to offer additional discounts based on currently active promotions. Please contact our sales team today to see if you qualify for any additional discounts.
Is Syncfusion Blazor Graph free?
No, this is a commercial product and requires a paid license. However, a free community license is also available for companies and individuals whose organizations have less than $1 million USD in annual gross revenue and five or fewer developers.
How do I get started with Syncfusion Blazor Graph?
A good place to start would be our comprehensive getting started documentation.
Conclusion
I hope you enjoyed learning about the quick getting started with the Blazor Graph Component. You can explore the runnable sample of getting started with Blazor Graph from this this GitHub location.
You can refer to our Blazor Graph’s feature tour page to know about its other groundbreaking feature representations. You can also explore our Blazor Graph example to understand how to present and manipulate data.
For current customers, you can check out our Blazor components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our Blazor Graph and other Blazor components.
If you have any queries or require clarifications, please let us know in comments below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!