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">
import { ElMessage } from "element-plus";
const xData:Ref<any> = ref([])
const yData:Ref<any> = ref([])
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",
data: xData,
boundaryGap: true, //
axisLabel: {
color: "#fff",
fontWeight: "500",
formatter: function (value:any) {
return value.substring(0, 3) + '..'; //
},
type: "category",
data: xData,
boundaryGap: true, //
axisLabel: {
color: "#fff",
fontWeight: "500",
formatter: function (value: any) {
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",
backgroundColor: "rgba(0,0,0,.6)",
borderColor: "rgba(147, 235, 248, .8)",
textStyle: {
color: "#FFF",
},
},
grid: {
//
show: false,
left: "10px",
right: "30px",
bottom: "0px",
top: "20px",
containLabel: true,
// borderColor: "#1F63A3",
},
// dataZoom
dataZoom: [
{
type: 'slider', //
show: true, //
start: 0, //
end: 100, //
handleSize: 10, //
height: 10, //
xAxisIndex: [0], // x
filterMode: 'empty', // 'empty'
},
{
type: 'inside', //
start: 0,
end: 100
}
],
series: [
{
data: yData,
type: "bar",
smooth: false,
name: "已报到人数",
color: "#2265ff",
label: {
show: true, //
position: 'top', //
color: '#999',
fontSize: 12,
},
grid: {
//
show: false,
left: "10px",
right: "30px",
bottom: "0px",
top: "20px",
containLabel: true,
// borderColor: "#1F63A3",
},
// dataZoom
/* dataZoom: [
{
type: 'slider', //
show: true, //
start: 0, //
end: 50, //
handleSize: 10, //
height: 10, //
xAxisIndex: [0], // x
filterMode: 'empty', // 'empty'
},
{
type: 'inside', //
start: 0,
end: 100
}
], */
// dataZoom
dataZoom: [{
show: showZoom,
type: 'slider',
start: 0,
end: zoomIndex
}], // dataZoom null
series: [
{
data: yData,
type: "bar",
smooth: false,
name: "已报到人数",
color: "#2265ff",
label: {
show: true, //
position: 'top', //
color: '#999',
fontSize: 12,
}
}
],
}
],
});
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",
@ -111,24 +117,31 @@ const setOption = async (xData: any[], yData: any[]) => {
containLabel: true,
// borderColor: "#1F63A3",
},
// dataZoom
dataZoom: [
{
type: 'slider', //
show: true, //
start: 0, //
end: 100, //
handleSize: 10, //
height: 15, //
xAxisIndex: [0], // x
filterMode: 'empty' // 'empty'
},
{
type: 'inside', //
start: 0,
end: 100
}
],
// dataZoom
/* dataZoom: [
{
type: 'slider', //
show: true, //
start: 0, //
end: 100, //
handleSize: 10, //
height: 15, //
xAxisIndex: [0], // x
filterMode: 'empty' // 'empty'
},
{
type: 'inside', //
start: 0,
end: 100
}
], */
// dataZoom
dataZoom: [{
show: showZoom,
type: 'slider',
start: 0,
end: zoomIndex
}], // dataZoom null
series: [
{
data: yData,