showTip.html 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <html>
  2. <head>
  3. <meta charset="utf-8">
  4. <script src="esl.js"></script>
  5. <script src="config.js"></script>
  6. </head>
  7. <body>
  8. <style>
  9. html, body, #main {
  10. width: 100%;
  11. height: 100%;
  12. }
  13. </style>
  14. <div id="main"></div>
  15. <script>
  16. require([
  17. 'echarts',
  18. 'echarts/chart/scatter',
  19. 'echarts/component/legend',
  20. 'echarts/component/grid',
  21. 'echarts/component/tooltip'
  22. ], function (echarts) {
  23. var chart = echarts.init(document.getElementById('main'));
  24. var data1 = [];
  25. var data2 = [];
  26. var data3 = [];
  27. var random = function (max) {
  28. return (Math.random() * max).toFixed(3);
  29. }
  30. for (var i = 0; i < 30; i++) {
  31. data1.push([random(5), random(5), random(2)]);
  32. data2.push([random(10), random(10), random(2)]);
  33. data3.push([random(15), random(10), random(2)]);
  34. }
  35. chart.setOption({
  36. legend: {
  37. data: ['scatter', 'scatter2', 'scatter3']
  38. },
  39. tooltip: {
  40. trigger: 'axis',
  41. axisPointer: {
  42. type: 'cross'
  43. },
  44. position: 'top'
  45. },
  46. xAxis: {
  47. type: 'value',
  48. splitLine: {
  49. show: false
  50. },
  51. min: 0,
  52. max: 15,
  53. splitNumber: 30
  54. },
  55. yAxis: {
  56. type: 'value',
  57. splitLine: {
  58. show: false
  59. }
  60. },
  61. series: [{
  62. name: 'scatter',
  63. type: 'scatter',
  64. label: {
  65. emphasis: {
  66. show: true
  67. }
  68. },
  69. // symbol: 'diamond',
  70. symbolSize: function (val) {
  71. return val[2] * 40;
  72. },
  73. data: data1
  74. }, {
  75. name: 'scatter2',
  76. type: 'scatter',
  77. label: {
  78. emphasis: {
  79. show: true
  80. }
  81. },
  82. symbolSize: function (val) {
  83. return val[2] * 40;
  84. },
  85. data: data2
  86. }, {
  87. name: 'scatter3',
  88. type: 'scatter',
  89. label: {
  90. emphasis: {
  91. show: true
  92. }
  93. },
  94. symbolSize: function (val) {
  95. return val[2] * 40;
  96. },
  97. data: data3
  98. }]
  99. });
  100. var count = 0;
  101. setInterval(function () {
  102. chart.dispatchAction({
  103. type: 'showTip',
  104. // seriesIndex: 0,
  105. dataIndex: (count++) % data1.length
  106. });
  107. }, 1000);
  108. });
  109. </script>
  110. </body>
  111. </html>