bar-large.html 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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/title',
  29. 'echarts/component/toolbox'
  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 < 100; 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. chart.setOption({
  45. legend: {
  46. data: ['bar', 'bar2', 'bar3', 'bar4'],
  47. align: 'left'
  48. },
  49. toolbox: {
  50. // y: 'bottom',
  51. feature: {
  52. magicType: {
  53. type: ['line', 'bar', 'stack', 'tiled']
  54. },
  55. dataView: {},
  56. saveAsImage: {
  57. pixelRatio: 2
  58. }
  59. }
  60. },
  61. tooltip: {},
  62. xAxis: {
  63. data: xAxisData,
  64. silent: false,
  65. splitLine: {
  66. show: false
  67. },
  68. splitArea: {
  69. show: false
  70. }
  71. },
  72. yAxis: {
  73. splitArea: {
  74. show: false
  75. }
  76. },
  77. series: [{
  78. name: 'bar',
  79. type: 'bar',
  80. stack: 'one',
  81. data: data1
  82. }, {
  83. show: false,
  84. name: 'bar2',
  85. type: 'bar',
  86. stack: 'one',
  87. data: data2
  88. }, {
  89. name: 'bar3',
  90. type: 'bar',
  91. stack: 'two',
  92. data: data3
  93. }, {
  94. name: 'bar4',
  95. type: 'bar',
  96. stack: 'two',
  97. data: data4,
  98. silent: true
  99. }],
  100. animationDelay: function (idx) {
  101. return idx * 5;
  102. },
  103. animationDelayUpdate: function (idx) {
  104. return idx * 5;
  105. }
  106. });
  107. chart.on('click', function (params) {
  108. console.log(params);
  109. });
  110. window.onresize = chart.resize;
  111. });
  112. </script>
  113. </body>
  114. </html>