custNewRadoChart.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352
  1. <template>
  2. <view class="radoContent">
  3. <!-- #ifdef APP-PLUS || H5 -->
  4. <view @click="echarts.onClick" :prop="option" :change:prop="echarts.updateEcharts" id="custRadoChart" class="echarts"></view>
  5. <!-- #endif -->
  6. </view>
  7. </template>
  8. <script>
  9. import echarts from '../../static/echarts.js'
  10. import icons from '../uni-icons/icons.js'
  11. export default {
  12. props: {
  13. chartId: String,
  14. dataInfo: null,
  15. isShowIcon: {
  16. type: Boolean,
  17. default: () => {
  18. return false
  19. }
  20. },
  21. themeColor: {
  22. type: String,
  23. default: '#3CD9D9'
  24. },
  25. themeColor50: {
  26. type: String,
  27. default: '#AAEFEF'
  28. },
  29. themeColor25: {
  30. type: String,
  31. default: '#D4F7F7'
  32. },
  33. fuzhuColor: {
  34. type: String,
  35. default: '#FEC350'
  36. },
  37. fuzhuColor50: {
  38. type: String,
  39. default: '#FEE1A7'
  40. },
  41. fuzhuColor15: {
  42. type: String,
  43. default: '#FFF6E4'
  44. }
  45. },
  46. data() {
  47. return {
  48. option: {
  49. radar: [{
  50. indicator: [{
  51. name: '关注意愿',
  52. max: 100,
  53. min: 0
  54. },
  55. {
  56. name: '浏览意愿',
  57. max: 100,
  58. min: 0
  59. },
  60. {
  61. name: '分享意愿',
  62. max: 100,
  63. min: 0
  64. }
  65. ],
  66. center: ['50%', '65%'],
  67. radius: 90,
  68. startAngle: 90,
  69. splitNumber: 2,
  70. shape: 'polygon',
  71. name: {
  72. formatter: '{value}',
  73. textStyle: {
  74. color: '#333',
  75. opacity: 0.7
  76. }
  77. },
  78. splitArea: {
  79. areaStyle: {
  80. // color: ['rgba(114, 172, 209, 0.2)',
  81. // 'rgba(114, 172, 209, 0.4)', 'rgba(114, 172, 209, 0.6)',
  82. // 'rgba(114, 172, 209, 0.8)', 'rgba(114, 172, 209, 1)'],
  83. color: [
  84. // '#333'
  85. 'rgba(115,227,227,0.3)'
  86. // '#88F4F4'
  87. // 'rgba(254,195,80,0.5)',
  88. // 'rgba(254,195,80,0.4)',
  89. // 'rgba(254,195,80,0.3)',
  90. // 'rgba(254,195,80,0.2)',
  91. // 'rgba(254,195,80,0.1)'
  92. ],
  93. shadowColor: 'rgba(0, 0, 0, 0)',
  94. // shadowBlur: 10
  95. }
  96. },
  97. axisLine: {
  98. lineStyle: {
  99. // color: 'rgba(255, 255, 255, 0.5)'
  100. color: 'rgba(84,222,222,1)'
  101. }
  102. },
  103. splitLine: {
  104. lineStyle: {
  105. // color: 'rgba(255, 255, 255, 0.5)'
  106. color: 'rgba(84,222,222,1)'
  107. }
  108. }
  109. }],
  110. series: [{
  111. name: '雷达图',
  112. type: 'radar',
  113. emphasis: {
  114. lineStyle: {
  115. width: 4
  116. }
  117. },
  118. data: [{
  119. value: [],
  120. name: '图一',
  121. symbol: 'circle',
  122. symbolSize: 6,
  123. itemStyle: {
  124. color: '#fff',
  125. borderWidth: 2,
  126. // borderColor: '#202638'
  127. borderColor: 'rgba(118,228,228,0.7)'
  128. },
  129. lineStyle: {
  130. type: 'solid',
  131. borderWidth: 4,
  132. // color: '#202638'
  133. color: 'rgba(118,228,228,1)'
  134. },
  135. areaStyle: {
  136. // color: 'rgba(255, 255, 255, 0.7)'
  137. color: 'rgba(118,228,228,0.6)'
  138. }
  139. }]
  140. }]
  141. }
  142. }
  143. },
  144. mounted() {
  145. this.getDataAction()
  146. },
  147. filters: {
  148. userLevelFilter(val) {
  149. if (val) {
  150. switch (val){
  151. case 1:
  152. return 'A'
  153. break;
  154. case 2:
  155. return 'B'
  156. break;
  157. default:
  158. return 'C'
  159. break;
  160. }
  161. }
  162. return '-'
  163. }
  164. },
  165. methods: {
  166. getDataAction() {
  167. this.option.radar[0].splitArea.areaStyle.color = [this.themeColor25]
  168. this.option.radar[0].axisLine.lineStyle.color = this.themeColor
  169. this.option.radar[0].splitLine.lineStyle.color = this.themeColor
  170. this.option.series[0].data[0].itemStyle.borderColor = this.themeColor
  171. this.option.series[0].data[0].lineStyle.color = this.themeColor
  172. this.option.series[0].data[0].areaStyle.color = this.themeColor
  173. // 关注意愿、浏览意愿、分享意愿
  174. this.option.series[0].data[0].value = [this.dataFilter(this.dataInfo.followIntention), this.dataFilter(this.dataInfo.scanIntention), this.dataFilter(this.dataInfo.shareIntention)]
  175. this.option.radar[0].indicator[0].name = '关注意愿' + ':' + this.levelFilter(this.dataInfo.followIntention)
  176. this.option.radar[0].indicator[1].name = '浏览意愿' + ':' + this.levelFilter(this.dataInfo.scanIntention)
  177. this.option.radar[0].indicator[2].name = '分享意愿' + ':' + this.levelFilter(this.dataInfo.shareIntention)
  178. },
  179. dataFilter(val) {
  180. if (val) {
  181. switch (val){
  182. case 'A':
  183. return 100
  184. break;
  185. case 'B':
  186. return 50
  187. break;
  188. default:
  189. return 10
  190. break;
  191. }
  192. }
  193. return 10
  194. },
  195. levelFilter(val) {
  196. if (val) {
  197. switch (val){
  198. case 'A':
  199. return '高'
  200. break;
  201. case 'B':
  202. return '中'
  203. break;
  204. default:
  205. return '低'
  206. break;
  207. }
  208. }
  209. return '-'
  210. },
  211. onViewClick(options) {
  212. // console.log(options)
  213. }
  214. },
  215. watch: {
  216. dataInfo: {
  217. handler(e) {
  218. this.getDataAction()
  219. },
  220. deep: true
  221. },
  222. fuzhuColor15: {
  223. handler(e) {
  224. this.getDataAction()
  225. },
  226. immediate: true
  227. }
  228. },
  229. components: {
  230. icons
  231. }
  232. }
  233. </script>
  234. <script module="echarts" lang="renderjs">
  235. let myChart
  236. export default {
  237. mounted() {
  238. this.initAction()
  239. },
  240. methods: {
  241. initAction() {
  242. if (typeof window.echarts === 'function') {
  243. this.initEcharts()
  244. } else {
  245. // 动态引入较大类库避免影响页面展示
  246. const script = document.createElement('script')
  247. // view 层的页面运行在 www 根目录,其相对路径相对于 www 计算
  248. script.src = 'static/echarts.js'
  249. script.onload = this.initEcharts.bind(this)
  250. document.head.appendChild(script)
  251. }
  252. },
  253. initEcharts() {
  254. myChart = echarts.init(document.getElementById('custRadoChart'))
  255. // 观测更新的数据在 view 层可以直接访问到
  256. if (myChart) {
  257. myChart.setOption(this.option)
  258. }
  259. },
  260. updateEcharts(newValue, oldValue, ownerInstance, instance) {
  261. // 监听 service 层数据变更
  262. if (myChart) {
  263. myChart.setOption(newValue)
  264. }
  265. },
  266. onClick(event, ownerInstance) {
  267. // 调用 service 层的方法
  268. ownerInstance.callMethod('onViewClick', {
  269. test: 'test'
  270. })
  271. }
  272. }
  273. }
  274. </script>
  275. <style scoped lang="scss">
  276. .radoContent {
  277. width: 100%;
  278. height: 100%;
  279. position: relative;
  280. font-size: 60rpx;
  281. font-family: DIN Alternate;
  282. font-weight: bold;
  283. background-color: #4CD964;
  284. .echarts {
  285. width: 100%;
  286. margin-top: 0rpx;
  287. height: 100%;
  288. }
  289. .topSection {
  290. position: absolute;
  291. top: 0;
  292. left: 0;
  293. width: 100%;
  294. display: flex;
  295. align-items: center;
  296. justify-content: space-between;
  297. padding: 50rpx 48rpx;
  298. box-sizing: border-box;
  299. .leftDiv {
  300. display: flex;
  301. flex-direction: column;
  302. .levelDiv {
  303. display: flex;
  304. align-items: center;
  305. .des {
  306. margin-top: 10rpx;
  307. font-size: 12rpx;
  308. font-family: Verdana, Verdana-Regular;
  309. font-weight: 400;
  310. color: #999999;
  311. }
  312. .levelImg {
  313. width: 144rpx;
  314. height: 22rpx;
  315. margin-top: 20rpx;
  316. }
  317. }
  318. }
  319. .level {
  320. font-size: 60rpx;
  321. font-family: DIN Alternate, DIN Alternate-Bold;
  322. font-weight: 700;
  323. text-align: center;
  324. }
  325. .levelDes {
  326. font-size: 20rpx;
  327. font-family: Verdana, Verdana-Regular;
  328. font-weight: 400;
  329. color: #999999;
  330. }
  331. }
  332. }
  333. </style>