자바 스크립트 캔버스 Ajax.
-
26-12-2019 - |
문제
내지도 캔버스에 데이터를 전달해야하지만 확실하지 않은 방법을 확실하지 않아야합니다.
콘솔 Fine
에 데이터 로깅이 있습니다.콘솔 로그
35 + 397
6 + 399
12 + 1314
13 + 1316
.
데이터 가져 오기
$.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();
. 해결책
이렇게 작용해야합니다 :
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.
});
.
및 차트 초기화 :
dataPoints: points
. 제휴하지 않습니다 StackOverflow