echarts的滑块

This commit is contained in:
张宁 2024-07-05 17:31:19 +08:00
parent 228fd0a5c6
commit 4933e4b52d
2 changed files with 110 additions and 84 deletions

View File

@ -1,8 +1,13 @@
<script setup lang="ts">
import { ElMessage } from "element-plus";
const xData: Ref<any> = ref([])
const yData: Ref<any> = ref([])
const zoomIndex = computed(() => {
return (7 / xData.value.length)?.toFixed(1) as any * 100 || 0
})
const showZoom = computed(() => {
return xData.value.length > 7
})
const option = reactive({
xAxis: {
type: "category",
@ -38,12 +43,12 @@ const option = reactive({
// borderColor: "#1F63A3",
},
// dataZoom
dataZoom: [
/* dataZoom: [
{
type: 'slider', //
show: true, //
start: 0, //
end: 100, //
end: 50, //
handleSize: 10, //
height: 10, //
xAxisIndex: [0], // x
@ -55,7 +60,14 @@ const option = reactive({
start: 0,
end: 100
}
],
], */
// dataZoom
dataZoom: [{
show: showZoom,
type: 'slider',
start: 0,
end: zoomIndex
}], // dataZoom null
series: [
{
data: yData,
@ -77,8 +89,9 @@ const getData = (params: any) => {
let dateList = params.map((el: any) => el.professionalName)
let numList = params.map((el: any) => el.reportNumber)
setOption(dateList, numList)
};
const setOption = async (x: any[], y: any[]) => {
const setOption = (x: any[], y: any[]) => {
// console.log(x, y);
xData.value = x
yData.value = y

View File

@ -36,6 +36,12 @@ const getData = () => {
setOption(tabs.value[0].dateList, tabs.value[0].numList)
};
const setOption = async (xData: any[], yData: any[]) => {
const zoomIndex = computed(() => {
return (12 / xData.length)?.toFixed(1) as any * 100 || 0
})
const showZoom = computed(() => {
return xData.length > 12
})
option.value = {
xAxis: {
type: "category",
@ -112,7 +118,7 @@ const setOption = async (xData: any[], yData: any[]) => {
// borderColor: "#1F63A3",
},
// dataZoom
dataZoom: [
/* dataZoom: [
{
type: 'slider', //
show: true, //
@ -128,7 +134,14 @@ const setOption = async (xData: any[], yData: any[]) => {
start: 0,
end: 100
}
],
], */
// dataZoom
dataZoom: [{
show: showZoom,
type: 'slider',
start: 0,
end: zoomIndex
}], // dataZoom null
series: [
{
data: yData,