当前位置:   article > 正文

echarts tooltip自定义线条样式及数据提示框内容_echarts自定义tooltip边框

echarts自定义tooltip边框
  1. option = {
  2. ......
  3. tooltip: {
  4. trigger: 'axis',
  5. borderWidth: 0, // 去除数据提示框默认的边框
  6. axisPointer: {
  7. lineStyle: { // 设置hover时竖线样式
  8. color: {
  9. type: 'linear',
  10. x: 0,
  11. y: 0,
  12. x2: 0,
  13. y2: 1,
  14. colorStops: [
  15. {
  16. offset: 0,
  17. color: 'rgba(128,200,244,0)' // 0% 处的颜色
  18. },
  19. {
  20. offset: 1,
  21. color: 'rgba(128,200,244,1)' // 100% 处的颜色
  22. }
  23. ],
  24. global: false // 缺省为 false
  25. }
  26. }
  27. },
  28. backgroundColor: 'transparent', // 去除数据提示框默认的背景
  29. formatter: (p) => { // 自定义数据提示框默认的样式 返回DOM结构
  30. let dom = `<div style="width: 100px;
  31. height: 50px;;color:#fff;position: relative;">
  32. <svg style="position: absolute;top: 50%;
  33. left: 50%;
  34. transform: translateX(-50%) translateY(-50%);" class="svg" xmlns="http://www.w3.org/2000/svg" width="100" height="71" viewBox="0 0 84 55">
  35. <defs>
  36. <style>
  37. .cls-1 {
  38. fill: #07172c;
  39. fill-opacity: 0.8;
  40. stroke: #a7d8ff;
  41. stroke-linejoin: round;
  42. stroke-opacity: 0.2;
  43. stroke-width: 1px;
  44. fill-rule: evenodd;
  45. }
  46. </style>
  47. </defs>
  48. <path id="矩形_419" data-name="矩形 419" class="cls-1" d="M266,595h74v50H266V624.046L261,620l5-3.984V595Z"
  49. transform="translate(-258.5 -592.5)" />
  50. </svg>
  51. <div style="padding: 4px 8px 4px 17px;display: flex;
  52. justify-content: center;
  53. align-items: center;
  54. flex-direction: column;position: relative;z-index: 1;">
  55. <div style="margin-bottom: 4px;width:100%;display:${
  56. p[0] ? 'block' : 'none'
  57. };justify-content:space-between;align-items:center;">
  58. <span style="font-size:14px;color:#fff;">${
  59. p[0]
  60. ? '日期:' +
  61. (p[0].name.indexOf('0') == 0
  62. ? p[0].name.slice(1)
  63. : p[0].name)
  64. : ''
  65. }</span><br>
  66. <span style="font-size:14px;color:#fff;">${
  67. p[0] ? '数值:' + p[0].data : ''
  68. }</span>
  69. </div>
  70. </div>
  71. </div>`;
  72. return dom;
  73. }
  74. },
  75. ......
  76. };

效果如下:

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/笔触狂放9/article/detail/308720?site
推荐阅读
相关标签
  

闽ICP备14008679号