top of page

How to Create Data Visualization App with Blazor

Updated: Jan 11

Data visualization has become a pivotal aspect of modern applications, providing a compelling way to present complex information understandably and engagingly. In this guide, we will delve into the process of creating a data visualization app using Blazor, a powerful web framework, along with Flexmonster, a versatile data visualization library.


The fusion of Blazor and Flexmonster not only facilitates the development of interactive and visually appealing dashboards but also offers seamless integration of data visualization capabilities into web applications.

How to Create Data Visualization App with Blazor

In recent years, Blazor has gained popularity, especially among C# programmers, making it easier for them to get into web development. This framework is a game-changer because it lets developers use C# for both internal and external logic while incorporating the features of different JavaScript libraries in a single project.


Many users anticipate a surge in Blazor's usage, and it's not without reason. The framework offers great flexibility and versatility:

  1. Applications work seamlessly across all browsers without needing extra plugins.

  2. You can leverage your C# knowledge and still use any libraries compatible with .NET Standard.

  3. You have the option to adopt either a server-side or client-side approach.


However, the flexibility brings a choice between Blazor Server and Web Assembly for your project. The dilemma arises because:

  • With Blazor Server, you may experience a loss in speed, no offline capabilities, and a dependency on the ASP.NET Core server.

  • On the other hand, Web Assembly can boost speed by rendering on the client, but it introduces constraints related to browser capabilities and download speeds.


Nevertheless, Blazor has made its mark in the tech market with numerous integrations and collaborative projects involving various components and tools. In terms of capabilities, it stands strong against established frameworks like Angular or React.


If you would like to quickly develop a data analytics application using Blazor then you must opt for Flexmonster Pivot Table & Charts JavaScript Library.


Flexmonster Pivot Table & Charts JavaScript Library

Flexmonster Pivot Table & Charts is a robust JavaScript library designed to facilitate advanced data analysis and reporting within web applications. It seamlessly integrates into frameworks like Blazor, providing a powerful toolset for developers to create dynamic and interactive data visualizations.


Key Features:

  1. Pivot Table Functionality:

  • Flexmonster specializes in pivot table capabilities, allowing users to analyze and summarize large datasets with ease.

  • It provides drag-and-drop functionality, enabling users to arrange rows, columns, and measures effortlessly to tailor the view according to their needs.

  1. Interactive Charts:

  • In addition to pivot tables, Flexmonster offers a variety of interactive chart options. Users can choose from bar charts, line charts, scatter plots, and more to visualize data trends effectively.

  • The integration of charts adds a dynamic layer to data exploration, offering a more engaging and informative user experience.

  1. Cross-Platform Compatibility:

  • Flexmonster is built to work seamlessly across various platforms and devices, ensuring a consistent and responsive experience. Whether on desktops, tablets, or mobile devices, users can interact with data effortlessly.

  1. Data Connectivity:

  • The library supports versatile data connectivity options. Developers can connect Flexmonster to different data sources, including databases, CSV files, JSON, and more. This flexibility makes it adaptable to various data storage and retrieval scenarios.

  1. Integration with Blazor:

  • For developers working with Blazor, Flexmonster seamlessly integrates into Blazor applications. This allows the utilization of C# for server-side logic while leveraging the rich data visualization features provided by Flexmonster on the client side.

  1. Customization and Styling:

  • Flexmonster offers a high degree of customization, allowing developers to tailor the appearance of pivot tables and charts to match the overall design of their applications.

  • Style elements, color schemes, and layouts can be adjusted to create a cohesive and branded user interface.

  1. Exporting and Sharing:

  • Users can export their pivot tables and charts in various formats, including PDF, Excel, CSV, and more. This feature facilitates easy sharing and collaboration, allowing stakeholders to access and analyze data outside the application.

  1. Real-Time Updates:

  • Flexmonster supports real-time updates, making it suitable for applications where data changes dynamically. As data is updated on the server, the pivot table and charts can reflect these changes in real-time, providing users with the latest insights.


Creating a Data Visualization App with Blazor and Flexmonster: A Step-by-Step Guide

We will walk you through the complete process of building a data visualization app using Blazor and Flexmonster.


Step 1. Minimum preparations

If you are new to working with .NET, start by installing the .NET Software Developer Kit (SDK). Choose the appropriate version for your operating system. Verify the installation by running the dotnet command in the terminal.


Step 2. Create a Basic Blazor app

Create your first Blazor app by executing the following command in the terminal:

dotnet new blazorserver -o BlazorApp — no-https

This creates a new Blazor app project named BlazorApp in your current location, with HTTPS disabled. Check the basic app by opening http://localhost:5000 in your browser.


Create Basic Blazor App

Overview of the Basic Blazor App: Navigate through different pages using the left-side menu. All pages are defined in the Pages/ directory in .razor files. The default page is Index.razor.


Basic Blazor App 1


Step 3. Install and add a pivot table to our app

Install the Flexmonster.Blazor package by running the following command in your terminal:

dotnet add package Flexmonster.Blazor

Locate the _Imports.razor file in the project's root directory and add the following line at the end:

@using Flexmonster.Blazor

Display the pivot table on the page by adding the Flexmonster script to the <head> section of the _Host.cshtml file:

<head>
    <! — Other metadata tags →
    <link href=”css/app.css” rel=”stylesheet” />
    <link href=”PivotBlazor.styles.css” rel=”stylesheet” />
    <script src=”_content/Flexmonster.Blazor/blazor-             
        flexmonster.js”></script>
    <! — Other metadata tags →
</head>

In the FetchData.razor file, delete everything except the following line:

@page “/fetchdata”

Add the heading and the Flexmonster component to the file:

<h3>Pivot</h3>
<FlexmonsterComponent Report=”@report”
					Toolbar=”true”
					Width=”100%”
					Height=”600">
</FlexmonsterComponent>

Specify initialization parameters for Flexmonster:

  • Report: The report to display

  • Toolbar: Enable or disable the Flexmonster Toolbar

  • Width and Height: The size of the pivot


Define the variable to contain the report in the @code block:

@code 
{
string report =“https://cdn.flexmonster.com/reports/report.json";
}

Your final FetchData.razor file should look like this:

@page “/fetchdata”
<h3>Pivot</h3>
<FlexmonsterComponent Report=”@report”
					Toolbar=”true”
					Width=”100%”
					Height=”600">
</FlexmonsterComponent>

@code 
{
	string report = “https://cdn.flexmonster.com/reports/report.json";
}

Step 4. Run your Blazor app

Run your app using the following command:

dotnet run

Open http://localhost:5000 in your browser. The final result should resemble the provided image.


Final Blazor App


Conclusion

Creating a data visualization app with Blazor proves to be a smart choice for developers. Blazor's appeal lies in its user-friendly approach, cross-browser compatibility, and the ability to use familiar C# skills.


The addition of the Flexmonster Pivot Table & Charts library enhances this process, offering dynamic pivot tables and interactive charts that seamlessly integrate into Blazor applications.


The choice between Blazor Server and Web Assembly introduces considerations of speed and offline capabilities. However, the end goal remains consistent — delivering a responsive and engaging data visualization experience.

コメント


bottom of page