在js文件中写了两遍一样的代码(改了id名称),在html中调用JS时只显示第二个id的图

onload = function(){

 Highcharts.chart('twitterChart1', {

    title: {
        text: 'Solar Employment Growth by Sector, 2010-2016'
    },

    subtitle: {
        text: 'Source: thesolarfoundation.com'
    },

    yAxis: {
        title: {
            text: 'Number of Employees'
        }
    },
    legend: {
        layout: 'vertical',
        align: 'right',
        verticalAlign: 'middle'
    },

    plotOptions: {
        series: {
            label: {
                connectorAllowed: false
            },
            pointStart: 2010
        }
    },

    series: [ {
        name: 'Other',
        data: [12908, 5948, 8105, 11248, 8989, 11816, 18274, 18111]
    }],

    responsive: {
        rules: [{
            condition: {
                maxWidth: 500
            },
            chartOptions: {
                legend: {
                    layout: 'horizontal',
                    align: 'center',
                    verticalAlign: 'bottom'
                }
            }
        }]
    }

});};

    这个是因为两次onload,只能调用最后一个吗?
方法一:
window.onload = function(){
    Highcharts.chart('twitterChart1', {
        ...........
    });
    Highcharts.chart('twitterChart2', {
        ...........
    });
};

方法二:
function a(){
    Highcharts.chart('twitterChart1', {
        ...........
    });
};
function b(){
    Highcharts.chart('twitterChart2', {
        ...........
    });
};
window.onload = function(){
    a();
    b();
};

方法三:
window.addEventListener("load", function () {
    Highcharts.chart('twitterChart1', {
        ...........
    });
}, false);
window.addEventListener("load", function () {
    Highcharts.chart('twitterChart2', {
        ...........
    });
}, false);

onload后面的方法会覆盖前面的,如果想两个都能执行,应该使用jquery的$(window).load(function(){}),或者这样写

function setOnload(fun){
    var old = function(){};
    if(typeof window.onload=='function'){
        old = window.onload;
    }
    window.onload = function(){
        old();
        fun();
    }
}