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

View File

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