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,84 +1,97 @@
<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",
data: xData, data: xData,
boundaryGap: true, // boundaryGap: true, //
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) + '..'; //
},
}, },
}, },
yAxis: { },
show: false, yAxis: {
show: false,
},
tooltip: {
trigger: "axis",
backgroundColor: "rgba(0,0,0,.6)",
borderColor: "rgba(147, 235, 248, .8)",
textStyle: {
color: "#FFF",
}, },
tooltip: { },
trigger: "axis", grid: {
backgroundColor: "rgba(0,0,0,.6)", //
borderColor: "rgba(147, 235, 248, .8)", show: false,
textStyle: { left: "10px",
color: "#FFF", right: "30px",
}, bottom: "0px",
}, top: "20px",
grid: { containLabel: true,
// // borderColor: "#1F63A3",
show: false, },
left: "10px", // dataZoom
right: "30px", /* dataZoom: [
bottom: "0px", {
top: "20px", type: 'slider', //
containLabel: true, show: true, //
// borderColor: "#1F63A3", start: 0, //
}, end: 50, //
// dataZoom handleSize: 10, //
dataZoom: [ height: 10, //
{ xAxisIndex: [0], // x
type: 'slider', // filterMode: 'empty', // 'empty'
show: true, //
start: 0, // },
end: 100, // {
handleSize: 10, // type: 'inside', //
height: 10, // start: 0,
xAxisIndex: [0], // x end: 100
filterMode: 'empty', // 'empty' }
], */
}, // dataZoom
{ dataZoom: [{
type: 'inside', // show: showZoom,
start: 0, type: 'slider',
end: 100 start: 0,
} end: zoomIndex
], }], // dataZoom null
series: [ series: [
{ {
data: yData, data: yData,
type: "bar", type: "bar",
smooth: false, smooth: false,
name: "已报到人数", name: "已报到人数",
color: "#2265ff", color: "#2265ff",
label: { label: {
show: true, // show: true, //
position: 'top', // position: 'top', //
color: '#999', color: '#999',
fontSize: 12, fontSize: 12,
}
} }
], }
],
}); });
const getData = (params: any) => { 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",
@ -111,24 +117,31 @@ const setOption = async (xData: any[], yData: any[]) => {
containLabel: true, containLabel: true,
// borderColor: "#1F63A3", // borderColor: "#1F63A3",
}, },
// dataZoom // dataZoom
dataZoom: [ /* dataZoom: [
{ {
type: 'slider', // type: 'slider', //
show: true, // show: true, //
start: 0, // start: 0, //
end: 100, // end: 100, //
handleSize: 10, // handleSize: 10, //
height: 15, // height: 15, //
xAxisIndex: [0], // x xAxisIndex: [0], // x
filterMode: 'empty' // 'empty' filterMode: 'empty' // 'empty'
}, },
{ {
type: 'inside', // type: 'inside', //
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,