Jump to content

Não desenha o grafico

Recommended Posts


Tenho este código para desenhar um gráfico de barras, onde vai buscar o id do item e a pontuação do item à base de dados. Quando meto o programa a correr no visual studio 2019 asp.net core 3.0 ele não funciona.  O que está a funcionar mal aqui?

@model IEnumerable<sia_Final.Models.Item>
@inject IJsonHelper Json;

    ViewData["Title"] = "Grafico";

    <script type="text/javascript">
    window.onload = function () {
            var model =@Html.Raw(Json.Serialize(Model));
            var datapoints = [];

        model.forEach(function (Item) {
        model.forEach(function (Item) {
            console.log("id: " + String(Item.idItem)+ "  Pontuacao: " + String(Item.pontuacao) );
            // aux = [Item.idItem, Item.pontuacao];
            //console.log("aux: " + String(aux));
            var auxx = Item.idItem;
            console.log("auxx: " + String(auxx));
            var auxy = Item.pontuacao;
            console.log("auxy: " + String(auxy));
            datapoints.push({ x: auxx, y: auxy });

            var chart = new CanvasJS.Chart("Grafico", {
                theme: "theme2",
                title: {
                    text: "Gráfico de SIA"


                data: [{
                    type: "column",
                    datapoints: datapoints

        chart.options.data[0].datapoints = datapoints;


<div Id="Grafico" style="height:360px; width:100%"></div>
<script src="https://canvasjs.com/assets/script/canvasjs.min.js"></script>


Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.