bar.html 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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. background: #fff;
  17. }
  18. </style>
  19. <div id="main"></div>
  20. <script>
  21. require([
  22. 'echarts',
  23. 'echarts/chart/bar',
  24. 'echarts/chart/line',
  25. 'echarts/component/legend',
  26. 'echarts/component/grid',
  27. 'echarts/component/tooltip',
  28. 'echarts/component/toolbox',
  29. 'echarts/component/title',
  30. 'zrender/vml/vml'
  31. ], function (echarts) {
  32. var chart = echarts.init(document.getElementById('main'));
  33. var xAxisData = [];
  34. var data1 = [];
  35. var data2 = [];
  36. var data3 = [];
  37. var data4 = [];
  38. for (var i = 0; i < 10; i++) {
  39. xAxisData.push('类目' + i);
  40. data1.push((Math.random() * 5).toFixed(2));
  41. data2.push(-Math.random().toFixed(2));
  42. data3.push((Math.random() + 0.5).toFixed(2));
  43. data4.push((Math.random() + 0.3).toFixed(2));
  44. }
  45. var itemStyle = {
  46. normal: {
  47. barBorderRadius: 5,
  48. label: {
  49. show: true,
  50. position: 'outside'
  51. }
  52. },
  53. emphasis: {
  54. label: {
  55. position: 'outside'
  56. },
  57. barBorderColor: '#fff',
  58. barBorderWidth: 1,
  59. shadowBlur: 10,
  60. shadowOffsetX: 0,
  61. shadowOffsetY: 0,
  62. shadowColor: 'rgba(0,0,0,0.5)'
  63. }
  64. };
  65. chart.setOption({
  66. backgroundColor: '#eee',
  67. title: {
  68. text: '我是柱状图',
  69. padding: 20
  70. },
  71. legend: {
  72. inactiveColor: '#abc',
  73. borderWidth: 1,
  74. data: [{
  75. name: 'bar'
  76. }, 'bar2', '\n', 'bar3', 'bar4'],
  77. selected: {
  78. // 'bar': false
  79. },
  80. // orient: 'vertical',
  81. // x: 'right',
  82. // y: 'bottom',
  83. align: 'left',
  84. tooltip: {
  85. show: true
  86. }
  87. },
  88. toolbox: {
  89. top: 25,
  90. // right: 20,
  91. feature: {
  92. magicType: {
  93. type: ['line', 'bar', 'stack', 'tiled']
  94. },
  95. dataView: {},
  96. saveAsImage: {
  97. pixelRatio: 2
  98. },
  99. myTool1: {
  100. show: true,
  101. title: '自定义扩展方法1',
  102. icon: 'path://M432.45,595.444c0,2.177-4.661,6.82-11.305,6.82c-6.475,0-11.306-4.567-11.306-6.82s4.852-6.812,11.306-6.812C427.841,588.632,432.452,593.191,432.45,595.444L432.45,595.444z M421.155,589.876c-3.009,0-5.448,2.495-5.448,5.572s2.439,5.572,5.448,5.572c3.01,0,5.449-2.495,5.449-5.572C426.604,592.371,424.165,589.876,421.155,589.876L421.155,589.876z M421.146,591.891c-1.916,0-3.47,1.589-3.47,3.549c0,1.959,1.554,3.548,3.47,3.548s3.469-1.589,3.469-3.548C424.614,593.479,423.062,591.891,421.146,591.891L421.146,591.891zM421.146,591.891',
  103. onclick: function (){
  104. alert('myToolHandler1')
  105. }
  106. },
  107. myTool2: {
  108. show: true,
  109. title: '自定义扩展方法2',
  110. icon: 'image://http://echarts.baidu.com/images/favicon.png',
  111. onclick: function (){
  112. alert('myToolHandler2')
  113. }
  114. }
  115. },
  116. iconStyle: {
  117. emphasis: {
  118. textPosition: 'top'
  119. // textAlign: 'right'
  120. }
  121. }
  122. },
  123. tooltip: {},
  124. xAxis: {
  125. data: xAxisData,
  126. name: '横轴',
  127. silent: false,
  128. axisTick: {
  129. alignWithLabel: true
  130. },
  131. // axisLabel: {
  132. // show: false
  133. // },
  134. // axisTick: {
  135. // show: false
  136. // },
  137. axisLine: {
  138. onZero: true
  139. },
  140. splitLine: {
  141. show: true
  142. },
  143. splitArea: {
  144. show: true
  145. }
  146. },
  147. yAxis: {
  148. inverse: true,
  149. // axisLabel: {
  150. // show: false
  151. // },
  152. axisTick: {
  153. show: false
  154. },
  155. // splitLine: {
  156. // show: false
  157. // },
  158. splitArea: {
  159. show: false
  160. }
  161. },
  162. series: [{
  163. name: 'bar',
  164. type: 'bar',
  165. stack: 'one',
  166. itemStyle: itemStyle,
  167. data: data1
  168. }, {
  169. name: 'bar2',
  170. type: 'bar',
  171. stack: 'one',
  172. itemStyle: itemStyle,
  173. data: data2
  174. }, {
  175. name: 'bar3',
  176. type: 'bar',
  177. stack: 'two',
  178. itemStyle: itemStyle,
  179. data: data3
  180. }, {
  181. name: 'bar4',
  182. type: 'bar',
  183. stack: 'two',
  184. itemStyle: itemStyle,
  185. data: data4
  186. }]
  187. });
  188. chart.on('click', function (params) {
  189. console.log(params);
  190. });
  191. window.onresize = chart.resize;
  192. });
  193. </script>
  194. </body>
  195. </html>