selectedMode.html 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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. width: 1000px;
  17. background: #fff;
  18. }
  19. </style>
  20. <div id="main"></div>
  21. <script>
  22. require([
  23. 'echarts',
  24. 'echarts/chart/bar',
  25. 'echarts/component/legend',
  26. 'echarts/component/grid',
  27. 'echarts/component/tooltip'
  28. ], function (echarts) {
  29. var chart = echarts.init(document.getElementById('main'), null, {
  30. renderer: 'canvas'
  31. });
  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. shadowBlur: 10,
  53. shadowOffsetX: 0,
  54. shadowOffsetY: 0,
  55. shadowColor: 'rgba(0,0,0,0.5)'
  56. }
  57. };
  58. console.profile('setOption');
  59. chart.setOption({
  60. legend: {
  61. data: [{
  62. name: 'bar'
  63. }, 'bar2', 'bar3', 'bar4'],
  64. selected: {
  65. // 'bar': false
  66. },
  67. selectedMode: 'single',
  68. orient: 'vertical',
  69. left: 'right',
  70. top: 'bottom',
  71. align: 'right'
  72. },
  73. tooltip: {},
  74. xAxis: {
  75. data: xAxisData,
  76. axisLine: {
  77. onZero: true
  78. },
  79. splitLine: {
  80. show: false
  81. },
  82. splitArea: {
  83. show: false
  84. }
  85. },
  86. yAxis: {
  87. inverse: true,
  88. splitArea: {
  89. show: false
  90. }
  91. },
  92. series: [{
  93. name: 'bar',
  94. type: 'bar',
  95. stack: 'one',
  96. itemStyle: itemStyle,
  97. data: data1
  98. }, {
  99. name: 'bar2',
  100. type: 'bar',
  101. stack: 'one',
  102. itemStyle: itemStyle,
  103. data: data2
  104. }, {
  105. name: 'bar3',
  106. type: 'bar',
  107. stack: 'two',
  108. itemStyle: itemStyle,
  109. data: data3
  110. }, {
  111. name: 'bar4',
  112. type: 'bar',
  113. stack: 'two',
  114. itemStyle: itemStyle,
  115. data: data4
  116. }]
  117. });
  118. console.profileEnd('setOption');
  119. })
  120. </script>
  121. </body>
  122. </html>