Data Visualization with Chart.js and .NET Core API

Ibrahim Jaber
5 min readMar 7, 2023

With Chart.js and .NET Core API, you can easily create beautiful charts and graphs that help you analyze and understand your data. In this blog post, we’ll walk you through a step-by-step process of using Chart.js with a .NET Core API to create different types of charts, including pie charts, bar charts, and line charts.

Let’s dive in!

Setting Up the .NET Core API

To get started, we’ll create a simple .NET Core API that returns some data we can use to create charts. Let’s say we’re running a coffee shop and want to track our sales of different products. Our API will return data in the following format:

[
{
"productName": "Coffee",
"totalAmount": 500
},
{
"productName": "Latte",
"totalAmount": 300
},
{
"productName": "Muffin",
"totalAmount": 200
}
]

To create this API, follow these steps:

  1. Open Visual Studio and create a new project.
  2. Select “ASP.NET Core Web Application” and click “Next”.
  3. Name your project and click “Create”.
  4. Choose the “API” template and click “Create”.
  5. Open the Controllers folder and create a new class called SalesController.
  6. Add the following code to the SalesController class:
[Route("api/[controller]")]
[ApiController]
public class SalesController : ControllerBase
{…

--

--

Ibrahim Jaber

Software developer | Programming and Blockchain enthusiast