HighCharts到2个或更多相同的div

时间:2012-06-12 14:36:38

标签: javascript jquery jquery-selectors highcharts

我有以下代码,只填充其中一个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?或者所有div如果有10,20,100或更多相同的div具有相同的类?

这是一个jsfiddle: http://jsfiddle.net/Chmts/

1 个答案:

答案 0 :(得分:3)

使用$ .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]        
        }]
    });
}));