bar2.html 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  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. <link rel="stylesheet" href="lib/reset.css">
  11. </head>
  12. <body>
  13. <style>
  14. h1 {
  15. line-height: 60px;
  16. height: 60px;
  17. background: #146402;
  18. text-align: center;
  19. font-weight: bold;
  20. color: #eee;
  21. font-size: 14px;
  22. }
  23. .chart {
  24. height: 400px;
  25. }
  26. </style>
  27. <div class="chart" id="main1"></div>
  28. <h1>Narrow grid</h1>
  29. <div class="chart" id="main2"></div>
  30. <script>
  31. require([
  32. 'echarts'
  33. // 'echarts/chart/bar',
  34. // 'echarts/component/legend',
  35. // 'echarts/component/grid',
  36. // 'echarts/component/tooltip',
  37. // 'echarts/component/markLine'
  38. ], function (echarts) {
  39. var chart = echarts.init(document.getElementById('main1'), null, {
  40. });
  41. chart.setOption({
  42. tooltip : {
  43. trigger: 'axis',
  44. axisPointer : { // 坐标轴指示器,坐标轴触发有效
  45. type : 'shadow' // 默认为直线,可选为:'line' | 'shadow'
  46. }
  47. },
  48. legend: {
  49. data:['直接访问','邮件营销','联盟广告','视频广告','搜索引擎','百度','谷歌','必应','其他']
  50. },
  51. toolbox: {
  52. show : true,
  53. orient: 'vertical',
  54. left: 'right',
  55. top: 'center',
  56. feature : {
  57. mark : {show: true},
  58. dataView : {show: true, readOnly: false},
  59. magicType : {show: true, type: ['line', 'bar', 'stack', 'tiled']},
  60. restore : {show: true},
  61. saveAsImage : {show: true}
  62. }
  63. },
  64. calculable : true,
  65. xAxis : [
  66. {
  67. type : 'category',
  68. data : ['周一','周二','周三','周四','周五','周六','周日']
  69. }
  70. ],
  71. yAxis : [
  72. {
  73. type : 'value'
  74. }
  75. ],
  76. series : [
  77. {
  78. name:'直接访问',
  79. type:'bar',
  80. data:[320, 332, 301, 334, 390, 330, 320]
  81. },
  82. {
  83. name:'邮件营销',
  84. type:'bar',
  85. stack: '广告',
  86. data:[120, 132, 101, 134, 90, 230, 210]
  87. },
  88. {
  89. name:'联盟广告',
  90. type:'bar',
  91. stack: '广告',
  92. data:[220, 182, 191, 234, 290, 330, 310]
  93. },
  94. {
  95. name:'视频广告',
  96. type:'bar',
  97. stack: '广告',
  98. data:[150, 232, 201, 154, 190, 330, 410]
  99. },
  100. {
  101. name:'搜索引擎',
  102. type:'bar',
  103. data:[862, 1018, 964, 1026, 1679, 1600, 1570],
  104. markLine : {
  105. itemStyle:{
  106. normal:{
  107. label: {
  108. formatter: function (params) {
  109. console.log(params);
  110. }
  111. },
  112. lineStyle:{
  113. type: 'dashed'
  114. }
  115. }
  116. },
  117. data : [
  118. [{type : 'min'}, {type : 'max'}]
  119. ]
  120. }
  121. },
  122. {
  123. name:'百度',
  124. type:'bar',
  125. barWidth : 5,
  126. stack: '搜索引擎',
  127. data:[620, 732, 701, 734, 1090, 1130, 1120]
  128. },
  129. {
  130. name:'谷歌',
  131. type:'bar',
  132. stack: '搜索引擎',
  133. data:[120, 132, 101, 134, 290, 230, 220]
  134. },
  135. {
  136. name:'必应',
  137. type:'bar',
  138. stack: '搜索引擎',
  139. data:[60, 72, 71, 74, 190, 130, 110]
  140. },
  141. {
  142. name:'其他',
  143. type:'bar',
  144. stack: '搜索引擎',
  145. data:[62, 82, 91, 84, 109, 110, 120]
  146. }
  147. ]
  148. });
  149. });
  150. </script>
  151. <script>
  152. var echarts;
  153. var chart;
  154. var myChart;
  155. var groupCategories = [];
  156. var groupColors = [];
  157. require([
  158. 'echarts'
  159. // 'echarts/chart/line',
  160. // 'echarts/chart/bar',
  161. // 'echarts/chart/pie',
  162. // 'echarts/chart/scatter',
  163. // 'echarts/chart/map',
  164. // 'echarts/chart/parallel',
  165. // 'echarts/chart/radar',
  166. // 'echarts/component/grid',
  167. // 'echarts/component/polar',
  168. // 'echarts/component/geo',
  169. // 'echarts/component/singleAxis',
  170. // 'echarts/component/legend',
  171. // 'echarts/component/tooltip',
  172. // 'echarts/component/toolbox',
  173. // 'echarts/component/visualMap',
  174. // 'echarts/component/dataZoom'
  175. ], function (ec) {
  176. echarts = ec;
  177. option = {
  178. xAxis: {
  179. // data: ['a', 'b', 'c', 'd'],
  180. data: ['a', 'b'],
  181. axisTick: {show: false},
  182. axisLabel: {
  183. formatter: 'barGap: \'-100%\''
  184. }
  185. },
  186. yAxis: {
  187. splitLine: {show: false}
  188. },
  189. animationDurationUpdate: 1200,
  190. grid: {
  191. width: 100
  192. },
  193. animation: false,
  194. series: [{
  195. type: 'bar',
  196. itemStyle: {
  197. normal: {
  198. color: '#ddd'
  199. }
  200. },
  201. silent: true,
  202. barWidth: 40,
  203. barGap: '-100%', // Make series be overlap
  204. data: [60, 60]
  205. }, {
  206. type: 'bar',
  207. barWidth: 40,
  208. z: 10,
  209. data: [45, 55]
  210. }]
  211. };
  212. testHelper.createChart(echarts, 'main2', option);
  213. });
  214. </script>
  215. </body>
  216. </html>