box2.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. var dom = document.getElementById("box2");
  2. var myChart = echarts.init(dom);
  3. var app = {};
  4. option = null;
  5. var posList = [
  6. 'left', 'right', 'top', 'bottom',
  7. 'inside',
  8. 'insideTop', 'insideLeft', 'insideRight', 'insideBottom',
  9. 'insideTopLeft', 'insideTopRight', 'insideBottomLeft', 'insideBottomRight'
  10. ];
  11. app.configParameters = {
  12. rotate: {
  13. min: -90,
  14. max: 90
  15. },
  16. align: {
  17. options: {
  18. left: 'left',
  19. center: 'center',
  20. right: 'right'
  21. }
  22. },
  23. verticalAlign: {
  24. options: {
  25. top: 'top',
  26. middle: 'middle',
  27. bottom: 'bottom'
  28. }
  29. },
  30. position: {
  31. options: echarts.util.reduce(posList, function (map, pos) {
  32. map[pos] = pos;
  33. return map;
  34. }, {})
  35. },
  36. distance: {
  37. min: 0,
  38. max: 100
  39. }
  40. };
  41. app.config = {
  42. rotate: 90,
  43. align: 'left',
  44. verticalAlign: 'middle',
  45. position: 'insideBottom',
  46. distance: 15,
  47. onChange: function () {
  48. var labelOption = {
  49. normal: {
  50. rotate: app.config.rotate,
  51. align: app.config.align,
  52. verticalAlign: app.config.verticalAlign,
  53. position: app.config.position,
  54. distance: app.config.distance
  55. }
  56. };
  57. }
  58. };
  59. var labelOption = {
  60. normal: {
  61. show: true,
  62. position: app.config.position,
  63. distance: app.config.distance,
  64. align: app.config.align,
  65. verticalAlign: app.config.verticalAlign,
  66. rotate: app.config.rotate,
  67. formatter: '{c} {name|{a}}',
  68. fontSize: 10,
  69. rich: {
  70. name: {
  71. textBorderColor: '#fff'
  72. }
  73. }
  74. }
  75. };
  76. option = {
  77. color: ['#00fff6', '#006699', '#4cabce', '#e5323e'],
  78. tooltip: {
  79. trigger: 'axis',
  80. axisPointer: {
  81. type: 'shadow'
  82. }
  83. },
  84. legend: {
  85. textStyle:{//图例文字的样式
  86. color:'#dbdbdb',
  87. fontSize:10
  88. },
  89. data: ['Forest', 'Steppe', 'Desert', 'Wetland']
  90. },
  91. textStyle:{//图例文字的样式
  92. color:'#dbdbdb',
  93. fontSize:10
  94. },
  95. calculable: true,
  96. xAxis: [
  97. {
  98. type: 'category',
  99. axisTick: {show: false},
  100. data: ['2014', '2015', '2016', '2017', '2018']
  101. }
  102. ],
  103. yAxis: [
  104. {
  105. type: 'value'
  106. }
  107. ],
  108. series: [
  109. {
  110. name: 'Forest',
  111. type: 'bar',
  112. barGap: 0,
  113. label: labelOption,
  114. data: [320, 332, 301, 334, 390]
  115. },
  116. {
  117. name: 'Steppe',
  118. type: 'bar',
  119. label: labelOption,
  120. data: [220, 182, 191, 234, 290]
  121. },
  122. {
  123. name: 'Desert',
  124. type: 'bar',
  125. label: labelOption,
  126. data: [150, 232, 201, 154, 190]
  127. },
  128. {
  129. name: 'Wetland',
  130. type: 'bar',
  131. label: labelOption,
  132. data: [98, 77, 101, 99, 40]
  133. }
  134. ]
  135. };;
  136. if (option && typeof option === "object") {
  137. myChart.setOption(option, true);
  138. }