0

我有以下代码,其中一个 Jquery 选项卡显示一个表格,另一个选项卡显示一个使用 HighCharts 制作的饼图。如果我删除 div 标签之间的表格,饼图会成功显示,但是一旦表格包含在 div 中,饼图将不再显示。我的代码有问题还是已知的 highcharts/jQuery 问题?

<script type="text/javascript">
    $(function () {
        $('#pie').highcharts({
            chart: { type:'pie' },
            title: { text: 'Test'},
            tooltip: {
                pointFormat: '{series.name}: <b>{point.percentage}%</b>',
                formatter: function() {
                    return '<b>'+ this.point.name +'</b>: '+ Math.round(this.percentage) +' %';
                }
            },
            plotOptions: {
                pie: {
                    allowPointSelect: true,
                    dataLabels: false,
                    showInLegend: true
                }
            },
            series: [{
                name: 'Overall Attendance',
                data: [
                    ['Present Students',4],
                    ['Absent Students',4],
                    ['Late Students',5]
                ]
            }],
            colors: [
                '#132f55',
                '#eeeeee',
                '#7f95aa'
            ]
        });
    });
</script>

<p id="notice"><%= notice %></p>
<ul id="tabs" class="nav nav-tabs">
  <li class="active"><a href="#registration" data-toggle="tab">Registration</a></li>
  <li><a href="#pie" data-toggle="tab">Pie Chart</a></li>
</ul>

<div class="tab-content">
  <div class="tab-pane active" id="registration">
    <table border="1">
      <tr>
        <td>row 1, cell 1</td>
        <td>row 1, cell 2</td>
      </tr>
      <tr>
        <td>row 2, cell 1</td>
        <td>row 2, cell 2</td>
      </tr>
    </table>
    <%= link_to 'Edit', edit_register_path(@register) %> |
    <%= link_to 'Back', registers_path %>

  </div>
  <div class="tab-pane" id="pie" style="width:91%; height:400px; ">  </div>
</div>
4

2 回答 2

0

你想要这样吗?在此处查看演示:http: //jsfiddle.net/visnupriya/qFwwf/

代码在这里:

    <li><a href="#tabs-3">Tab 3</a></li>
</ul>
<div id="tabs-1">
    <div id="container" style="width: 320px; height: 200px"></div>
</div>
<div id="tabs-2">
  <table border="1">
  <tr>
    <td>row 1, cell 1</td>
    <td>row 1, cell 2</td>
  </tr>
  <tr>
    <td>row 2, cell 1</td>
    <td>row 2, cell 2</td>
  </tr>
</table>
</div>
<div id="tabs-3">
    <p>Content for Tab 3</p>
</div>

于 2013-04-19T11:04:02.257 回答
0

请看小提琴

<div id="tabs">
  <ul>
    <li><a href="#registration">Nunc tincidunt</a></li>
    <li><a href="#pie">Proin dolor</a></li>

  </ul>
  <div class="tab-pane active" id="registration">
    <table border="1">
      <tr>
        <td>row 1, cell 1</td>
        <td>row 1, cell 2</td>
      </tr>
      <tr>
        <td>row 2, cell 1</td>
        <td>row 2, cell 2</td>
      </tr>
    </table>

  </div>
<div class="tab-pane" id="pie" style="width:91%; height:400px; ">  <div id="chart"></div>

</div>

您需要正确地附上 div。

于 2013-04-19T11:00:11.820 回答