bar.html 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  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 < 10; 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. title: {
  88. text: '我是柱状图',
  89. padding: 20
  90. },
  91. legend: {
  92. left: 150,
  93. inactiveColor: '#abc',
  94. borderWidth: 1,
  95. data: [{
  96. name: 'bar'
  97. }, 'bar2', '\n', 'bar3', 'bar4'],
  98. selected: {
  99. // 'bar': false
  100. },
  101. // orient: 'vertical',
  102. // x: 'right',
  103. // y: 'bottom',
  104. align: 'left',
  105. tooltip: {
  106. show: true
  107. }
  108. },
  109. brush: {
  110. xAxisIndex: 0
  111. },
  112. toolbox: {
  113. top: 25,
  114. // right: 20,
  115. feature: {
  116. magicType: {
  117. type: ['line', 'bar', 'stack', 'tiled']
  118. },
  119. dataView: {},
  120. saveAsImage: {
  121. pixelRatio: 2
  122. },
  123. brush: {
  124. type: ['rect', 'polygon', 'lineX', 'lineY', 'keep', 'clear']
  125. },
  126. restore: {},
  127. dataZoom: {},
  128. myTool1: {
  129. show: true,
  130. title: '自定义扩展方法1',
  131. 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',
  132. onclick: function (){
  133. alert('myToolHandler1')
  134. }
  135. },
  136. myTool2: {
  137. show: true,
  138. title: '自定义扩展方法2',
  139. icon: 'image://http://echarts.baidu.com/images/favicon.png',
  140. onclick: function (){
  141. alert('myToolHandler2')
  142. }
  143. }
  144. },
  145. iconStyle: {
  146. emphasis: {
  147. textPosition: 'top'
  148. // textAlign: 'right'
  149. }
  150. }
  151. },
  152. tooltip: {},
  153. xAxis: {
  154. data: xAxisData,
  155. name: '横轴',
  156. silent: false,
  157. axisTick: {
  158. alignWithLabel: true
  159. },
  160. // axisLabel: {
  161. // show: false
  162. // },
  163. // axisTick: {
  164. // show: false
  165. // },
  166. axisLine: {
  167. onZero: true
  168. },
  169. splitLine: {
  170. show: true
  171. },
  172. splitArea: {
  173. show: true
  174. }
  175. },
  176. yAxis: {
  177. inverse: true,
  178. // axisLabel: {
  179. // show: false
  180. // },
  181. axisTick: {
  182. show: false
  183. },
  184. // splitLine: {
  185. // show: false
  186. // },
  187. splitArea: {
  188. show: false
  189. }
  190. },
  191. series: [{
  192. name: 'bar',
  193. type: 'bar',
  194. stack: 'one',
  195. itemStyle: itemStyle,
  196. cursor: 'move',
  197. data: data1
  198. }, {
  199. name: 'bar2',
  200. type: 'bar',
  201. stack: 'one',
  202. itemStyle: itemStyle,
  203. cursor: 'default',
  204. data: data2
  205. }, {
  206. name: 'bar3',
  207. type: 'bar',
  208. stack: 'two',
  209. itemStyle: itemStyle,
  210. data: data3
  211. }, {
  212. name: 'bar4',
  213. type: 'bar',
  214. stack: 'two',
  215. itemStyle: itemStyle,
  216. data: data4
  217. }]
  218. });
  219. chart.on('click', function (params) {
  220. console.log(params);
  221. });
  222. chart.on('legendselectchanged', function (params) {
  223. chart.setOption({
  224. // title: {
  225. // },
  226. graphic: [{
  227. type: 'circle',
  228. shape: {
  229. cx: 100,
  230. cy: 100,
  231. r: 20,
  232. }
  233. }]
  234. });
  235. });
  236. window.onresize = chart.resize;
  237. }
  238. );
  239. </script>
  240. </body>
  241. </html>