我想用 Highcharts 在 Angularjs 中动态创建图表。问题是,Highcharts 没有找到渲染它的 div,尽管已经创建了。
<div ng-controller="MyCtrl">
<button class="btn btn-default" ng-click="test()">Test</button>
<div id="test"></div>
</div>
function MyCtrl($scope) {
var names = ["ab", "cd", "de"];
_.each(names, function(name) {
$("#test").append("<div id='" + name + "'>");
});
$scope.test = function() {
_.each(names, function(name) {
var chart = {
chart: {
type: 'line',
zoomType: 'x',
spacingRight: 20,
renderTo: "#" + name
},
title: {
text: "name"
},
xAxis: {
type: 'datetime',
dateTimeLabelFormats: {
month: '%e. %b',
year: '%b'
}
},
series: [{
name: "test1",
data: [
[1, 2],
[2, 3],
[3, 3],
[4, 2]
]
}]
}
var chartObj = new Highcharts.Chart(chart);
});
}
}
这是我的小提琴:http: //jsfiddle.net/Phosphoros/bRNZV/2/
提前谢谢了!