I have several echarts in an application I develop. I'm using V4 of echarts (can't upgrade just yet) and following the documentation for tooltip usage as found here: https://echarts.apache.org/v4/en/option.html#tooltip All but my latest one are showing the tooltip just fine. I cannot see any difference between my new one and my old ones.
I have explicitly imported the proper modules as outlined in the answer to this question: Apache ECharts with Vue does not show Tooltip just like I did for my old ones.
I use vue files with the template on top, script in the middle, and css at the bottom. The chart is defined in the template thus:
<echarts
id="alertPie"
:options="option"
autoresize
/>
In my scripts section, I have these imports:
import 'echarts/lib/chart/pie'
import 'echarts/lib/component/tooltip'
import 'echarts/lib/component/title'
import 'echarts/lib/component/legend'
The "option" for the chart is a computed field defined thus:
computed: {
option () {
return {
backgroundColor: '#efefef',
textStyle: {
fontStyle: 'italic',
fontWeight: 'bold'
},
title: {
text: 'Alert Adoption',
subtext: 'Count by Alert',
left: 'center',
top: 10,
textStyle: {
color: '#ee0022',
textBorderColor: '#000000',
textBorderWidth: 2,
textShadowColor: 'rgba(0,0,0,0.5)',
textShadowBlur: 4,
fontWeight: 'bold',
textShadowOffsetX: 2,
textShadowOffsetY: 2,
fontSize: 28
},
subtextStyle: {
color: 'black'
}
},
tooltip: {
trigger: 'item',
formatter: '{a} <br/>{b} : {c} ({d}%)'
},
legend: {
// orient: 'vertical',
// top: 'middle',
bottom: 10,
left: 'center'
},
series: [
{
name: 'pie',
type: 'pie',
data: this.alertPieData,
radius: '40%',
center: ['50%', '40%'],
selectedMode: 'single',
itemStyle: {
emphasis: {
shadowBlur: 10,
shadowOffsetX: 0,
shadowColor: 'rgba(0, 0, 0, 0.5)'
}
}
}
],
animationDuration: 2000
}
}
}
The pie shows the data correctly. The title and legend both show correctly. Of the imported items, only the tooltip is not working.
Like I said, my other charts are built the same and tooltips work. What could I have missed? I've stared at this and compared to my working examples and don't see any differences (other than data sources and title/label changes).
Any ideas?
Data sample below:
[ { "name": "Acthar Gel Med Order Alert", "value": 10 },
{ "name": "Anticoagulation / Hemoglobin Alert", "value": 6 },
{ "name": "Anticoagulation or Dual Antiplatelet / Hemoglobin Alert", "value": 7 },
{ "name": "Berinert Alert", "value": 10 },
{ "name": "Blood Culture Identification Alert", "value": 13 },
{ "name": "Clostridium Difficile Alert", "value": 9 },
{ "name": "Clostridium Difficile Lab Order Alert", "value": 15 },
{ "name": "Controlled Substance - Pyxis Removal / Late Admin Alert", "value": 13 } ]
CodePudding user response:
I have tried this using CDN it should work.
<!--
THIS EXAMPLE WAS DOWNLOADED FROM https://echarts.apache.org/examples/en/editor.html?c=pie-roseType
-->
<!DOCTYPE html>
<html style="height: 100%">
<head>
<meta charset="utf-8">
</head>
<body style="height: 100%; margin: 0">
<div id="container" style="height: 100%"></div>
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/[email protected]/dist/echarts.min.js"></script>
<!-- Uncomment this line if you want to dataTool extension
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/[email protected]/dist/extension/dataTool.min.js"></script>
-->
<!-- Uncomment this line if you want to use gl extension
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/echarts-gl@2/dist/echarts-gl.min.js"></script>
-->
<!-- Uncomment this line if you want to echarts-stat extension
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/echarts-stat@latest/dist/ecStat.min.js"></script>
-->
<!-- Uncomment this line if you want to use map
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/[email protected]/map/js/china.js"></script>
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/[email protected]/map/js/world.js"></script>
-->
<!-- Uncomment these two lines if you want to use bmap extension
<script type="text/javascript" src="https://api.map.baidu.com/api?v=2.0&ak=<Your Key Here>"></script>
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/echarts@{{version}}/dist/extension/bmap.min.js"></script>
-->
<script type="text/javascript">
var dom = document.getElementById("container");
var myChart = echarts.init(dom);
var app = {};
var option;
option = {
backgroundColor: '#efefef',
textStyle: {
fontStyle: 'italic',
fontWeight: 'bold'
},
title: {
text: 'Alert Adoption',
subtext: 'Count by Alert',
left: 'center',
top: 10,
textStyle: {
color: '#ee0022',
textBorderColor: '#000000',
textBorderWidth: 2,
textShadowColor: 'rgba(0,0,0,0.5)',
textShadowBlur: 4,
fontWeight: 'bold',
textShadowOffsetX: 2,
textShadowOffsetY: 2,
fontSize: 28
},
subtextStyle: {
color: 'black'
}
},
tooltip: {
trigger: 'item',
formatter: '{a} <br/>{b} : {c} ({d}%)'
},
legend: {
// orient: 'vertical',
// top: 'middle',
bottom: 10,
left: 'center'
},
series: [
{
name: 'pie',
type: 'pie',
data: [ { "name": "Acthar Gel Med Order Alert", "value": 10 },
{ "name": "Anticoagulation / Hemoglobin Alert", "value": 6 },
{ "name": "Anticoagulation or Dual Antiplatelet / Hemoglobin Alert", "value": 7 },
{ "name": "Berinert Alert", "value": 10 },
{ "name": "Blood Culture Identification Alert", "value": 13 },
{ "name": "Clostridium Difficile Alert", "value": 9 },
{ "name": "Clostridium Difficile Lab Order Alert", "value": 15 },
{ "name": "Controlled Substance - Pyxis Removal / Late Admin Alert", "value": 13 } ],
radius: '40%',
center: ['50%', '40%'],
selectedMode: 'single',
itemStyle: {
emphasis: {
shadowBlur: 10,
shadowOffsetX: 0,
shadowColor: 'rgba(0, 0, 0, 0.5)'
}
}
}
],
animationDuration: 2000
}
if (option && typeof option === 'object') {
myChart.setOption(option);
}
</script>
</body>
</html>