echarts dataZoom控制滚轮滚动而不是缩放
const lnbsInit = () => {
const chartEle: HTMLElement = document.getElementById("echarts1") as HTMLElement;
// chartEle.removeAttribute("_echarts_instance_");
const myChart1 = echarts.init(chartEle);
let xData:any = ['2019', '2020', '2021', '2022', '2023', '2024','44','45','67','68','69']
let yData:any = [123,123,343,232,232,122,23,54,56,23,456]
let legenData:any = ["日均流量", "敏感生态流量下限", "敏感生态流量上限"]
let option = {
backgroundColor: '#ddd',
title: {
show: xData.length == 0,
text: '暂无数据',
x: 'center',
y: 'center',
textStyle: {
fontFamily: 'Manteka',
fontSize: '12',
fontWeight: 'normal',
color: '#ACD4FF'
}
},
tooltip: {
trigger: "axis",
axisPointer: {
type: "shadow",
},
},
legend: {
show: false,
data: legenData,
top: "1%",
textStyle: {
color: "rgba(172, 212, 255, 1)",
},
itemWidth: 10,
itemHeight: 10,
},
grid: {
top: '10%',
left: "6%",
right: "4%",
bottom: "5%",
containLabel: true,
},
xAxis: [
{
type: "category",
data: xData,
axisLine: {
show: false,
},
axisTick: {
show: false,
},
axisLabel: {
show: true,
textStyle: {
color: "rgba(172, 212, 255, 1)",
},
},
},
],
yAxis: [
{
type: "value",
name: xData.length == 0 ? '' : "流量:m³/s",
nameTextStyle: {
color: "rgba(172, 212, 255, 1)"
},
axisTick: {
show: false,
},
axisLabel: {
show: true,
textStyle: {
color: "rgba(172, 212, 255, 1)",
},
},
axisLine: {
show: false,
},
splitLine: {
lineStyle: {
color: "rgba(255, 255, 255, 0.25)",
width: 1,
type: "dashed",
},
},
},
],
//滚轮控制滚动
dataZoom: [
{
id: 'dataZoomY',
xAxisIndex: [0],
show: true, //是否显示滑动条,不影响使用
type: 'slider', // 这个 dataZoom 组件是 slider 型 dataZoom 组件
startValue: 0, // 从头开始。
endValue: 4, // 一次性展示5个
height: 6,
borderColor: 'transparent',
fillerColor: 'rgba(205,205,205,1)',
zoomLock: true,
showDataShadow: false, //是否显示数据阴影 默认auto
backgroundColor: '#fff',
showDetail: false, //即拖拽时候是否显示详细数值信息 默认true
realtime: true, //是否实时更新
filterMode: 'filter',
handleIcon: 'circle',
handleStyle: {
color: 'rgba(205,205,205,1)',
borderColor: 'rgba(205,205,205,1)',
},
handleSize: '80%',
moveHandleSize: 0,
maxValueSpan: 4,
minValueSpan: 4,
brushSelect: false, //刷选功能,设为false可以防止拖动条长度改变 ************(这是一个坑)
}, {
type:'inside',
xAxisIndex:0,
zoomOnMouseWheel:false, //滚轮是否触发缩放
moveOnMouseMove:true, //鼠标滚轮触发滚动
moveOnMouseWheel:true
}
],
series: [
{
name: legenData[0],
type: "bar",
barWidth: 10,
data: yData,
smooth: false,
symbol: 'circle', // 设置拐点为圆形
symbolSize: 6,
areaStyle: {
normal: {
color: new echarts.graphic.LinearGradient(
0,
0,
0,
1,
[
{
offset: 0,
color: "rgba(10, 161, 255, 0.45)",
},
{
offset: 1,
color: "rgba(10, 161, 255, 0.05)",
},
],
false
),
},
},
itemStyle: {
normal: {
color: "#0FA0FF",
borderColor: "#0FA0FF",
borderWidth: 2,
},
},
}
],
};
myChart1.setOption(option);
}