Bootstrap标签页(Tab)插件切换echarts不显示问题的

1.  在echarts跟bootstrap选项卡整合的时候,默认第一个选中选项卡可以正常加载echarts图表,但是切换其他选项的时候不能渲染出其他选项卡echarts图表。

2.  echarts自适应怎么实现?

解决办法:

//解决tab切换不显示问题 在加载窗口后重新渲染。 $('a[data-toggle="pill"]').on('shown.bs.tab', function(e) { for(var i = 0; i < charts.length; i++) { charts[i].resize(); } }); //data-toggle="pill还是data-toggle="tab" 根据前面所用标签页的不同来选择

//echarts自适应 var charts = []; var chart1 = echarts.init(document.getElementById("left1")); var chart2 = echarts.init(document.getElementById("left2")); var chart3 = echarts.init(document.getElementById("right11")); var chart4 = echarts.init(document.getElementById("right12")); var chart5 = echarts.init(document.getElementById("right21")); var chart6 = echarts.init(document.getElementById("right22")); chart1.setOption(option1); chart2.setOption(option1); chart3.setOption(option2); chart4.setOption(option2); chart5.setOption(option1); chart6.setOption(option1); charts.push(chart1); charts.push(chart2); charts.push(chart3); charts.push(chart4); charts.push(chart5); charts.push(chart6); $(window).resize(function() { for(var i = 0; i < charts.length; i++) { charts[i].resize(); } })

下面看一个实现的demo:

demo 完成内容:

1. bootstrap实现响应式布局

2. echats实现自适应

3. 标签页切换、缩放正常显示

<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <!--设置视口的宽度(值为设备的理想宽度),页面初始缩放值<理想宽度/可见宽度>--> <meta content="width=device-width, initial-scale=1"> <link type="text/css" href="https://www.jb51.net/css/bootstrap.min.css" /> <link href="https://www.jb51.net/css/main.css" /> <!-- 可选的Bootstrap主题文件(一般不用引入) --> <link href="https://cdn.bootcss.com/twitter-bootstrap/3.0.3/css/bootstrap-theme.min.css" > <title></title> <!-- jQuery文件。务必在bootstrap.min.js 之前引入 --> <script src="https://www.jb51.net/js/jquery-3.1.1.js"></script> <!-- 最新的 Bootstrap 核心 JavaScript 文件 --> <script src="https://www.jb51.net/js/bootstrap.min.js"></script> <!-- 最新的echarts核心 JavaScript 文件 --> <script src="https://www.jb51.net/js/echarts.js"></script> <script src="https://www.jb51.net/js/main.js" type="text/javascript" charset="utf-8"></script> </head> <body> <div> <div> <div> <div> </div> <div> </div> </div> <div> <div> <ul> <li> <a href="#right1" data-toggle="pill">1</a> </li> <li> <a href="#right2" data-toggle="pill">2</a> </li> <li> <a href="#" data-toggle="pill">3</a> </li> <li> <a href="#" data-toggle="pill">4</a> </li> <li> <a href="#" data-toggle="pill">5</a> </li> </ul> </div> <div> <div> <div> </div> <div> </div> </div> <div> <div> </div> <div> </div> </div> </div> </div> </div> </div> </body> </html> <script type="text/javascript"> var charts = []; var chart1 = echarts.init(document.getElementById("left1")); var chart2 = echarts.init(document.getElementById("left2")); var chart3 = echarts.init(document.getElementById("right11")); var chart4 = echarts.init(document.getElementById("right12")); var chart5 = echarts.init(document.getElementById("right21")); var chart6 = echarts.init(document.getElementById("right22")); chart1.setOption(option1); chart2.setOption(option1); chart3.setOption(option2); chart4.setOption(option2); chart5.setOption(option1); chart6.setOption(option1); charts.push(chart1); charts.push(chart2); charts.push(chart3); charts.push(chart4); charts.push(chart5); charts.push(chart6); $(window).resize(function() { for(var i = 0; i < charts.length; i++) { charts[i].resize(); } }); //解决tab切换不显示问题 在加载窗口后重新渲染。 $('a[data-toggle="pill"]').on('shown.bs.tab', function(e) { for(var i = 0; i < charts.length; i++) { charts[i].resize(); } }); </script>

.css_height{ height: 400px; margin-top: 30px; } .css_height1{ height: 400px; margin-top: 72px; } .right_title{ width: 90%; margin-left: 10%; } .nav>li>a{ padding: 5px 18px; margin-top: 10px; } body{ background-color:#009688; } .container{ background-color:#dcedf5; margin-top: 25px; border-radius: 15px; }

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/ebb89b866920a2dc18dce7ea7079a329.html