tooltip.html 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. <html>
  2. <head>
  3. <meta charset="utf-8">
  4. <script src="esl.js"></script>
  5. <script src="config.js"></script>
  6. <meta name="viewport" content="width=device-width, initial-scale=1" />
  7. </head>
  8. <body>
  9. <style>
  10. html, body, #main {
  11. width: 100%;
  12. height: 100%;
  13. margin: 0;
  14. }
  15. #main {
  16. width: 1000px;
  17. background: #fff;
  18. }
  19. </style>
  20. <div id="main"></div>
  21. <script>
  22. require([
  23. 'echarts',
  24. 'echarts/chart/bar',
  25. 'echarts/component/legend',
  26. 'echarts/component/grid',
  27. 'echarts/component/tooltip'
  28. ], function (echarts) {
  29. var chart = echarts.init(document.getElementById('main'), null, {
  30. renderer: 'canvas'
  31. });
  32. var xAxisData = [];
  33. var data1 = [];
  34. var data2 = [];
  35. var data3 = [];
  36. var data4 = [];
  37. for (var i = 0; i < 10; i++) {
  38. xAxisData.push('类目' + i);
  39. data1.push((Math.random() * 5).toFixed(2));
  40. data2.push(-Math.random().toFixed(2));
  41. data3.push((Math.random() + 0.5).toFixed(2));
  42. data4.push((Math.random() + 0.3).toFixed(2));
  43. }
  44. chart.setOption({
  45. tooltip : { // Option config. Can be overwrited by series or data
  46. trigger: 'axis',
  47. //show: true, //default true
  48. showDelay: 0,
  49. hideDelay: 50,
  50. transitionDuration:0,
  51. backgroundColor : 'rgba(255,0,255,0.7)',
  52. borderColor : '#f50',
  53. borderRadius : 8,
  54. borderWidth: 2,
  55. padding: 10, // [5, 10, 15, 20]
  56. axisPointer: {
  57. type: 'shadow'
  58. },
  59. position : function(p) {
  60. // 位置回调
  61. // console.log && console.log(p);
  62. return [p[0] + 10, p[1] - 10];
  63. },
  64. textStyle : {
  65. color: 'yellow',
  66. decoration: 'none',
  67. fontFamily: 'Verdana, sans-serif',
  68. fontSize: 15,
  69. fontStyle: 'italic',
  70. fontWeight: 'bold'
  71. },
  72. formatter: function (params,ticket,callback) {
  73. var res = 'Function formatter : <br/>' + params[0].name;
  74. for (var i = 0, l = params.length; i < l; i++) {
  75. res += '<br/>' + params[i].seriesName + ' : ' + params[i].value;
  76. }
  77. setTimeout(function (){
  78. // 仅为了模拟异步回调
  79. callback(ticket, res);
  80. }, 1000);
  81. return 'loading';
  82. }
  83. //formatter: "Template formatter: <br/>{b}<br/>{a}:{c}<br/>{a1}:{c1}"
  84. },
  85. toolbox: {
  86. show : true,
  87. feature : {
  88. mark : {show: true},
  89. dataView : {show: true, readOnly: false},
  90. magicType : {show: true, type: ['line', 'bar', 'stack', 'tiled']},
  91. restore : {show: true},
  92. saveAsImage : {show: true}
  93. }
  94. },
  95. calculable : true,
  96. xAxis : {
  97. data : ['周一','周二','周三','周四','周五','周六','周日']
  98. },
  99. yAxis : {
  100. type : 'value'
  101. },
  102. series : [
  103. {
  104. name:'坐标轴触发1',
  105. type:'bar',
  106. data:[
  107. {value:320, extra:'Hello~'},
  108. 332, 301, 334, 390, 330, 320
  109. ]
  110. },
  111. {
  112. name:'坐标轴触发2',
  113. type:'bar',
  114. data:[862, 1018, 964, 1026, 1679, 1600, 157]
  115. },
  116. {
  117. name:'数据项触发1',
  118. type:'bar',
  119. tooltip : { // Series config.
  120. trigger: 'item',
  121. backgroundColor: 'black',
  122. position : [0, 0],
  123. formatter: 'Series formatter: <br/>{a}<br/>{b}:{c}'
  124. },
  125. stack: '数据项',
  126. data:[
  127. 120, 132,
  128. {
  129. value: 301,
  130. itemStyle: {normal: {color: 'red'}},
  131. tooltip : { // Data config.
  132. backgroundColor: 'blue',
  133. formatter: 'Data formatter: <br/>{a}<br/>{b}:{c}'
  134. }
  135. },
  136. 134, 90,
  137. {
  138. value: 230,
  139. tooltip: {show: false}
  140. },
  141. 210
  142. ]
  143. },
  144. {
  145. name:'数据项触发2',
  146. type:'bar',
  147. tooltip : {
  148. show : false,
  149. trigger: 'item'
  150. },
  151. stack: '数据项',
  152. data:[150, 232, 201, 154, 190, 330, 410]
  153. }
  154. ]
  155. });
  156. });
  157. </script>
  158. </body>
  159. </html>