totalLine.vue 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. <template>
  2. <div :id="id" style="height: 100%;width:100%;"></div>
  3. </template>
  4. <script>
  5. export default {
  6. data () {
  7. return {}
  8. },
  9. props:{
  10. id:{
  11. type: String
  12. }
  13. },
  14. mounted(){
  15. this.drawLine();
  16. },
  17. methods:{
  18. drawLine(){
  19. let _this = this
  20. // 基于准备好的dom,初始化echarts实例
  21. let myChart = this.$echarts.init(document.getElementById(this.id));
  22. let arrlabel = ["3/15", "3/16", "3/17", "3/18", "3/19", "3/20", "3/21", "3/22", "3/23", "3/24", "TODAY"];
  23. let arrTotal1 = ["22", "17", "0", "26", "22", "24", "18", "30", "15", "10", "30"];
  24. let arrTotal2 = ["26", "20", "2", "18", "27", "22", "26", "33", "9", "0", "40"];
  25. let arrTotal3 = ["40", "26", "8", "1", "34", "8", "54", "16", "16", "25", "20"];
  26. myChart.setOption({
  27. backgroundColor: 'rgba(17, 17, 17, 0.14)',
  28. tooltip: {
  29. trigger: 'axis',
  30. borderRadius: 0,
  31. // backgroundColor:'#7AD1A8',
  32. // formatter: function(pm) {
  33. // var param = pm[0];
  34. // var pht = '<span style="display:inline-block;margin-right:5px;width:10px;height:10px;background-color:rgba(166,154,228);"></span>';
  35. // console.log(param.marker);
  36. // var prm = "星期" + "日一二三四五六 ".charAt(new Date(param.name).getDay());
  37. // return param.name + ":&nbsp;&nbsp;" + prm + "<br>" +
  38. // pht + param.seriesName + ":&nbsp;&nbsp;" + param.value + "&nbsp;&nbsp;|&nbsp;&nbsp;80.33ttt%";
  39. // },
  40. // axisPointer: { // 坐标轴指示器,坐标轴触发有效
  41. // type: 'none' // 默认为直线,可选为:'line' | 'shadow'
  42. // },
  43. },
  44. grid: {
  45. left: '0',
  46. right: '0',
  47. bottom: '5%',
  48. top: '0',
  49. containLabel: true,
  50. },
  51. xAxis: [{
  52. axisTick: {
  53. show: false,
  54. },
  55. type: 'category',
  56. axisLabel: {
  57. margin: 10,
  58. textStyle: {
  59. fontSize: 11,
  60. color: '#94998a'
  61. },
  62. interval:0,
  63. formatter:function(val){
  64. let firstOne = arrlabel[0];
  65. let labellength = arrlabel.length
  66. let lastOne = arrlabel[labellength-1];
  67. if(firstOne != val && lastOne != val){
  68. return val
  69. }
  70. }
  71. },
  72. boundaryGap: false,
  73. splitLine: {
  74. lineStyle: {
  75. color: 'rgba(185, 193, 173, 0.63)',
  76. },
  77. show: true
  78. },
  79. axisLine: {
  80. lineStyle: {
  81. color: 'rgba(185, 193, 173, 0.63)',
  82. width: 1,
  83. }
  84. },
  85. data: arrlabel
  86. }],
  87. yAxis: [{
  88. position: 'right',
  89. type: 'value',
  90. // name: '单 位(%)',
  91. axisTick: {
  92. show: false
  93. },
  94. axisLine: {
  95. show: true,
  96. lineStyle: {
  97. color: 'rgba(185, 193, 173, 0.63)',
  98. }
  99. },
  100. axisLabel: {
  101. margin: 10,
  102. inside: true,
  103. textStyle: {
  104. fontSize: 14,
  105. color:'transparent'
  106. }
  107. },
  108. splitLine: {
  109. show: true,
  110. lineStyle: {
  111. color: 'rgba(185, 193, 173, 0.63)',
  112. }
  113. }
  114. }],
  115. series: [{
  116. // name: '实名率',
  117. type: 'line',
  118. // symbol: 'circle',
  119. //symbolSize: 5,
  120. // showSymbol: false,
  121. // markPoint: { // markLine 也是同理
  122. // data: [{
  123. // coord: [0,1,2,3,4], // 其中 5 表示 xAxis.data[5],即 '33' 这个元素。
  124. // // coord: ['5', 33.4] // 其中 '5' 表示 xAxis.data中的 '5' 这个元素。
  125. // // 注意,使用这种方式时,xAxis.data 不能写成 [number, number, ...]
  126. // // 而只能写成 [string, string, ...]
  127. // }]
  128. // },
  129. lineStyle: {
  130. normal: {
  131. width: 2
  132. }
  133. },
  134. areaStyle: {
  135. normal: {
  136. // 渐变色
  137. color: new this.$echarts.graphic.LinearGradient(0, 0, 0, 1, [{
  138. offset: 0,
  139. color: "rgba(28, 208, 161, 1)" // 0% 处的颜色
  140. },{
  141. offset: 1,
  142. color: "rgba(28, 208, 161, 0.5)" // 100% 处的颜色
  143. }], false)
  144. },
  145. },
  146. itemStyle: {
  147. normal: {
  148. areaStyle: {
  149. type: 'default'
  150. },
  151. color: '#1CD0A1',
  152. },
  153. emphasis: {
  154. // color: 'rgb(0,196,132)',
  155. borderColor: 'rgba(0,196,132,0.2)',
  156. extraCssText: 'box-shadow: 8px 8px 8px rgba(0, 0, 0, 1);',
  157. // borderWidth: 10
  158. }
  159. },
  160. data: arrTotal1
  161. },
  162. {
  163. type: 'line',
  164. lineStyle: {
  165. normal: {
  166. width: 2
  167. }
  168. },
  169. areaStyle: {
  170. normal: {
  171. // 渐变色
  172. color: new this.$echarts.graphic.LinearGradient(0, 0, 0, 1, [{
  173. offset: 0,
  174. color: "rgba(255, 107, 106, 1)" // 0% 处的颜色
  175. },{
  176. offset: 1,
  177. color: "rgba(255, 107, 106, 0.5)" // 100% 处的颜色
  178. }], false)
  179. },
  180. },
  181. itemStyle: {
  182. normal: {
  183. areaStyle: {
  184. type: 'default'
  185. },
  186. color: '#FF6B6A',
  187. },
  188. emphasis: {
  189. // color: 'rgb(0,196,132)',
  190. borderColor: 'rgba(0,196,132,0.2)',
  191. extraCssText: 'box-shadow: 8px 8px 8px rgba(0, 0, 0, 1);',
  192. // borderWidth: 10
  193. }
  194. },
  195. data: arrTotal2
  196. },
  197. {
  198. type: 'line',
  199. lineStyle: {
  200. normal: {
  201. width: 2
  202. }
  203. },
  204. areaStyle: {
  205. normal: {
  206. // 渐变色
  207. color: new this.$echarts.graphic.LinearGradient(0, 0, 0, 1, [{
  208. offset: 0,
  209. color: "rgba(72, 219, 252, 1)" // 0% 处的颜色
  210. },{
  211. offset: 1,
  212. color: "rgba(72, 219, 252, 0.5)" // 100% 处的颜色
  213. }], false)
  214. },
  215. },
  216. itemStyle: {
  217. normal: {
  218. areaStyle: {
  219. type: 'default'
  220. },
  221. color: '#48DBFC',
  222. },
  223. emphasis: {
  224. // color: 'rgb(0,196,132)',
  225. borderColor: 'rgba(0,196,132,0.2)',
  226. extraCssText: 'box-shadow: 8px 8px 8px rgba(0, 0, 0, 1);',
  227. // borderWidth: 10
  228. }
  229. },
  230. data: arrTotal3
  231. }
  232. ]
  233. });
  234. }
  235. }
  236. }
  237. </script>
  238. <style>
  239. </style>