scatter.html 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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. 'echarts/component/toolbox'
  23. ], function (echarts) {
  24. var chart = echarts.init(document.getElementById('main'));
  25. var data1 = [];
  26. var data2 = [];
  27. var data3 = [];
  28. var random = function (max) {
  29. return (Math.random() * max).toFixed(3);
  30. }
  31. for (var i = 0; i < 30; i++) {
  32. data1.push([random(5), random(5), random(2)]);
  33. data2.push([random(10), random(10), random(2)]);
  34. data3.push([random(15), random(10), random(2)]);
  35. }
  36. chart.setOption({
  37. legend: {
  38. data: ['scatter', 'scatter2', 'scatter3']
  39. },
  40. toolbox: {
  41. left: 'left',
  42. feature: {
  43. dataView: {},
  44. saveAsImage: {}
  45. }
  46. },
  47. tooltip: {
  48. trigger: 'axis',
  49. axisPointer: {
  50. type: 'cross'
  51. }
  52. },
  53. xAxis: {
  54. type: 'value',
  55. splitLine: {
  56. show: false
  57. },
  58. min: 0,
  59. max: 15,
  60. splitNumber: 30
  61. },
  62. yAxis: {
  63. type: 'value',
  64. splitLine: {
  65. show: false
  66. }
  67. },
  68. series: [{
  69. name: 'scatter',
  70. type: 'scatter',
  71. label: {
  72. emphasis: {
  73. show: true
  74. }
  75. },
  76. // symbol: 'diamond',
  77. symbolSize: function (val) {
  78. return val[2] * 40;
  79. },
  80. // itemStyle: {
  81. // normal: {
  82. // color: function (params) {
  83. // return 'rgba(30, 70, 50, ' + params.value[2] + ')';
  84. // }
  85. // }
  86. // },
  87. data: data1
  88. }, {
  89. name: 'scatter2',
  90. type: 'scatter',
  91. label: {
  92. emphasis: {
  93. show: true,
  94. position: 'top',
  95. formatter: function (params) {
  96. return params.value;
  97. }
  98. }
  99. },
  100. symbolSize: function (val) {
  101. return val[2] * 40;
  102. },
  103. // itemStyle: {
  104. // normal: {
  105. // label: {
  106. // show: true
  107. // }
  108. // }
  109. // },
  110. data: data2
  111. }, {
  112. name: 'scatter3',
  113. type: 'scatter',
  114. label: {
  115. emphasis: {
  116. show: true
  117. }
  118. },
  119. symbolSize: function (val) {
  120. return val[2] * 40;
  121. },
  122. data: data3
  123. }],
  124. animationDelay: function (idx) {
  125. return idx * 20;
  126. },
  127. animationDelayUpdate: function (idx) {
  128. return idx * 20;
  129. }
  130. });
  131. chart.on('click', function (params) {
  132. console.log(params.data);
  133. });
  134. })
  135. </script>
  136. </body>
  137. </html>