最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

echart中tooltip自動展示代碼示例

 更新時間:2023年09月22日 09:48:50   作者:13pan  
這篇文章主要給大家介紹了關(guān)于echart中tooltip自動展示的相關(guān)資料,ECharts是一款基于JavaScript的數(shù)據(jù)可視化圖表庫,提供直觀,生動,可交互,可個性化定制的數(shù)據(jù)可視化圖表,需要的朋友可以參考下

引入js文件

import {autoHover} from ‘./tooltip’

/**
 * echarts tooltip輪播
 * @param chart ECharts實例
 * @param chartOption echarts的配置信息
 * @param options object 選項
 * {
 *  interval    輪播時間間隔,單位毫秒,默認(rèn)為3000
 *              true表示循環(huán)所有series的tooltip,false則顯示指定seriesIndex的tooltip
 *  seriesIndex 默認(rèn)為0,指定某個系列(option中的series索引)循環(huán)顯示tooltip,
 *              當(dāng)loopSeries為true時,從seriesIndex系列開始執(zhí)行。
 * }
 * @returns {{clearLoop: clearLoop}|undefined}
 */
 export function autoHover(myChart, option, num, time) {
    var defaultData = { // 設(shè)置默認(rèn)值
      time: 3000,
      num: 14
    };
    if (!time) {
      time = defaultData.time;
    }
    if (!num) {
      num = defaultData.num;
    }
    var count = 0;
    var timeTicket = 0;
    // 清除定時器
    function clearLoop() {
      if (timeTicket) {
        clearInterval(timeTicket);
        timeTicket = 0;
      }
      myChart.off('mousemove', stopAutoShow);
      myChart.getZr().off('mousemove', zRenderMouseMove);
      // myChart.getZr().off('globalout', zRenderGlobalOut);
    }
    // 關(guān)閉輪播
    function stopAutoShow() {
      if (timeTicket) {
        clearInterval(timeTicket);
        timeTicket = 0;
      }
    }
    function zRenderMouseMove(param) {
      if (param.event) {
        // 阻止canvas上的鼠標(biāo)移動事件冒泡
        // param.event.cancelBubble = true;
      }
      stopAutoShow();
    }
    timeTicket && clearInterval(timeTicket);
    timeTicket = setInterval(function() {
      myChart.dispatchAction({
        type: 'downplay',
        seriesIndex: 0 // serieIndex的索引值   可以觸發(fā)多個
      });
      myChart.dispatchAction({
        type: 'highlight',
        seriesIndex: 0,
        dataIndex: count
      });
      myChart.dispatchAction({
        type: 'showTip',
        seriesIndex: 0,
        dataIndex: count
      });
      count++;
      if (count >= num) {
        count = 0;
      }
    }, time);
    myChart.on('mouseover', function(params) {
      clearInterval(timeTicket);
      myChart.dispatchAction({
        type: 'downplay',
        seriesIndex: 0
      });
      myChart.dispatchAction({
        type: 'highlight',
        seriesIndex: 0,
        dataIndex: params.dataIndex
      });
      myChart.dispatchAction({
        type: 'showTip',
        seriesIndex: 0,
        dataIndex: params.dataIndex
      });
    });
    myChart.on('mouseout', function() {
      timeTicket && clearInterval(timeTicket);
      timeTicket = setInterval(function() {
        myChart.dispatchAction({
          type: 'downplay',
          seriesIndex: 0 // serieIndex的索引值   可以觸發(fā)多個
        });
        myChart.dispatchAction({
          type: 'highlight',
          seriesIndex: 0,
          dataIndex: count
        });
        myChart.dispatchAction({
          type: 'showTip',
          seriesIndex: 0,
          dataIndex: count
        });
        count++;
        if (count >= 14) {
          count = 0;
        }
      }, 3000);
    });
    return {
      clearLoop: clearLoop
    };
  }

在echart里注冊使用

 myChart.setOption(option, true);
      this.tootipTimer && this.tootipTimer.clearLoop(); // this.tootipTimer 在data里定義
      this.tootipTimer = 0;
      this.tootipTimer = autoHover(myChart, option, 8, 3000);

附:echart tooltip自定義 

ECharts 提供了 tooltip 的自定義功能,可以通過 formatter 函數(shù)來自定義 tooltip 的內(nèi)容和樣式。

下面是一個簡單的示例:

option = {
  // ... 其他配置項
  tooltip: {
    trigger: 'axis',
    axisPointer: {
      type: 'cross',
      crossStyle: {
        color: '#999'
      }
    },
    formatter: function (params) {
      // 自定義 tooltip 的內(nèi)容和樣式
      return params[0].name + '<br/>' +
        params[0].seriesName + ' : ' + params[0].value + '<br/>' +
        params[1].seriesName + ' : ' + params[1].value + '<br/>' +
        params[2].seriesName + ' : ' + params[2].value + '<br/>' +
        params[3].seriesName + ' : ' + params[3].value + '<br/>'
    }
  },
  // ... 其他配置項
  series: [
    {
      name:'郵件營銷',
      type:'bar',
      data:[120, 132, 101, 134, 90, 230, 210]
    },
    {
      name:'聯(lián)盟廣告',
      type:'bar',
      data:[220, 182, 191, 234, 290, 330, 310]
    },
    {
      name:'視頻廣告',
      type:'bar',
      data:[150, 232, 201, 154, 190, 330, 410]
    },
    {
      name:'直接訪問',
      type:'bar',
      data:[320, 332, 301, 334, 390, 330, 320]
    }
  ]
};

在上面的示例中,通過 formatter 函數(shù)來自定義 tooltip 的內(nèi)容和樣式。在這個函數(shù)中,我們可以通過 params 參數(shù)獲取到當(dāng)前 tooltip 中所展示的數(shù)據(jù),從而可以自定義 tooltip 的樣式和展示內(nèi)容。

需要注意的是,formatter 函數(shù)的返回值必須是一個字符串。在字符串中,可以使用 HTML 標(biāo)簽來控制 tooltip 的樣式,比如使用 <br/> 來換行。

總結(jié) 

到此這篇關(guān)于echart中tooltip自動展示的文章就介紹到這了,更多相關(guān)echart tooltip自動展示內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評論

潍坊市| 城固县| 闵行区| 新平| 巨野县| 江阴市| 华安县| 邹城市| 阳高县| 乐东| 济阳县| 诸城市| 莱芜市| 自治县| 阜阳市| 涟水县| 冕宁县| 永兴县| 华阴市| 榆林市| 全椒县| 西乌珠穆沁旗| 吴忠市| 常熟市| 东方市| 开江县| 静乐县| 磴口县| 永嘉县| 南丰县| 寿光市| 荆门市| 大竹县| 苗栗市| 米泉市| 宁南县| 平湖市| 台南县| 延川县| 九江县| 连云港市|