ThreeStackedBarAndLine.vue 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. <template>
  2. <div id="ThreeStackedBarAndLine" ref="ThreeStackedBarAndLine"></div>
  3. </template>
  4. <script>
  5. //这里可以导入其他文件(比如:组件,工具js,第三方插件js,json文件,图片文件等等)
  6. export default {
  7. components: {},
  8. data() {
  9. return {};
  10. },
  11. //监听属性 类似于data概念
  12. computed: {},
  13. //监控data中的数据变化
  14. watch: {},
  15. //方法集合
  16. methods: {
  17. init_echart(legendData, xdata, result) {
  18. const _this = this;
  19. _this.chart = echarts.init(this.$refs.ThreeStackedBarAndLine);
  20. let y1Data = [110, 90, 120, 70, 60]
  21. let option = {
  22. backgroundColor: 'rgba(0, 0, 0, 0)',
  23. // tooltip: {
  24. // trigger: 'axis',
  25. // extraCssText: 'box-shadow: 0 0 8px rgba(0, 0, 0, 0.3);',
  26. // backgroundColor: '#3A4667', // 背景
  27. // borderColor: '#3A4667',
  28. // textStyle: {
  29. // color: '#fff'
  30. // },
  31. // },
  32. tooltip: {
  33. backgroundColor: 'RGBA(20, 106, 178, 0.4)',
  34. trigger: "axis",
  35. textStyle: { fontSize: '100%' },
  36. formatter: params => {
  37. let rander = params.map(item =>
  38. `
  39. <div style='
  40. border:none;
  41. border-radius:3px;
  42. color:#FFF;
  43. font-size:12px
  44. '>
  45. ${item.seriesName}: ${item.value}
  46. </div>`).join('')
  47. return rander
  48. }
  49. },
  50. grid: {
  51. top: '20%',
  52. left: '3%',
  53. right: '3%',
  54. bottom: '5%',
  55. containLabel: true,
  56. },
  57. color: ['#efc943', '#4ee1ac', '#186bb8'],
  58. legend: {
  59. data: ['临时用地面积', '正常使用', '剩余1个月', '已到期',],
  60. top: '1%',
  61. // textStyle: {
  62. // color: "#666666"
  63. // },
  64. textStyle: {
  65. fontSize: 12,
  66. color: '#fff',
  67. padding: [0, 0, 0, 0],
  68. rich: {
  69. a: {
  70. verticalAlign: 'middle',
  71. },
  72. },
  73. },
  74. itemWidth: 15,
  75. itemHeight: 10,
  76. itemGap: 10
  77. },
  78. xAxis: [{
  79. type: 'category',
  80. data: ['崖州区', '育才区', '天涯区', '吉阳区', '海棠区'],
  81. axisLabel: {
  82. show: true,
  83. fontSize: 12,
  84. color: '#fff',
  85. align: 'center',
  86. verticalAlign: 'top',
  87. },
  88. axisLine: {
  89. show: true,
  90. lineStyle: {
  91. width: 1,
  92. color: 'rgba(239, 247, 253, .7)'
  93. }
  94. },
  95. axisTick: {
  96. show: false,
  97. },
  98. }
  99. ],
  100. yAxis: [{
  101. name: '',
  102. nameTextStyle: {
  103. color: "#fff",
  104. fontSize: 12,
  105. padding: [0, 0, 4, 0], //name文字位置 对应 上右下左
  106. },
  107. axisLabel: {
  108. interval: 0,
  109. show: true,
  110. fontSize: 10,
  111. color: '#fff',
  112. },
  113. axisLine: {
  114. show: false,
  115. },
  116. axisTick: {
  117. show: false,
  118. },
  119. splitLine: {
  120. show: false,
  121. lineStyle: {
  122. color: 'rgba(239, 247, 253, .1)'
  123. }
  124. },
  125. }, {
  126. name: '',
  127. nameTextStyle: {
  128. color: "#fff",
  129. fontSize: 12,
  130. padding: [0, 0, 4, 0], //name文字位置 对应 上右下左
  131. },
  132. axisLabel: {
  133. interval: 0,
  134. show: true,
  135. fontSize: 10,
  136. color: '#fff',
  137. },
  138. axisLine: {
  139. show: false,
  140. },
  141. axisTick: {
  142. show: false,
  143. },
  144. splitLine: {
  145. show: false,
  146. lineStyle: {
  147. color: 'rgba(239, 247, 253, .1)'
  148. }
  149. },
  150. }],
  151. series: [
  152. {
  153. name: "临时用地面积",
  154. type: 'line',
  155. smooth: true,
  156. itemStyle: {
  157. normal: {
  158. color: '#FFCC64' // 折线的颜色
  159. }
  160. },
  161. yAxisIndex: 1, // 指定使用第二个Y轴
  162. data: y1Data,
  163. }
  164. , {
  165. name: '剩余1个月',
  166. type: 'bar',
  167. stack: '渠道1',
  168. barWidth: 14,
  169. data: [12, 12, 12, 12, 1, 2],
  170. },
  171. {
  172. name: '已到期',
  173. type: 'bar',
  174. stack: '渠道1',
  175. barWidth: 14,
  176. data: [24, 12, 12, 0, 1, 2],
  177. },
  178. {
  179. name: '正常使用',
  180. barWidth: 14,
  181. type: 'bar',
  182. barWidth: 8,
  183. stack: '渠道1',
  184. data: [12, 0, 0, 24, 21],
  185. },
  186. ],
  187. }
  188. this.chart.setOption(option);
  189. },
  190. setOptions(legendData, xdata, result) {
  191. this.init_echart(legendData, xdata, result);
  192. }
  193. },
  194. beforeCreate() { }, //生命周期 - 创建之前
  195. created() { }, //生命周期 - 创建完成(可以访问当前this实例)
  196. beforeMount() { }, //生命周期 - 挂载之前
  197. mounted() {
  198. const that = this;
  199. this.$nextTick((res) => {
  200. this.init_echart();
  201. })
  202. }, //生命周期 - 挂在完成
  203. beforeUpdate() { }, //生命周期 - 更新之前
  204. updated() { }, //生命周期 - 更新之后
  205. beforeDestroy() { }, //生命周期 - 销毁之前
  206. destroy() { },//生命周期 - 销毁完成
  207. activated() { }, //若组件实例是 <KeepAlive> 缓存树的一部分,当组件被插入到 DOM 中时调用。
  208. deactivated() { } //若组件实例是 <KeepAlive> 缓存树的一部分,当组件从 DOM 中被移除时调用。
  209. };
  210. </script>
  211. <style scoped>
  212. #ThreeStackedBarAndLine {
  213. left: 0rem;
  214. top: 0.1rem;
  215. width: 21rem;
  216. height: 12rem;
  217. }
  218. </style>