Jump to content
Marta

Não desenha o grafico

Recommended Posts

Marta

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";
}

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

        console.log(String(model));
        model.forEach(function (Item) {
            console.log(String(Item.pontuacao));
        });
        model.forEach(function (Item) {
            console.log("id: " + String(Item.idItem)+ "  Pontuacao: " + String(Item.pontuacao) );
            // aux = [Item.idItem, Item.pontuacao];
            //console.log("aux: " + String(aux));
            //datapoints.push(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 });
        });
        console.log(datapoints);

        
            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;
        chart.render();
        };

       
    </script>
</head>

<h1>Grafico</h1>
<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.