bar-t.html 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. <html>
  2. <head>
  3. <meta charset="utf-8">
  4. <script src="lib/esl.js"></script>
  5. <script src="lib/config.js"></script>
  6. <script src="lib/jquery.min.js"></script>
  7. <script src="lib/facePrint.js"></script>
  8. <script src="lib/testHelper.js"></script>
  9. <meta name="viewport" content="width=device-width, initial-scale=1" />
  10. </head>
  11. <body>
  12. <style>
  13. h1 {
  14. line-height: 60px;
  15. height: 60px;
  16. background: #146402;
  17. text-align: center;
  18. font-weight: bold;
  19. color: #eee;
  20. font-size: 14px;
  21. }
  22. .chart {
  23. height: 600px;
  24. }
  25. </style>
  26. <div id="main" class="chart"></div>
  27. <script>
  28. require(
  29. (testHelper.hasURLParam('en')
  30. ? [
  31. 'echarts',
  32. // 'echarts/lang/en',
  33. ]
  34. : [
  35. 'echarts'
  36. ]
  37. ).concat(
  38. [
  39. // 'echarts/chart/bar',
  40. // 'echarts/chart/line',
  41. // 'echarts/component/legend',
  42. // 'echarts/component/graphic',
  43. // 'echarts/component/grid',
  44. // 'echarts/component/tooltip',
  45. // 'echarts/component/brush',
  46. // 'echarts/component/toolbox',
  47. // 'echarts/component/title',
  48. // 'zrender/vml/vml'
  49. ]
  50. ),
  51. function (echarts) {
  52. var chart = echarts.init(document.getElementById('main'));
  53. var xAxisData = [];
  54. var data1 = [];
  55. var data2 = [];
  56. var data3 = [];
  57. var data4 = [];
  58. for (var i = 0; i < 5; i++) {
  59. xAxisData.push('类目' + i);
  60. data1.push((Math.random() * 5).toFixed(2));
  61. data2.push(-Math.random().toFixed(2));
  62. data3.push((Math.random() + 0.5).toFixed(2));
  63. data4.push((Math.random() + 0.3).toFixed(2));
  64. }
  65. var itemStyle = {
  66. normal: {
  67. barBorderRadius: 5,
  68. label: {
  69. show: true,
  70. position: 'outside'
  71. }
  72. },
  73. emphasis: {
  74. label: {
  75. position: 'outside'
  76. },
  77. barBorderColor: '#fff',
  78. barBorderWidth: 1,
  79. shadowBlur: 10,
  80. shadowOffsetX: 0,
  81. shadowOffsetY: 0,
  82. shadowColor: 'rgba(0,0,0,0.5)'
  83. }
  84. };
  85. chart.setOption({
  86. backgroundColor: '#eee',
  87. animationDurationUpdate: 1000,
  88. legend: {
  89. left: 0,
  90. inactiveColor: '#abc',
  91. borderWidth: 1,
  92. itemWidth: 35,
  93. itemHeight: 30,
  94. data: [{
  95. name: 'bar'
  96. }, 'bar2', 'bar3', 'bar4'],
  97. selected: {
  98. // 'bar': false
  99. },
  100. // orient: 'vertical',
  101. // x: 'right',
  102. // y: 'bottom',
  103. align: 'left',
  104. tooltip: {
  105. show: true
  106. }
  107. },
  108. // brush: {
  109. // xAxisIndex: 0
  110. // },
  111. // // toolbox: {
  112. // // top: 25,
  113. // // // right: 20,
  114. // // feature: {
  115. // // magicType: {
  116. // // type: ['line', 'bar', 'stack', 'tiled']
  117. // // },
  118. // // dataView: {},
  119. // // saveAsImage: {
  120. // // pixelRatio: 2
  121. // // },
  122. // // brush: {
  123. // // type: ['rect', 'polygon', 'lineX', 'lineY', 'keep', 'clear']
  124. // // },
  125. // // restore: {},
  126. // // dataZoom: {},
  127. // // myTool1: {
  128. // // show: true,
  129. // // title: '自定义扩展方法1',
  130. // // 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',
  131. // // onclick: function (){
  132. // // alert('myToolHandler1')
  133. // // }
  134. // // },
  135. // // myTool2: {
  136. // // show: true,
  137. // // title: '自定义扩展方法2',
  138. // // icon: 'image://http://echarts.baidu.com/images/favicon.png',
  139. // // onclick: function (){
  140. // // alert('myToolHandler2')
  141. // // }
  142. // // }
  143. // // },
  144. // iconStyle: {
  145. // emphasis: {
  146. // textPosition: 'top'
  147. // // textAlign: 'right'
  148. // }
  149. // }
  150. // },
  151. tooltip: {},
  152. grid: {
  153. top: 50
  154. },
  155. xAxis: {
  156. data: xAxisData,
  157. name: '横轴',
  158. silent: false,
  159. axisTick: {
  160. alignWithLabel: true
  161. },
  162. // axisLabel: {
  163. // show: false
  164. // },
  165. // axisTick: {
  166. // show: false
  167. // },
  168. axisLine: {
  169. onZero: true
  170. },
  171. splitLine: {
  172. show: true
  173. },
  174. splitArea: {
  175. show: true
  176. }
  177. },
  178. yAxis: {
  179. inverse: true,
  180. // axisLabel: {
  181. // show: false
  182. // },
  183. axisTick: {
  184. show: false
  185. },
  186. // splitLine: {
  187. // show: false
  188. // },
  189. splitArea: {
  190. show: false
  191. }
  192. },
  193. series: [{
  194. name: 'bar',
  195. type: 'bar',
  196. stack: 'one',
  197. itemStyle: itemStyle,
  198. cursor: 'move',
  199. data: data1
  200. }, {
  201. name: 'bar2',
  202. type: 'bar',
  203. stack: 'one',
  204. itemStyle: itemStyle,
  205. cursor: 'default',
  206. data: data2
  207. // }, {
  208. // name: 'bar3',
  209. // type: 'bar',
  210. // stack: 'two',
  211. // itemStyle: itemStyle,
  212. // data: data3
  213. // }, {
  214. // name: 'bar4',
  215. // type: 'bar',
  216. // stack: 'two',
  217. // itemStyle: itemStyle,
  218. // data: data4
  219. }]
  220. });
  221. chart.on('click', function (params) {
  222. console.log(params);
  223. });
  224. // chart.on('legendselectchanged', function (params) {
  225. // chart.setOption({
  226. // // title: {
  227. // // },
  228. // graphic: [{
  229. // type: 'circle',
  230. // shape: {
  231. // cx: 100,
  232. // cy: 100,
  233. // r: 20,
  234. // }
  235. // }]
  236. // });
  237. // });
  238. window.onresize = chart.resize;
  239. }
  240. );
  241. </script>
  242. </body>
  243. </html>