如何使用谷歌图表onclick bootstrap选项卡按钮修复宽度和高度?

时间:2014-11-07 12:05:26

标签: javascript jquery html css twitter-bootstrap

我正在尝试在点击引导标签按钮时显示Google图表。我能够显示图表,但是我遇到了点击标签按钮上图表对齐的问题。请指导我如何解决这个问题。 我正在使用的Javascript -

<head>      
    <script src="/assets/jquery-1.10.2.js"></script>    
    <script src="/assets/bootstrap.js"></script>     


<script type="text/javascript" src="https://www.google.com/jsapi"></script>
    <script type="text/javascript">
      google.load("visualization", "1", {packages:["corechart"]});
      google.setOnLoadCallback(drawChart);
      function drawChart() {
        var data = google.visualization.arrayToDataTable([
          ['Task', 'Hours per Day'],
          ['Work',     11],
          ['Eat',      2],
          ['Commute',  2],
          ['Watch TV', 2],
          ['Sleep',    7]
        ]);

        var options = {
          title: 'My Daily Activities',
          is3D: true,
        };

        var chart = new google.visualization.PieChart(document.getElementById('google_chart1'));
        chart.draw(data, options);
      }
    </script>

    <script type="text/javascript" src="https://www.google.com/jsapi"></script>
    <script type="text/javascript">
      google.load("visualization", "1", {packages:["corechart"]});
      google.setOnLoadCallback(drawChart);
      function drawChart() {
        var data = google.visualization.arrayToDataTable([
          ['Task', 'Hours per Day'],
          ['Work',     11],
          ['Eat',      2],
          ['Commute',  2],
          ['Watch TV', 2],
          ['Sleep',    7]
        ]);

        var options = {
          title: 'My Daily Activities',
          is3D: true,
        };

        var chart = new google.visualization.PieChart(document.getElementById('google_chart2'));
        chart.draw(data, options);
      }
    </script>


</head>

身体部位 -

<section>
<div class="container">
  <div class="row">
      <div class="col-md-3">
        <div class="well well-lg">
        <ul id="myTab" class="nav nav-pills nav-stacked">
            <li class="active"><a href="#panel_conservative" data-toggle="tab">Side Tab 1</a></li>
            <li><a href="#panel_mconservative" data-toggle="tab">Side Tab 2</a></li>                   
        </ul>
        </div>
      </div>

      <div class="col-md-9">
      <div id="myTabContent" class="tab-content"> 

          <div class="tab-pane fade in active" id="panel_conservative">
              <div class="col-sm-12">
                <div class="panel panel-default">

                  <ul id="myTab1" class="nav nav-pills nav-justified">
                      <li class="active"><a href="#cons18" data-toggle="tab">Tab NO 1</a></li>
                      <li><a href="#cons31" data-toggle="tab">Tab NO 2</a></li>   
                  </ul>

                    <div class="panel-heading">
                        <div id="myTabContent1" class="tab-content">

                            <div class="tab-pane fade in active" id="cons18">
                                <div class="row">                                      
                                  <div class="col-sm-8">
                                    <div class="row pad_right">
              <div id="google_chart1" style="width: 500px;height: 300px;"></div>
                                    </div>
                                  </div>
                                </div>
                            </div>

                            <div class="tab-pane fade" id="cons31">
                                <div class="row">

                                  <div class="col-sm-8">
                                    <div class="row pad_right">               
              <div id="google_chart2" style="width: 500px;height: 300px;"></div>
                                    </div>
                                  </div>
                                </div>
                            </div>

                        </div>
                    </div>

                </div>
              </div>
          </div>

          <div class="tab-pane fade" id="panel_mconservative">
             content of side tab 2                  
          </div>


      </div>

      </div>
  </div>
</div>       
</section>

请检查此链接 - http://www.bootply.com/ddPRHKy8ey 在这里单击选项卡1,图表正确显示,div大小正常。但是在单击Tab 2时,Div大小会变短。我想解决这个问题。它应该像Tab 1一样显示。

1 个答案:

答案 0 :(得分:0)

只需从ryenus复制。 Why are Bootstrap tabs displaying tab-pane divs with incorrect widths when using highcharts?

/* bootstrap hack: fix content width inside hidden tabs */
.tab-content > .tab-pane,
.pill-content > .pill-pane {
display: block;     /* undo display:none          */
height: 0;          /* height:0 is also invisible */ 
overflow-y: hidden; /* no-overflow                */
}
.tab-content > .active,
.pill-content > .active {
height: auto;       /* let the content decide it  */
} /* bootstrap hack end */