2

I am trying to display Google chart on clicking bootstrap tab button. I am able to display the chart but I am facing problem with the alignment of the chart on clicking tab button. Please guide me how can I fix this. Javascript I am using-

<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>

Body part-

<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>

Please check this link- http://www.bootply.com/ddPRHKy8ey Here onclicking Tab 1 the chart appears properly and the div size is ok. But on clicking Tab 2 the Div size gets shorter. I want to fix this. it should appear as it is like Tab 1.

Rajat Kar
  • 23
  • 2

1 Answers1

0

Simply copied from 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 */
Community
  • 1
  • 1
Priyanko
  • 318
  • 1
  • 5
  • 13