box2.js 3.2 KB

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