Displaying Barchart with multiple datasets dynamically - Chart Js

Blooming Developer 281 Reputation points
2023-09-10T06:49:00.6933333+00:00

Hi All,

I want to display a barchart with multiple datasets as shown below,

User's image

i'm able to fetch the data as shown belowUser's image

But how to convert this json array as below code. I need to show the attendance percentage for each shift for last 7 days.


var barChartDataDaily = {
        labels: [@Html.Raw("'" + String.Join("','", (Model.GetWeeklyData.GroupBy(c => c.FormattedAccessDate).Select(c => c.First().FormattedAccessDate).ToList()))+"'" )],
        datasets: [
            {
                label: "First Shift",
                backgroundColor: "#7F1E5E",
                borderColor: "#7F1E5E",
                borderWidth: 1,
                data: [14, 27, 33, 46, 100, 67, 74]
            },
            {
                label: "Second Shift",
                backgroundColor: "#CE6D28",
                borderColor: "#CE6D28",
                borderWidth: 1,
                data: [14, 27, 33, 46, 100, 67, 74]
            },
            {
                label: "Third Shift",
                backgroundColor: "#005486",
                borderColor: "#005486",
                borderWidth: 1,
                data: [100, 27, 34, 56, 69, 87, 73]
            }
        ]
    };


Appreciate your help for this. Thanks!

ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,815 questions
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.