Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am creating a page containing tab using Twitter bootstrap. And want to add google charts inside the every tab content. But when I run the app the chart takes different size in width and height though I mentioned width and height in every chart using inline css. How can I fix the problem? If any one have any idea please share with me. You can see my code here:

http://www.bootply.com/ddPRHKy8ey


JavaScript
<code><pre><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></pre>
</code>


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


</body>
Posted
Updated 6-Nov-14 23:17pm
v3
Comments
vbmike 7-Nov-14 10:48am    
Googling this issue reveals that charts have some problems with bootstrap as it were. I did not go further but you should look into the google docs for this. Their charts put some code in for you and apparently it is not working super with bootstrap etc. I bet there is a way around it but you will have to experiment some....

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900