TS使用echarts柱状图鼠标放上去并弹出

编程入门 行业动态 更新时间:2024-10-25 20:29:53

TS使用echarts柱状图<a href=https://www.elefans.com/category/jswz/34/1769042.html style=鼠标放上去并弹出"/>

TS使用echarts柱状图鼠标放上去并弹出

效果

代码

<template><div><Chart style="width: 100%; height: 344px" :option="chartOption" /></div>
</template><script lang="ts" setup>import { ref } from 'vue';import { ToolTipFormatterParams } from '@/types/echarts';const tooltipItemsHtmlString = (items: ToolTipFormatterParams[]) => {return items.map((el) => `<div class="content-panel"><p><span style="background-color: ${el.color}" class="tooltip-item-icon"></span><span>${el.seriesName}</span></p><span class="tooltip-value">${Number(el.value).toLocaleString()}</span></div>`).join('');};const xAxis = ref<string[]>(['1月','2月','3月','4月','5月','6月','7月','8月','9月','10月','11月','12月',]);const aseries = ref<number[]>([32, 43, 43, 53, 23, 143, 25, 23, 76, 98, 62, 34,]);const bseries = ref<number[]>([32, 13, 33, 53, 123, 43, 35, 54, 34, 47, 76, 54,]);const cseries = ref<number[]>([32, 143, 33, 73, 23, 13, 95, 54, 24, 22, 12, 23,]);const chartOption = {grid: {left: '3%', // 调整左边距right: '3%', // 调整右边距top: '20',bottom: '60',},color: ['#246EFF', '#81E2FF', '#00B2FF'],tooltip: {show: true, // 启用提示框trigger: 'axis', // 触发类型为坐标轴axisPointer: {type: 'cross', // 坐标轴指示器类型},formatter: (params: ToolTipFormatterParams[]) => {// 定义提示框的内容格式const [firstElement] = params as ToolTipFormatterParams[];return `<div><p class="tooltip-title">${firstElement.axisValueLabel}</p>${tooltipItemsHtmlString(params as ToolTipFormatterParams[])}</div>`;},className: 'echarts-tooltip-diy',},xAxis: {type: 'category',data: xAxis.value,},yAxis: {type: 'value',},series: [{name: '系列 A',data: aseries.value,type: 'bar',},{name: '系列 B',data: bseries.value,type: 'bar',},{name: '系列 C',data: cseries.value,type: 'bar',},],};
</script><style scoped lang="less"></style>

更多推荐

TS使用echarts柱状图鼠标放上去并弹出

本文发布于:2023-12-06 23:16:01,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1669298.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:鼠标   弹出   柱状图   TS   echarts

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!