index.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. <template>
  2. <view class="top">
  3. <view class="qiun-charts">
  4. <view v-for="(item,index) in datalist">
  5. <view class="content">
  6. <view class="qiun-charts-one">
  7. </view>
  8. <text class="qiun-charts-two">赛轮轮胎品牌任务统计</text>
  9. <view style="display: flex;justify-content: space-between;">
  10. <view class="qiun-charts-three">
  11. <view>
  12. </view>
  13. <view>
  14. 10月10条任务统计
  15. </view>
  16. </view>
  17. <view class="qiun-charts-four">
  18. <view>
  19. </view>
  20. <view>
  21. 10月10条任务统计
  22. </view>
  23. </view>
  24. </view>
  25. <view class="content-one">
  26. <canvas canvas-id="canvasRing" id="canvasRing" class="charts" @touchstart="touchRing"></canvas>
  27. <canvas canvas-id="canvasRing" id="canvasRing" class="charts" @touchstart="touchRing"></canvas>
  28. </view>
  29. </view>
  30. </view>
  31. </view>
  32. </view>
  33. </template>
  34. <script>
  35. import uCharts from '@/components/u-charts/u-charts.js';
  36. import {
  37. isJSON
  38. } from '@/common/checker.js';
  39. var _self;
  40. var canvaRing = null;
  41. export default {
  42. data() {
  43. return {
  44. datalist: [{},
  45. {},
  46. {},
  47. {},
  48. {},
  49. ],
  50. cWidth: '',
  51. cHeight: '',
  52. pixelRatio: 1,
  53. textarea: ''
  54. }
  55. },
  56. onLoad() {
  57. _self = this;
  58. _self.cWidth = uni.upx2px(370);
  59. _self.cHeight = uni.upx2px(320);
  60. this.showRing('canvasRing')
  61. // this.getServerData();
  62. },
  63. methods: {
  64. // 这是官网给的调接口渲染数据的代码,我写的没有后台数据,自己写的固定的数据 就注销了
  65. // getServerData() {
  66. // uni.request({
  67. // url: 'https://www.ucharts.cn/data.json',
  68. // data: {},
  69. // success: function(res) {
  70. // console.log(res.data.data)
  71. // console.log("3333")
  72. // let Ring = {
  73. // series: []
  74. // };
  75. // //这里我后台返回的是数组,所以用等于,如果您后台返回的是单条数据,需要push进去
  76. // Ring.series = res.data.data.Ring.series;
  77. // //自定义文案示例,需设置format字段
  78. // for (let i = 0; i < Ring.series.length; i++) {
  79. // Ring.series[i].format = () => {
  80. // console.log(Ring.series[i].name + Ring.series[i].data)
  81. // return Ring.series[i].name + Ring.series[i].data
  82. // };
  83. // }
  84. // _self.textarea = JSON.stringify(res.data.data.Ring);
  85. // _self.showRing("canvasRing", Ring);
  86. // },
  87. // fail: () => {
  88. // _self.tips = "网络错误,小程序端请检查合法域名";
  89. // },
  90. // });
  91. // },
  92. showRing(canvasId, chartData) {
  93. var chartData = {
  94. series: [{
  95. "name": "已完成",
  96. "data": 50
  97. }, {
  98. "name": "待完成",
  99. "data": 30
  100. }]
  101. };
  102. canvaRing = new uCharts({
  103. $this: _self,
  104. canvasId: canvasId,
  105. type: 'ring',
  106. fontSize: 11,
  107. padding: [5, 5, 5, 5],
  108. legend: {
  109. show: true,
  110. position: 'bottom',
  111. float: 'center',
  112. itemGap: 10,
  113. padding: 2,
  114. lineHeight: 26,
  115. margin: 1,
  116. //backgroundColor:'rgba(41,198,90,0.2)',
  117. //borderColor :'rgba(41,198,90,0.5)',
  118. borderWidth: 1
  119. },
  120. background: '#fff',
  121. pixelRatio: _self.pixelRatio,
  122. series: chartData.series,
  123. animation: false,
  124. width: _self.cWidth,
  125. height: _self.cHeight,
  126. disablePieStroke: true,
  127. dataLabel: true,
  128. subtitle: {
  129. name: '70%',
  130. color: '#7cb5ec',
  131. fontSize: 12 * _self.pixelRatio,
  132. },
  133. title: {
  134. name: '已完成',
  135. color: '#666666',
  136. fontSize: 13 * _self.pixelRatio,
  137. },
  138. extra: {
  139. pie: {
  140. offsetAngle: 0,
  141. ringWidth: 15 * _self.pixelRatio,
  142. labelWidth: 1
  143. }
  144. },
  145. });
  146. },
  147. // touchRing(e) {
  148. // canvaRing.touchLegend(e, {
  149. // animation: false
  150. // });
  151. // canvaRing.showToolTip(e, {
  152. // format: function(item) {
  153. // return item.name + ':' + item.data
  154. // }
  155. // });
  156. // },
  157. touchRing(e) {
  158. canvaRing.touchLegend(e, {
  159. animation: false
  160. });
  161. canvaRing.showToolTip(e, {
  162. format: function(item) {
  163. return item.name + ':' + item.data
  164. }
  165. });
  166. },
  167. changeData() {
  168. if (isJSON(_self.textarea)) {
  169. let newdata = JSON.parse(_self.textarea);
  170. canvaRing.updateData({
  171. series: newdata.series,
  172. categories: newdata.categories
  173. });
  174. } else {
  175. uni.showToast({
  176. title: '数据格式错误',
  177. image: '../../../static/images/alert-warning.png'
  178. })
  179. }
  180. }
  181. }
  182. }
  183. </script>
  184. <style>
  185. /*样式的width和height一定要与定义的cWidth和cHeight相对应*/
  186. .qiun-charts {
  187. width: 750rpx;
  188. height: 331rpx;
  189. background: url(../../static/sailun/background.png) no-repeat;
  190. background-size: 750rpx 331rpx;
  191. }
  192. .qiun-charts-one {
  193. width: 6rpx;
  194. height: 30rpx;
  195. background: #0292FD;
  196. position: relative;
  197. top: 20rpx;
  198. left: 30rpx;
  199. }
  200. .qiun-charts-two {
  201. position: relative;
  202. top: -18rpx;
  203. left: 60rpx;
  204. font-size: 26rpx;
  205. font-weight: bold;
  206. }
  207. .content {
  208. width: 702rpx;
  209. height: 410rpx;
  210. background: #FFFFFF;
  211. box-shadow: 0px 10px 40px 0px rgba(223, 223, 223, 0.91);
  212. border-radius: 18px;
  213. margin: 0 auto;
  214. position: relative;
  215. top: 20rpx;
  216. margin-bottom: 40rpx;
  217. }
  218. .content-one {
  219. display: flex;
  220. justify-content: space-between;
  221. }
  222. .charts {
  223. width: 380rpx;
  224. height: 450rpx;
  225. position: relative;
  226. top: -20rpx;
  227. }
  228. .qiun-charts-three>view:nth-child(1) {
  229. width: 24rpx;
  230. height: 24rpx;
  231. border: 6rpx solid #0094FE;
  232. transform:rotate(50deg);
  233. position: relative;
  234. top: 20rpx;
  235. left: 30rpx;
  236. }
  237. .qiun-charts-three>view:nth-child(2) {
  238. width: 150rpx;
  239. height: 22rpx;
  240. background-color: #000000;
  241. color: #fff;
  242. font-size: 15rpx;
  243. opacity: 0.3;
  244. text-align: center;
  245. position: relative;
  246. top: -2rpx;
  247. left: 40rpx;
  248. border-top-right-radius: 12rpx;
  249. }
  250. .qiun-charts-four {
  251. position: relative;
  252. right: 200rpx;
  253. }
  254. .qiun-charts-four>view:nth-child(1) {
  255. width: 24rpx;
  256. height: 24rpx;
  257. border: 6rpx solid #0094FE;
  258. transform:rotate(50deg);
  259. position: relative;
  260. top: 20rpx;
  261. left: 30rpx;
  262. }
  263. .qiun-charts-four>view:nth-child(2) {
  264. width: 150rpx;
  265. height: 22rpx;
  266. background-color: #000000;
  267. color: #fff;
  268. font-size: 15rpx;
  269. opacity: 0.3;
  270. text-align: center;
  271. position: relative;
  272. top: -2rpx;
  273. left: 40rpx;
  274. border-top-right-radius: 12rpx;
  275. }
  276. </style>