doubleLineChart2.vue 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  1. <template>
  2. <view class="content">
  3. <!-- #ifdef APP-PLUS || H5 -->
  4. <view class="top-Section">
  5. <view class="title">{{title}}</view>
  6. <view class="top-Section-right">
  7. <view class="right-item">
  8. <view class="right-item-point" :style="`background-color: ${fuzhuColor};`"></view>
  9. <view class="right-item-title">认购</view>
  10. </view>
  11. <view class="right-item">
  12. <view class="right-item-point" :style="`background-color: ${themeColor};`"></view>
  13. <view class="right-item-title">签约</view>
  14. </view>
  15. </view>
  16. </view>
  17. <view class="top-Section-right">
  18. <!-- <view class="right-item">
  19. <view class="right-item-point" :style="`background-color: ${fuzhuColor};`"></view>
  20. <view class="right-item-title">认购</view>
  21. </view>
  22. <view class="right-item">
  23. <view class="right-item-point" :style="`background-color: ${themeColor};`"></view>
  24. <view class="right-item-title">签约</view>
  25. </view> -->
  26. </view>
  27. <view v-if="themeColor!=null" @click="echarts.onClick" :prop="option" :change:prop="echarts.updateEcharts" ref="chartId"
  28. :id="chartId" class="echarts"></view>
  29. <!-- #endif -->
  30. </view>
  31. </template>
  32. <script>
  33. import echarts from '../../static/echarts.js'
  34. export default {
  35. props: {
  36. themeColor: String,
  37. fuzhuColor: String,
  38. themeColor50: String,
  39. themeColor25: String,
  40. fuzhuColor50: String,
  41. chartId: String,
  42. title: String,
  43. dataList: Array,
  44. data1: Array,
  45. data2: Array,
  46. },
  47. data() {
  48. return {
  49. option: {
  50. tooltip: {
  51. trigger: 'axis',
  52. axisPointer: {
  53. type: 'line',
  54. lineStyle: {
  55. color: '#F1F5F9',
  56. // color: '#3CD9D9',
  57. type: 'dotted',
  58. width: 2
  59. },
  60. label: {
  61. backgroundColor: '#6a7985'
  62. },
  63. },
  64. extraCssText: 'z-index:50'
  65. },
  66. grid: {
  67. left: '2%',
  68. right: '5%',
  69. bottom: 0,
  70. top: '10%',
  71. padding: 0,
  72. containLabel: true,
  73. },
  74. xAxis: {
  75. type: 'category',
  76. boundaryGap: false,
  77. data: [],
  78. axisLabel: { //坐标轴刻度标签的相关设置。
  79. margin: 10,
  80. textStyle: {
  81. color: '#616F88',
  82. fontFamily: 'Verdana',
  83. fontSize: 10,
  84. opacity: 0.5
  85. },
  86. },
  87. axisTick: { //坐标轴刻度相关设置。
  88. show: false,
  89. },
  90. axisLine: { //坐标轴轴线相关设置
  91. show: false,
  92. lineStyle: {
  93. color: '',
  94. opacity: 1
  95. }
  96. },
  97. },
  98. yAxis: {
  99. // show: false,
  100. type: 'value',
  101. splitNumber: 4,
  102. boundaryGap: false,
  103. axisTick: {
  104. show: false
  105. },
  106. axisLine: { //坐标轴轴线相关设置
  107. // show: false
  108. lineStyle: {
  109. color: '#707070',
  110. opacity: 0
  111. }
  112. },
  113. minInterval: 1,
  114. splitLine: {
  115. show: false
  116. }
  117. },
  118. series: [{
  119. name: '认购',
  120. type: 'line',
  121. // stack: '总量',
  122. symbol: 'circle',
  123. symbolSize: 6,
  124. itemStyle: {
  125. opacity: 0,
  126. normal: {
  127. borderRadius: 3,
  128. color: this.fuzhuColor,
  129. borderWidth: 2,
  130. borderColor: '#FFF'
  131. },
  132. },
  133. areaStyle: {
  134. color: ''
  135. },
  136. smooth: true,
  137. lineStyle: {
  138. color: ''
  139. },
  140. data: []
  141. },
  142. {
  143. name: '签约',
  144. type: 'line',
  145. // stack: '总量',
  146. symbol: 'circle',
  147. symbolSize: 6,
  148. itemStyle: {
  149. opacity: 0,
  150. normal: {
  151. borderRadius: 3,
  152. color: '',
  153. borderWidth: 2,
  154. borderColor: '#FFF'
  155. },
  156. },
  157. areaStyle: {
  158. // color: '#56CBCB'
  159. color: ''
  160. },
  161. smooth: true,
  162. lineStyle: {
  163. // color: '#fff',
  164. // type: 'dotted'
  165. },
  166. data: [],
  167. }
  168. ]
  169. },
  170. isCompare: false
  171. }
  172. },
  173. methods: {
  174. getDataAction() {
  175. this.option.series[1].data = this.data1 || []
  176. this.option.series[0].data = this.data2 || []
  177. this.option.xAxis.data = this.dataList || []
  178. if (this.data2.length == 1) {
  179. this.option.xAxis.axisLine.show = true
  180. this.option.xAxis.axisLine.lineStyle.color = this.themeColor50
  181. }
  182. else {
  183. this.option.xAxis.axisLine.show = false
  184. }
  185. },
  186. onViewClick(options) {
  187. // console.log(options)
  188. },
  189. reloadColor() {
  190. // console.log('what???:', this.option.series)
  191. this.option.series[1].areaStyle.color = new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
  192. offset: 0,
  193. color: this.themeColor
  194. }, {
  195. offset: 1,
  196. color: this.themeColor25
  197. }])
  198. this.option.series[0].areaStyle.color = new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
  199. offset: 0,
  200. color: this.fuzhuColor50
  201. }, {
  202. offset: 1,
  203. color: '#ffffff'
  204. }])
  205. this.option.tooltip.axisPointer.lineStyle.color = this.themeColor
  206. this.option.series[0].lineStyle.color = this.fuzhuColor
  207. this.option.series[1].itemStyle.normal.color = this.themeColor
  208. this.option.series[0].itemStyle.normal.color = this.fuzhuColor
  209. this.option.xAxis.axisLine.lineStyle.color = this.themeColor50
  210. }
  211. },
  212. watch: {
  213. chartId: {
  214. handler(e) {
  215. // // console.log('走没走!!!!', e)
  216. this.getDataAction()
  217. },
  218. immediate: true
  219. },
  220. themeColor: {
  221. handler(e) {
  222. // console.log('走没走!!!!', e)
  223. this.reloadColor()
  224. },
  225. immediate: true
  226. },
  227. data2: {
  228. handler(e) {
  229. this.getDataAction()
  230. },
  231. immediate: true
  232. }
  233. }
  234. }
  235. </script>
  236. <script module="echarts" lang="renderjs">
  237. let myChart
  238. export default {
  239. mounted() {
  240. this.initAction()
  241. },
  242. methods: {
  243. initAction() {
  244. if (typeof window.echarts === 'function') {
  245. this.initEcharts()
  246. } else {
  247. // 动态引入较大类库避免影响页面展示
  248. const script = document.createElement('script')
  249. // view 层的页面运行在 www 根目录,其相对路径相对于 www 计算
  250. script.src = 'static/echarts.js'
  251. script.onload = this.initEcharts.bind(this)
  252. document.head.appendChild(script)
  253. }
  254. },
  255. initEcharts() {
  256. // console.log("initEcharts -> this.$refs", this.$refs.chartId.$el.id)
  257. myChart = echarts.init(document.getElementById(this.$refs.chartId.$el.id))
  258. // 观测更新的数据在 view 层可以直接访问到
  259. if (myChart) {
  260. myChart.clear()
  261. myChart.setOption(this.option)
  262. }
  263. },
  264. updateEcharts(newValue, oldValue, ownerInstance, instance) {
  265. // 监听 service 层数据变更
  266. if (myChart) {
  267. myChart.clear()
  268. myChart.setOption(newValue)
  269. }
  270. },
  271. onClick(event, ownerInstance) {
  272. // 调用 service 层的方法
  273. ownerInstance.callMethod('onViewClick', {
  274. test: 'test'
  275. })
  276. }
  277. }
  278. }
  279. </script>
  280. <style scoped lang="scss">
  281. .content {
  282. width: 100%;
  283. height: 100%;
  284. // background-color: #FFFFFF;
  285. overflow: hidden;
  286. margin-bottom: 80rpx;
  287. .top-Section {
  288. padding: 0 20rpx;
  289. display: flex;
  290. flex-direction: row;
  291. justify-content: space-between;
  292. font-family: Verdana;
  293. align-items: center;
  294. margin-bottom: 10rpx;
  295. .title {
  296. font-size: 32rpx;
  297. font-weight: bold;
  298. color: #383838;
  299. }
  300. }
  301. .top-Section-right {
  302. display: flex;
  303. align-items: center;
  304. .right-item {
  305. display: flex;
  306. align-items: center;
  307. margin-left: 30rpx;
  308. .right-item-point {
  309. width: 20rpx;
  310. height: 20rpx;
  311. border-radius: 50%;
  312. }
  313. .right-item-title {
  314. margin-left: 10rpx;
  315. font-size: 24rpx;
  316. font-family: Verdana, Verdana-Regular;
  317. font-weight: 400;
  318. text-align: right;
  319. color: #546074;
  320. }
  321. }
  322. }
  323. .echarts {
  324. width: 100%;
  325. margin-top: 0;
  326. height: 350rpx;
  327. }
  328. }
  329. </style>