tooltip
https://echarts.apache.org/zh/option.html#tooltip.alwaysShowContent

  1. tooltip: {
  2. trigger: 'axis',
  3. backgroundColor: 'rgba(50,50,50,.8)',
  4. textStyle: {
  5. fontSize: 12,
  6. color: '#ccc',
  7. },
  8. enterable: true,
  9. extraCssText: 'max-height: 300px; overflow: auto;',
  10. // formatter: '{b1} <br /> {a0}: {c0} <br /> {a1}: {c1} <br /> {a2}: {c2}-{c3}',
  11. formatter(params) {
  12. const [a, b, c, d] = params;
  13. console.log('params', params);
  14. return `${a.axisValueLabel}<br/>
  15. ${a.marker} ${a.seriesName}<span style='float:right;margin-left:8px;font-size:12px;color:#ccc;font-weight:900'>${a.data}</span><br/>
  16. ${b.marker} ${b.seriesName}<span style='float:right;margin-left:8px;font-size:12px;color:#ccc;font-weight:900'>${b.data}</span><br/>
  17. ${c.marker} ${c.seriesName}<span style='float:right;margin-left:8px;font-size:12px;color:#ccc;font-weight:900'>${c.data}-${d.data}</span>`;
  18. },
  19. appendToBody: true,
  20. // alwaysShowContent: true, 一直显示 tooltip
  21. },

tooltip formatter模板字符串

  1. formatter: '{b1} <br /> {a0}: {c0} <br /> {a1}: {c1} <br /> {a2}: {c2}-{c3}',

formatter params callback

image.png
tooltip 默认的样式

  1. <div
  2. class=""
  3. style="
  4. position: absolute; display: block;
  5. border-style: solid; white-space: nowrap; z-index: 9999999; will-change: transform;
  6. box-shadow: rgba(0, 0, 0, 0.2) 1px 2px 10px;
  7. transition: opacity 0.2s cubic-bezier(0.23, 1, 0.32, 1) 0s,
  8. visibility 0.2s cubic-bezier(0.23, 1, 0.32, 1) 0s, transform 0.4s cubic-bezier(0.23, 1, 0.32, 1) 0s;
  9. background-color: rgba(50, 50, 50, 0.8);
  10. border-width: 1px; border-radius: 4px; color: rgb(204, 204, 204);
  11. font: 12px / 18px sans-serif; padding: 10px; top: 0px; left: 0px;
  12. transform: translate3d(1057px, 415px, 0px);
  13. border-color: rgb(255, 255, 255);
  14. max-height: 300px; overflow: auto; pointer-events: auto;"
  15. >
  16. <div style="margin: 0px 0 0;line-height:1;">
  17. <div style="margin: 0px 0 0;line-height:1;">
  18. <div style="font-size:12px;color:#ccc;font-weight:400;line-height:1;">
  19. 2020-06-01 09:33
  20. </div>
  21. <div style="margin: 10px 0 0;line-height:1;">
  22. <div style="margin: 0px 0 0;line-height:1;">
  23. <div style="margin: 0px 0 0;line-height:1;"><span
  24. style="display:inline-block;margin-right:4px;border-radius:10px;width:10px;height:10px;background-color:#188ffe;"></span><span
  25. style="font-size:12px;color:#ccc;font-weight:400;margin-left:2px">求和</span><span
  26. style="float:right;margin-left:20px;font-size:12px;color:#ccc;font-weight:900">4,475</span>
  27. <div style="clear:both"></div>
  28. </div>
  29. <div style="clear:both"></div>
  30. </div>
  31. <div style="margin: 10px 0 0;line-height:1;">
  32. <div style="margin: 0px 0 0;line-height:1;"><span
  33. style="display:inline-block;margin-right:4px;border-radius:10px;width:10px;height:10px;background-color:#2fc25b;"></span><span
  34. style="font-size:12px;color:#ccc;font-weight:400;margin-left:2px">baseline</span><span
  35. style="float:right;margin-left:20px;font-size:12px;color:#ccc;font-weight:900">6,406.453755785153</span>
  36. <div style="clear:both"></div>
  37. </div>
  38. <div style="clear:both"></div>
  39. </div>
  40. <div style="margin: 10px 0 0;line-height:1;">
  41. <div style="margin: 0px 0 0;line-height:1;"><span
  42. style="display:inline-block;margin-right:4px;border-radius:10px;width:10px;height:10px;background-color:rgb(47,194,91, 0.4);"></span><span
  43. style="font-size:12px;color:#ccc;font-weight:400;margin-left:2px">boundary</span><span
  44. style="float:right;margin-left:20px;font-size:12px;color:#ccc;font-weight:900">-</span>
  45. <div style="clear:both"></div>
  46. </div>
  47. <div style="clear:both"></div>
  48. </div>
  49. <div style="margin: 10px 0 0;line-height:1;">
  50. <div style="margin: 0px 0 0;line-height:1;"><span
  51. style="display:inline-block;margin-right:4px;border-radius:10px;width:10px;height:10px;background-color:rgb(47,194,91, 0.4);"></span><span
  52. style="font-size:12px;color:#ccc;font-weight:400;margin-left:2px">boundary</span><span
  53. style="float:right;margin-left:20px;font-size:12px;color:#ccc;font-weight:900">-</span>
  54. <div style="clear:both"></div>
  55. </div>
  56. <div style="clear:both"></div>
  57. </div>
  58. <div style="clear:both"></div>
  59. </div>
  60. <div style="clear:both"></div>
  61. </div>
  62. <div style="clear:both"></div>
  63. </div>
  64. </div>

marker

图例样式和颜色,echarts默认的样式

  1. <span
  2. style="
  3. display:inline-block;
  4. margin-right:4px;
  5. border-radius:10px;
  6. width:10px;
  7. height:10px;
  8. background-color:#188ffe;"
  9. ></span>