<template>
<div class="echarts-content">
<div ref="chartRef" id="mainDataZoom" style="width: 100vw; height: 600px"></div>
</div>
</template>
<script lang="ts" setup>
import {onMounted, ref, shallowRef} from 'vue';
import * as echarts from 'echarts';
import {useDataZoom} from '@/views/Echart/useDataZoom';
const chartRef = shallowRef();
const chart = shallowRef();
onMounted(() => {
const chartDom = document.getElementById('mainDataZoom');
const myChart = echarts.init(chartDom);
chart.value = myChart;
const option = {
grid: {
left: 100,
right: 100
},
xAxis: {
type: 'category',
data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun', 'Mon1', 'Tue1', 'Wed1', 'Thu1', 'Fri1', 'Sat1', 'Sun1', 'Mon2', 'Tue2', 'Wed2', 'Thu2', 'Fri2', 'Sat2', 'Sun2']
},
yAxis: {
type: 'value'
},
series: [
{
data: [120, 200, 150, 80, 70, 110, 130, 120, 200, 150, 80, 70, 110, 130, 120, 200, 150, 80, 70, 110, 130],
type: 'bar',
label: {
show: true,
position: 'top',
fontSize: 13,
fontWeight: 'normal',
color: '#242424'
},
emphasis: {
focus: 'series'
},
barWidth: 30,
barGap: '30%'
}
],
dataZoom: [
{
type: 'slider',
show: true,
filterMode: 'weakFilter',
showDataShadow: false,
showDetail: false,
brushSelect: false,
height: 20,
bottom: 10,
startValue: 0,
endValue: 10
}
]
};
option && myChart.setOption(option);
window.addEventListener('resize',() => {
chart.value.resize()
// autoSizeDrawDataZoom()
});
})
const { autoSizeDrawDataZoom } = useDataZoom(chart, 140)
</script>
<style scoped lang="scss">
.m-2 {
width: 100px;
}
.echarts-content {
width: 100%;
display: grid;
grid-template-columns: repeat(3, 33%);
gap: 20px;
}
.chart-item {
height: 800px;
}
</style>