JQuery移动和highcharts集成

时间:2011-06-30 08:26:56

标签: jquery-mobile highcharts

有没有人设法将highcharts与jquerymobile正确集成?

如果我直接请求包含某些图表的页面(即http://mysite.com/mobile/page.html),则图表将按预期进行初始化和渲染。相反,如果我尝试使用锚链接导航到同一页面,页面呈现但图表不会。我正在使用“pageshow”事件初始化图表。

任何反馈意见都会受到重视!

3 个答案:

答案 0 :(得分:4)

当我第一次开始使用jQuery Mobile进行编码时,我遇到了同样的问题...你必须在pagecreate上绑定你的脚本,即:

$(document).delegate("#page-id", "pagecreate", function() {
    // highcharts, etc.
}

答案 1 :(得分:1)

使用jQuery mobile,您需要将特定于页面的脚本和样式放在page-content div中。见"Known Limitations" in documentation.

答案 2 :(得分:1)

我已经尝试过沙皇提到的东西,对我来说它有用。我做的是:

在head标记中添加了脚本, 并在“页面内容”中添加了脚本中使用的ID(rederTo)。

<html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<title>Acura</title>
<link href="http://code.jquery.com/mobile/latest/jquery.mobile.min.css" rel="stylesheet">
<script src="http://code.jquery.com/jquery.min.js"></script>
<script src="http://code.jquery.com/mobile/latest/jquery.mobile.min.js"></script>
<script src="libs/hightcharts/highcharts.js"></script>
<script src="http://code.highcharts.com/modules/exporting.js"></script>

    <script type="text/javascript">
        var chart1; // globally available
$(document).ready(function() {
      chart1 = new Highcharts.Chart({
         chart: {
            renderTo: 'container',
            type: 'bar'
         },
         title: {
            text: 'Fruit Consumption'
         },
         xAxis: {
            categories: ['Apples', 'Bananas', 'Oranges']
         },
         yAxis: {
            title: {
               text: 'Fruit eaten'
            }
         },
         series: [{
            name: 'Jane',
            data: [1, 0, 4]
         }, {
            name: 'John',
            data: [5, 7, 3]
         }]
      });
   });
    </script>
</head>

<body>

<div id="ge" data-role="page">
    <div data-role="header">
        //header
    </div>
    <div data-role="content">
        <div id="container"></div>
    </div>
</div>
</body>
</html>