【发布时间】:2023-03-27 18:10:01
【问题描述】:
我正在尝试在一个 div 中创建多个 CanvasJS 图表。
div 需要来自控制器的数据数组,循环通过它(使用 ng-repeat)并在各种控件中显示数据。
现在,当我尝试将 CanvasJS 图表放入此 div 时,图表不会呈现,并且我看到的错误是“未找到带有 id 的图表”
但同样的图表在这个 div 之外也能正常工作。
此处的示例代码: http://jsfiddle.net/DTheWebDev/mozfsxpc/7/
APP.JS
var m = {
"India": "2",
"Australia": "3"
};
function MyCtrl($scope) {
$scope.items = m;
}
var dps = [{
x: 1,
y: 10
}]; //dataPoints.
var chart = new CanvasJS.Chart("chartContainer", {
title: {
text: "Live Data"
},
axisX: {
title: "Axis X Title"
},
axisY: {
title: "Units"
},
data: [{
type: "line",
dataPoints: dps
}]
});
chart.render();
var xVal = dps.length - 1;
var yVal = 15;
var updateInterval = 1000;
var updateChart = function() {
yVal = yVal + Math.round(5 + Math.random() * (-5 - 5));
dps.push({
x: xVal,
y: yVal
});
xVal--;
chart.render();
};
setInterval(function() {
updateChart()
}, updateInterval);
HTML:
<h3>Match Summary:</h3>
<div ng-app ng-controller="MyCtrl">
<div ng-repeat="(country,goals) in items">
<div id="chartContainer" style="height: 200px; width: 100%;"></div>
<h2>{{country}}: {{goals}} </h2>
</div>
</div>
尝试搜索类似问题,但没有成功。
提前感谢您的时间和帮助。
【问题讨论】:
标签: angularjs html angularjs-ng-repeat canvasjs