bar.html 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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. 'zrender/vml/vml'
  30. ], function (echarts) {
  31. var chart = echarts.init(document.getElementById('main'));
  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. var itemStyle = {
  45. normal: {
  46. label: {
  47. show: true,
  48. position: 'outside'
  49. }
  50. },
  51. emphasis: {
  52. label: {
  53. position: 'outside'
  54. },
  55. barBorderWidth: 1,
  56. shadowBlur: 10,
  57. shadowOffsetX: 0,
  58. shadowOffsetY: 0,
  59. shadowColor: 'rgba(0,0,0,0.5)'
  60. }
  61. };
  62. chart.setOption({
  63. backgroundColor: '#eee',
  64. legend: {
  65. borderWidth: 1,
  66. data: [{
  67. name: 'bar'
  68. }, 'bar2', '\n', 'bar3', 'bar4'],
  69. selected: {
  70. // 'bar': false
  71. },
  72. // orient: 'vertical',
  73. // x: 'right',
  74. // y: 'bottom',
  75. align: 'left'
  76. },
  77. toolbox: {
  78. // y: 'bottom',
  79. feature: {
  80. magicType: {
  81. type: ['line', 'bar', 'stack', 'tiled']
  82. },
  83. dataView: {},
  84. saveAsImage: {
  85. pixelRatio: 2
  86. },
  87. myTool1: {
  88. show: true,
  89. title: '自定义扩展方法1',
  90. 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',
  91. onclick: function (){
  92. alert('myToolHandler1')
  93. }
  94. },
  95. myTool2: {
  96. show: true,
  97. title: '自定义扩展方法2',
  98. icon: 'image://http://echarts.baidu.com/images/favicon.png',
  99. onclick: function (){
  100. alert('myToolHandler2')
  101. }
  102. }
  103. }
  104. },
  105. tooltip: {},
  106. xAxis: {
  107. data: xAxisData,
  108. name: '横轴',
  109. silent: false,
  110. axisLine: {
  111. onZero: true
  112. },
  113. splitLine: {
  114. show: false
  115. },
  116. splitArea: {
  117. show: false
  118. }
  119. },
  120. yAxis: {
  121. inverse: true,
  122. splitArea: {
  123. show: false
  124. }
  125. },
  126. series: [{
  127. name: 'bar',
  128. type: 'bar',
  129. stack: 'one',
  130. itemStyle: itemStyle,
  131. data: data1
  132. }, {
  133. name: 'bar2',
  134. type: 'bar',
  135. stack: 'one',
  136. itemStyle: itemStyle,
  137. data: data2
  138. }, {
  139. name: 'bar3',
  140. type: 'bar',
  141. stack: 'two',
  142. itemStyle: itemStyle,
  143. data: data3
  144. }, {
  145. name: 'bar4',
  146. type: 'bar',
  147. stack: 'two',
  148. itemStyle: itemStyle,
  149. data: data4
  150. }]
  151. });
  152. chart.on('click', function (params) {
  153. console.log(params);
  154. });
  155. window.onresize = chart.resize;
  156. });
  157. </script>
  158. </body>
  159. </html>