
echarts 时序图,tooltip提示框添加vue组件渲染到页面上](https://i-blog.csdnimg.cn/direct/3978425baea74ef580483cdbf246ffe4.png)
在这里插入代码片
const option = {
title: {
},
tooltip: {
alwaysShowContent: true,
extraCssText: 'width:470px;min-height:275px',
enterable: true,
triggerOn: 'click',
className: 'echarts-tooltip',
},
xAxis: {
type: 'category',
boundaryGap: false,
data: years,
axisLine: {
show: false,
},
position: 'top',
},
yAxis: {
type: 'category',
data: clusterKeywords,
axisLine: {
show: false,
},
position: 'right',
axisLabel: {
formatter: function (value, index) {
const formattedValue = value.split('').reduce((acc, char, i) => {
return acc + char + ((i + 1) % 4 === 0 ? '\n' : '');
}, '');
return `{color${index}| ${formattedValue}}`;
},
rich: clusterKeywords.reduce((acc, keyword, index) => {
acc[`color${index}`] = {
color: groupColors[keyword],
fontWeight: 'bold',
fontSize: 14,
};
return acc;
}, {}),
align: 'left',
padding: [0, 0, 0, 20],
fontWeight: 'bold',
fontSize: 14,
},
},
series: [series],
};
在这里插入代码片
const series = {
type: 'graph',
layout: 'none',
coordinateSystem: 'cartesian2d',
legendHoverLink: true,
symbolSize: 40,
label: {
show: true,
},
edgeSymbol: ['circle', 'arrow'],
edgeSymbolSize: [4, 10],
data: seriesData,
links: links,
lineStyle: {
normal: {
show: true,
width: 2,
opacity: 0.3,
curveness: 0.2,
},
},
markLine: {
data: markLineData,
symbol: ['none', 'arrow'],
},
};
在这里插入代码片
import Vue from 'vue';
import router from '@/router';
import echartsTooltip from './echartsTooltip.vue';
const seriesData = parsedResult.flatMap((item) =>
item.evolutionKeywords.map((keyword) => {
if (!keywordCounter[item.clusterKeyword]) {
keywordCounter[item.clusterKeyword] = 0;
}
keywordCounter[item.clusterKeyword] += 1;
const uniqueName = `#${
clusterKeywords.length -
1 -
clusterKeywords.indexOf(item.clusterKeyword)
}_${keyword.keyword}`;
const color = groupColors[item.clusterKeyword];
return {
name: keyword.keyword,
id: uniqueName,
clusterKeyword: item.clusterKeyword,
value: [
years.indexOf(keyword.year),
clusterKeywords.indexOf(item.clusterKeyword),
keyword.count,
],
symbolSize: getCircleSize(keyword),
obj: { ...keyword },
itemStyle: {
color: color,
},
label: {
show: true,
position: 'bottom',
offset: [0, 10],
formatter: function (value) {
let str = value.name;
let max = 6;
if (str.length > max) {
return str.slice(0, max) + '\n' + str.slice(max, str.length);
}
return str;
},
fontWeight: 'bold',
},
tooltip: {
show: true,
formatter: function (value, ticket, callback) {
let question = value.data.clusterKeyword + '+' + value.name;
const div = document.createElement('div');
let mapTooltip = new Vue({
router,
render: (h) =>
h(echartsTooltip, {
props: {
name: value.name,
count: keyword.count,
year: keyword.year,
question: question,
},
on: {
changeList: (payload) => {
console.log('Received event:', payload);
},
closeTooltip: () => {
console.log('closeTooltip');
let tooltipElement =
document.querySelector('.echarts-tooltip');
tooltipElement.style.display = 'none';
},
},
}),
});
that.$nextTick(() => {
mapTooltip.$mount(div);
callback(ticket, mapTooltip.$el);
});
return `
<span style="font-weight:bold;">关键词:</span>${value.name}
<br>
<span style="font-weight:bold;">文献数量:</span>${keyword.count}
<br>
<span style="font-weight:bold;">学术高峰年:</span>${keyword.year}年
`;
},
},
};
})
);