Vue-echarts:工具提示适用于除我的一张图表之外的所有图表。为什么?

Vue-echarts: tooltip working on all but one of my charts. Why?

我开发的一个应用中有几个echarts。我正在使用 echarts 的 V4(目前还不能升级)并按照此处找到的工具提示使用文档进行操作:https://echarts.apache.org/v4/en/option.html#tooltip 除了我最新的以外,所有工具提示都显示得很好。我看不出新的和旧的有什么区别。

我已经明确地导入了正确的模块,如这个问题的答案中所述:Apache ECharts with Vue does not show Tooltip 就像我为我的旧模块所做的那样。

我用的是vue文件,上面是模板,中间是脚本,下面是css。该图表在模板中定义如下:

<echarts
  id="alertPie"
  :options="option"
  class="alertChart"
  autoresize
/>

在我的脚本部分,我有这些导入:

import 'echarts/lib/chart/pie'
import 'echarts/lib/component/tooltip'
import 'echarts/lib/component/title'
import 'echarts/lib/component/legend'

图表的“选项”是这样定义的计算字段:

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
      }
    }
  }

饼图正确显示了数据。标题和图例均正确显示。在导入的项目中,只有工具提示不起作用。

就像我说的,我的其他图表构建相同,工具提示也有效。我错过了什么?我盯着这个看,并与我的工作示例进行了比较,没有发现任何差异(除了数据源和 title/label 更改)。

有什么想法吗?

数据示例如下:

[ { "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 } ]

我已经用 CDN 试过了,应该可以。

<!--
    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/echarts@5.3.2/dist/echarts.min.js"></script>
        <!-- Uncomment this line if you want to dataTool extension
        <script type="text/javascript" src="https://cdn.jsdelivr.net/npm/echarts@5.3.2/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/echarts@5.3.2/map/js/china.js"></script>
        <script type="text/javascript" src="https://cdn.jsdelivr.net/npm/echarts@5.3.2/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>