开发者

30 Instances of a jQuery plugin on one page. Optimization?

开发者 https://www.devze.com 2023-03-23 06:36 出处:网络
I have a calendar I\'m generating with PHP that shows a standard month view. Inside of each day\'scell, there is an instance of jqPlot that loads a series of points.

I have a calendar I'm generating with PHP that shows a standard month view. Inside of each day's cell, there is an instance of jqPlot that loads a series of points.

Each day has its own chart, therefore with 31 days I need 31 charts. There is a noticable 1-2 second lag in Firefox. In IE, it is 6 or 7 seconds long. This is all client-side rendering time.

I'm 100% sure that there is a more efficient way of getting these charts to load a little quicker.

Below is a rough PHP script of what I'm doing.

    echo "<script type=\"text/javascript\">

    $(document).ready(function(){

    try {

    $.jqplot ('calendarchart$this_day', [[";

    foreach($todays_kwhs as $row){

        echo '["'.date('H:i', $row['time_read']).'",'.$row['kwh']. '],';

    }
    echo "]], 
          {
            axes: {
              xaxis: {
                showTicks: false,
                renderer: $.jqplot.DateAxisRenderer,
                ticks: [['00:00', '12AM'], ['06:00', '6AM'], ['12:00', '12PM'], ['18:00', '6PM'], ['24:00','12AM']]        ,
                pad: 0.0,
                tickOptions: {
                  formatString: '%H:%I%p'
                }
              },
              yaxis: {
                showTicks: false,
                min: 0,
                max: 600,
                pad:0.0
              }
            },
            seriesDefaults: {
              show: true,
              lineWidth: 1.0,
              markerOptions: {
                show: false
              }
            },
            gridPadding: {top:1, right:1, bottom:1, left:1},
            grid: {
              background: '#f开发者_运维百科fffff',
              borderWidth: 0,
              borderColor: '#cccccc',
              shadow: false,
              drawGridlines: true,
              gridLineColor: '#f0f0f0'
            }
          }
        );
      } catch(err) { console.log(err); }
    });
    </script>";
    }

Naturally, this is all repeated about 30 times and hangs up the client for a couple seconds.

0

精彩评论

暂无评论...
验证码 换一张
取 消