效果
代码
<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>