2

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

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

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

Code: http://www.bootply.com/ddPRHKy8ey

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Priyank Dey
  • 1,104
  • 1
  • 19
  • 43
  • Possible duplicate of [Why are Bootstrap tabs displaying tab-pane divs with incorrect widths when using highcharts?](https://stackoverflow.com/questions/17206631/why-are-bootstrap-tabs-displaying-tab-pane-divs-with-incorrect-widths-when-using) – Brian Tompsett - 汤莱恩 Aug 08 '19 at 21:17

2 Answers2

7

Got the solution from ryenus. Thanks to him. Why are Bootstrap tabs displaying tab-pane divs with incorrect widths when using highcharts?

Update

Please check out the updated solution.

Community
  • 1
  • 1
Priyank Dey
  • 1,104
  • 1
  • 19
  • 43
0

Pass width and height as options

        var options = {
            title: 'My Daily Activities',
            is3D: true,
            width: 500,
            height: 300
        };

Demo here

anpsmn
  • 7,217
  • 2
  • 28
  • 44