Skip to content
Advertisement

How to create chartjs chart with data from database C#

I am trying to create a chart.js graph in my .Net Core Web app, with data from the database. I am using ajax to call a method that will pull the data from the database, but I’m unsure how to group the data to display in the graph.

At the moment I have a database that looks like so:

Database table

I am looking to show the time along the bottom and count how many jobs success and how m any jobs exception. At the moment my graph is hard coded.

Hard coded graph layout

JavaScript

Advertisement

Answer

Here is a simple demo like below:

1.Model:

JavaScript

2.View:

JavaScript

3.Controller:

JavaScript

4.Database:

enter image description here

5.Result:

enter image description here

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement