JavaScript Canvasjs Ajax.
-
26-12-2019 - |
Domanda
Ho bisogno di passare alcuni dati alle mie mappe canvasjs ma non sicuro di come.
Ho le mie registrazioni di dati nella console Fine
Console Log
35 + 397
6 + 399
12 + 1314
13 + 1316
.
Fetch Data
$.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);
});
});
.
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();
. Soluzione
Qualcosa come questo dovrebbe funzionare:
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 poi nell'inizializzazione del tuo grafico:
dataPoints: points
. Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow