問題
前端使用bootstrap,引入百度ECHarts,但是ECHarts不能隨着bootstrap自適應佈局,就算設置了overflow:hidden
還是不可以。
解決辦法
window.onresize = function() {
$('#baiduECharts').width('90%');
myChart.resize();
};
完整代碼
var myChart = echarts.init(document.getElementById('baiduECharts'));
var option = {
title: {
text: ' ↑'
},
tooltip: {
trigger: 'axis'
},
legend: {
data: ['已評審', '待評審']
},
grid: {
left: '3%',
right: '4%',
bottom: '3%',
containLabel: true
},
toolbox: {
feature: {
saveAsImage: {}
}
},
xAxis: {
type: 'category',
boundaryGap: false,
data: ['2020/1', '2020/2', '2020/3', '2020/4', '2020/5', '2020/6', '2020/7']
},
yAxis: {
type: 'value'
},
series: [
{
name: '已評審',
type: 'line',
stack: '總量',
data: [120, 132, 101, 134, 90, 230, 210]
},
{
name: '待評審',
type: 'line',
stack: '總量',
data: [220, 182, 191, 234, 290, 330, 310]
}
]
};
myChart.setOption(option);
/*解決百度ECHarts不能自適應問題*/
window.onresize = function() {
$('#baiduECharts').width('90%');
myChart.resize();
};
結尾