0

我有很多图表(hightchart)要在同一个页面中生成,加载我所有的图表至少需要 5-6 秒..

网页:

    <div class="graph_score" title="2" >
    <div class="graph_score" title="3" >
    <div class="graph_score" title="4" >
    <div class="graph_score" title="5" >
....

我的jQuery:

    $(".graph_score").each(function() {
      id_graph = $(this).attr("title");

      $.getJSON('http://' + document.domain + '/school/teachers/generate_score/graph' + id_graph, function(data) {
            options = data;
            options.tooltip = {
            formatter: function() {
                var extrafield = this.series.options.extrafield;
                var extrafield2 = this.series.options.extrafield2;
                var extrafield3 = this.series.options.extrafield3;
                return '<b> Note: ' + this.y + ' % <br/>' + '<b>Nom de l\'examen:</b>' + extrafield[this.point.x - 1] + '</b><br/><b>Pondération</b>' + extrafield2[this.point.x - 1] + "<br /><b>Date</b>" + extrafield3[this.point.x - 1];
            }
            }
            chart = new Highcharts.Chart(options);
        });

    })

我可以做些什么来更快地呈现这个页面吗?

*我知道问题是我的脚本调用 8 次http://' + document.domain + '/school/teachers/generate_score所以它的 8 个 DOM 请求......但我不知道如何优化它......

谢谢

4

1 回答 1

2

如果您认为网络传输需要很长时间,那么您可以在服务器上创建一个新函数,该函数获取 ID 列表并返回多个结果。

于 2012-04-11T15:03:45.580 回答