Reputation: 2485
I need to pass some data to my maps canvasjs but not to sure how.
I have my data logging in 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);
});
});
Graph
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();
Upvotes: 0
Views: 866
Reputation: 72957
Something like this should work:
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.
});
And then in your chart initialization:
dataPoints: points
Upvotes: 1