<div id="main" style="width: 100%;height:65vh;margin-top:5vh;position:absolute;"></div>
/*
图表
*/
// 基于准备好的dom,初始化echarts实例
var myChart = echarts.init(document.getElementById('main'));
// 指定图表的配置项和数据
var option = {
title: {
text: '数量top5',
left:'center',
top:'10px',
textStyle: { //文本样式
fontSize: 24,
color: '#7f7f7f'
}
},
xAxis: {
data: ["线路板","电容","电阻","电感","电解"],
axisTick: {
show: false,
},
axisLine: {
show: false
}
},
yAxis: [
{
type: 'value',
min: 0, //最小值
max: 35, //最大值
interval: 5, //间隔
axisTick: {
show: false,
},
axisLine: {
show: false
}
}
],
series: [{
name: '销量',
type: 'bar',
data: [32, 19, 18, 15, 12],
itemStyle: {
normal: {
color: '#4f81bd',
label: {
show: true, //显示
position: 'top', //在上方
textStyle: { //文字样式
color: 'black',
fontSize: 12
}
}
}
}
}]
};
// 使用刚指定的配置项和数据显示图表。
myChart.setOption(option);
window.onresize = function() {
var h1=document.documentElement.clientHeight;//获取屏幕的高度
if(h1>700){
myChart.getDom().style.height = 65 + "vh";
}else{
myChart.getDom().style.height = 60 + "vh";
}
myChart.resize();
}
util.call(function(h){
//h为点击的那个高度
var h2=document.documentElement.clientHeight;//获取屏幕的高度
console.log(h2);
if(h2<600){
//这里重新设置echarts的高度
myChart.getDom().style.height = ((h2-h)/2)+70 + "px";
myChart.resize();
}
})