Pergunta

Preciso passar alguns dados para meus canvasjs de mapas, mas não sei como.

Eu tenho meu registro de dados no console bem

Registro do console

35 + 397 
6 + 399 
12 + 1314 
13 + 1316 

Buscar dados

$.get("graph/" + $_GET["centre"] + "", function (d) {

    var graphDataData = null;

    try {
        graphDataData = JSON.parse(d);
    }
    catch (err) {
        return;
    }

    $.each(graphDataData, function(key, value) {
          console.log(value.value + " + " + value.source);
    });
});

Gráfico

var chart = new CanvasJS.Chart("chartContainer", {
---->
    data: [
    {     
        type: "bar",
        name: "Stores",
        axisYType: "secondary",
        color: "#00b6de",               
        dataPoints: [


        // Put my data here.
        {y: 5, label: "Sweden"  },
        {y: 6, label: "Taiwan"  },
        {y: 7, label: "Russia"  },

        ]
    }

    ]
});

chart.render();
Foi útil?

Solução

Algo assim deve funcionar:

var points = [];
$.each(graphDataData, function(key, value) {
      points.push({y: value.value, label:value.source}); // I'm assuming that's how the data has to be structured.
});

E então na inicialização do seu gráfico:

dataPoints: points
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top