我有以下代码,仅填充 1 个 div:
$(function () {
var $container = $('.portlet_content_18');
var chart = new Highcharts.Chart({
chart: {
renderTo: $container[0],
height: 400
},
xAxis: {
categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
},
series: [{
data: [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4]
}]
});
});
HTML 看起来链接如下:
<div class="portlet_content_18">
<div class="portlet_content_18">
如何让它填充两个 div?或者如果有 10、20、100 或更多具有相同类的相同 div,则为所有 div?
这是一个jsfiddle: http://jsfiddle.net/Chmts/
最佳答案
使用$.each:
$('.portlet_content_18').each(function(){
var chart = new Highcharts.Chart({
chart: {
renderTo: this,
height: 400
},
xAxis: {
categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
},
series: [{
data: [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4]
}]
});
}));
关于javascript - HighCharts 到 2 个或更多相同的 div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10998911/