charts123.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622
  1. <template>
  2. <view class="body">
  3. <allArea @getChild="childMess"></allArea>
  4. <swiper :interval="3000" :duration="500" :style="{ height:mainHeight+ 'px' }" style="background-color: #FFFFFF;" v-bind:current="swiperTabIdx">
  5. <swiper-item>
  6. <view class="swiper-item" style="padding-top: 10%;overflow-x: scroll;">
  7. <view class="qiun-columns" style=" display: flex;">
  8. <view class="bt" style="flex: 1;">
  9. <button type="default" v-for="(item,index) in indexList" :key='index' @click="changeDate(index)">{{item}}</button>
  10. </view>
  11. <view class="qiun-charts-rotate" style="flex: 0 0 50%;padding: 0;">
  12. <canvas canvas-id="canvasColumn" id="canvasColumn" class="charts-rotate"></canvas>
  13. </view>
  14. <view class="" style="flex:0 0 20%;">
  15. <view class="text">
  16. 日新增订单
  17. </view>
  18. </view>
  19. </view>
  20. </view>
  21. </swiper-item>
  22. <swiper-item>
  23. <view class="swiper-item">
  24. <view class="swiper-item" style="padding-top: 10%;overflow-x: scroll;">
  25. <view class="qiun-columns" style=" display: flex;">
  26. <view class="qiun-charts-rotate" style="flex: 0 0 80%;padding: 0upx;">
  27. <canvas canvas-id="canvasColumnA" id="canvasColumnA" class="charts-rotate"></canvas>
  28. </view>
  29. <view class="" style="flex:1">
  30. <view class="text">
  31. 用户数据
  32. </view>
  33. </view>
  34. </view>
  35. </view>
  36. </view>
  37. </swiper-item>
  38. <swiper-item>
  39. <view class="swiper-item">
  40. <view class="swiper-item" style="padding-top: 10%;overflow-x: scroll;">
  41. <view class="qiun-columns" style=" display: flex;">
  42. <view class="bt" style="flex:0 0 10%;">
  43. <!-- <button type="default" v-for="(item,index) in indexList" :key='index' @click="changeDate(index)">{{item}}</button> -->
  44. </view>
  45. <view class="qiun-charts-rotate" style="flex: 0 0 70%;padding: 0;">
  46. <!-- <view class="qiun-charts"> -->
  47. <!--#ifdef MP-ALIPAY -->
  48. <canvas canvas-id="canvasLineA" id="canvasLineA" class="charts-rotate" :width="cWidth*pixelRatio" :height="cHeight*pixelRatio"
  49. :style="{'width':cWidth+'px','height':cHeight+'px'}" disable-scroll=true @touchstart="touchIt($event,'canvasLineA')"
  50. @touchmove="moveLineA"></canvas>
  51. <!-- 使用图表拖拽功能时,建议给canvas增加disable-scroll=true属性,在拖拽时禁止屏幕滚动 -->
  52. <!--#endif-->
  53. <!--#ifndef MP-ALIPAY -->
  54. <canvas canvas-id="canvasLineA" style="width:100%;" class="charts-rotate" id="canvasLineA" disable-scroll=true
  55. @touchstart="touchIt($event,'canvasLineA')" @touchmove="moveLineA"></canvas>
  56. <!-- 使用图表拖拽功能时,建议给canvas增加disable-scroll=true属性,在拖拽时禁止屏幕滚动 -->
  57. <!--#endif-->
  58. <!-- </view> -->
  59. </view>
  60. <view class="" style="flex:0 0 20%;">
  61. <view class="text">
  62. 收益详情
  63. </view>
  64. </view>
  65. </view>
  66. </view>
  67. </view>
  68. </swiper-item>
  69. </swiper>
  70. </view>
  71. </template>
  72. <script>
  73. import uCharts from '@/pages/mine/uchart/u-charts.js';
  74. import allArea from '../../component/allArea/allArea.vue'
  75. import {
  76. isJSON
  77. } from '@/pages/mine/uchart/checker.js';
  78. var _self;
  79. var canvaColumn = null;
  80. var app = getApp()
  81. var canvasObj = {};
  82. export default {
  83. data() {
  84. return {
  85. swiperTabIdx:2,
  86. // cWidth:'',
  87. // cHeight:'',
  88. cWidth2: '', //横屏图表
  89. cHeight2: '', //横屏图表
  90. pixelRatio: 1,
  91. serverData: '',
  92. indexList: "", //默认显示日期
  93. dayIndex: "",
  94. dayTabIndex: 0, //默认显示第一个按钮的日期数据
  95. }
  96. },
  97. onLoad() {
  98. uni.getSystemInfo({
  99. success: res => {
  100. console.log(res, "这是屏幕信息")
  101. this.mainHeight = res.windowHeight;
  102. }
  103. })
  104. console.log(12344)
  105. _self = this;
  106. this.cWidth = uni.upx2px(500);
  107. this.cHeight = uni.upx2px(1100);
  108. // this.cWidth2 = uni.upx2px(700);
  109. // this.cHeight2 = uni.upx2px(1100);
  110. this.dayDate();
  111. this.userDate();
  112. this.getServerData(); //收益数据
  113. },
  114. methods: {
  115. childMess: function(e) {
  116. console.log(e, '这是子组件穿过来的值')
  117. this.areaID = e.areaID
  118. this.getServerData();
  119. // this.getFeed()
  120. },
  121. changeDate: function(e) {
  122. this.dayTabIndex = e
  123. console.log(e, "3333")
  124. this.dayDate();
  125. },
  126. getServerData() {
  127. let date = {
  128. area_id: 1,
  129. days: 'thirtyDays'
  130. }
  131. app.request('order/profitChart', date, 'GET').then(res => {
  132. let LineA = {
  133. categories: [],
  134. series: []
  135. };
  136. console.log(res, '这是所有数据999999999')
  137. var arr = new Array
  138. arr = res.data
  139. var data = new Array
  140. for (let i = 0, len = res.data.length; i < len; i++) { // 编程式
  141. console.log("for循环", arr[i]);
  142. console.log(arr[i].data, "数组")
  143. var aa = arr[i].data
  144. console.log(aa, "这是第" + i)
  145. LineA.series.push({
  146. name: arr[i].name,
  147. data: arr[i].data
  148. })
  149. }
  150. for (let k = 0, leng = aa.length; k < leng; k++) {
  151. // console.log(aa[k].value,'666666')
  152. // console.log(aa[k].date,"这是横坐标")
  153. LineA.categories.push(aa[k].date)
  154. // console.log(this.lineData2.categories,"这是横坐标")
  155. // console.log(this.lineData2.series,"这是最终数据")
  156. }
  157. console.log(res.data.data, "333")
  158. // LineA.categories=res.data.data.LineA.categories;
  159. // LineA.series=res.data.data.LineA.series;
  160. //第二根线为虚线的设置
  161. // LineA.series[1].lineType='dash';
  162. // LineA.series[1].dashLength=10;
  163. _self.textarea = JSON.stringify(LineA);
  164. _self.showLineA("canvasLineA", LineA);
  165. })
  166. },
  167. //日新增订单
  168. dayDate() {
  169. _self = this;
  170. this.cWidth = uni.upx2px(500);
  171. this.cHeight = uni.upx2px(1400);
  172. // this.cWidth2 = uni.upx2px(700);
  173. // this.cHeight2 = uni.upx2px(1100);
  174. let date = {
  175. area_id: 1,
  176. days: 'thirtyDays'
  177. }
  178. app.request('order/hourOrderNumber', date, 'GET').then(res => {
  179. let Column = {
  180. categories: [],
  181. series: []
  182. };
  183. // _self.serverData=res;
  184. console.log(res, '22222')
  185. // console.log(res, 'disanzu这是所有数据')
  186. _self.indexList = res.data.date
  187. Column.categories = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16",
  188. "17", "18", "19", "20", "21", "22", '23', "24"
  189. ]
  190. var arr = []
  191. var day = res.data.date[_self.dayTabIndex]
  192. console.log(day, "444444555555555")
  193. arr.push({
  194. name: day,
  195. data: res.data.data[day]
  196. })
  197. console.log(arr, "444")
  198. Column.series = arr
  199. // Column.series=res.data.data
  200. console.log(Column, "6666")
  201. _self.showColumn("canvasColumn", Column);
  202. })
  203. },
  204. //用户数据统计
  205. userDate() {
  206. let date = {
  207. area_id: 1,
  208. days: 'thirtyDays'
  209. }
  210. app.request('user/newUsersChart', date, 'GET').then(res => {
  211. let Column = {
  212. categories: [],
  213. series: [
  214. ]
  215. };
  216. console.log(res.data, "88888888")
  217. var arr = []
  218. for (let i = 0, len = res.data.length; i < len; i++) { // 编程式
  219. console.log("for循环", res.data[i]);
  220. Column.categories.push(res.data[i].date)
  221. arr.push(res.data[i].value)
  222. Column.series.push({
  223. name: res.data[i].date,
  224. data: arr,
  225. color: '#55ff00'
  226. })
  227. }
  228. console.log(arr, "898988989898")
  229. console.log(Column, "数组5656565655")
  230. // _self.indexList = res.data.date
  231. _self.showColumn1("canvasColumnA", Column);
  232. })
  233. },
  234. showColumn(canvasId, chartData) {
  235. canvaColumn = new uCharts({
  236. $this: _self,
  237. canvasId: canvasId,
  238. type: 'column',
  239. legend: true,
  240. fontSize: 11,
  241. background: '#55ff00',
  242. pixelRatio: _self.pixelRatio,
  243. animation: true,
  244. rotate: true,
  245. categories: chartData.categories,
  246. series: chartData.series,
  247. xAxis: {
  248. disableGrid: true,
  249. },
  250. yAxis: {
  251. //disabled:true
  252. },
  253. dataLabel: true,
  254. width: _self.cWidth * _self.pixelRatio,
  255. height: _self.cHeight * _self.pixelRatio,
  256. extra: {
  257. column: {
  258. type: 'group',
  259. width: _self.cWidth * _self.pixelRatio * 0.45 / chartData.categories.length
  260. }
  261. }
  262. });
  263. },
  264. changeGaugeData() {
  265. let series = [{
  266. name: "完成率",
  267. data: Math.random()
  268. }]; //这里是随机数据,生产环境请从服务器获取,注意series数据类型为数组
  269. //这里我借用之前的categories数据,判断一下新数据的title.color,没有写死在程序里,以便于自定义
  270. let newTitleColor;
  271. for (let i = 0; i < _self.serverData.Gauge.categories.length; i++) {
  272. if (series[0].data <= _self.serverData.Gauge.categories[i].value) {
  273. newTitleColor = _self.serverData.Gauge.categories[i].color;
  274. break;
  275. }
  276. }
  277. canvasObj['canvasGauge'].updateData({
  278. series: series, //这里给了新数值
  279. categories: _self.serverData.Gauge.categories,
  280. title: {
  281. name: Math.round(series[0].data * 100) + '%',
  282. color: newTitleColor,
  283. fontSize: 25 * _self.pixelRatio,
  284. offsetY: 50 * _self.pixelRatio, //新增参数,自定义调整Y轴文案距离
  285. },
  286. subtitle: {
  287. name: '更新数据',
  288. color: '#666666',
  289. fontSize: 15 * _self.pixelRatio,
  290. offsetY: -50 * _self.pixelRatio, //新增参数,自定义调整Y轴文案距离
  291. }
  292. });
  293. },
  294. touchLineA(e) {
  295. canvasObj['canvasLineA'].scrollStart(e);
  296. },
  297. moveLineA(e) {
  298. canvasObj['canvasLineA'].scroll(e);
  299. },
  300. touchEndLineA(e) {
  301. console.log(e, "00")
  302. canvasObj['canvasLineA'].scrollEnd(e);
  303. //下面是toolTip事件,如果滚动后不需要显示,可不填写
  304. canvasObj['canvasLineA'].showToolTip(e, {
  305. format: function(item, category) {
  306. return category + ' ' + item.name + ':' + item.data
  307. }
  308. });
  309. },
  310. touchIt(e, id) {
  311. canvasObj['canvasLineA'].scrollStart(e);
  312. canvasObj[id].touchLegend(e, {
  313. animation: false
  314. });
  315. canvasObj[id].showToolTip(e, {
  316. format: function(item, category) {
  317. if (typeof item.data === 'object') {
  318. return category + ' ' + item.name + ':' + item.data.value
  319. } else {
  320. return category + ' ' + item.name + ':' + item.data
  321. }
  322. }
  323. });
  324. },
  325. touchMix(e) {
  326. canvasObj['canvasMix'].scrollStart(e);
  327. },
  328. moveMix(e) {
  329. canvasObj['canvasMix'].scroll(e);
  330. },
  331. showLineA(canvasId, chartData) {
  332. canvasObj[canvasId] = new uCharts({
  333. $this: _self,
  334. canvasId: canvasId,
  335. type: 'line',
  336. fontSize: 8,
  337. rotate: true,
  338. dataLabel:false,
  339. // dataLabel: false,
  340. padding: [15, 15, 0, 15],
  341. legend: {
  342. show: true,
  343. padding: 5,
  344. lineHeight: 11,
  345. margin: 5,
  346. },
  347. // dataLabel: false,
  348. dataPointShape: false,
  349. background: '#FFFFFF',
  350. pixelRatio: _self.pixelRatio,
  351. categories: chartData.categories,
  352. series: chartData.series,
  353. animation: false,
  354. enableScroll: true, //开启图表拖拽功能
  355. xAxis: {
  356. // rotateLabel: true,
  357. // disableGrid: true,
  358. // itemCount: chartData.length,
  359. // labelCount: 30,
  360. // gridType: 'dash',
  361. disableGrid: true,
  362. type: 'grid',
  363. rotateLabel: true,
  364. // gridType: 'dash',
  365. itemCount: 30,
  366. // scrollShow: true,
  367. scrollAlign: 'left',
  368. //scrollBackgroundColor:'#F7F7FF',//可不填写,配合enableScroll图表拖拽功能使用,X轴滚动条背景颜色,默认为 #EFEBEF
  369. //scrollColor:'#DEE7F7',//可不填写,配合enableScroll图表拖拽功能使用,X轴滚动条颜色,默认为 #A6A6A6
  370. },
  371. yAxis: {
  372. //disabled:true
  373. gridType: 'dash',
  374. splitNumber: 8,
  375. min: 10,
  376. max: 180,
  377. format: (val) => {
  378. return val.toFixed(0)
  379. } //如不写此方法,Y轴刻度默认保留两位小数
  380. },
  381. width: _self.cWidth * _self.pixelRatio,
  382. height: _self.cHeight * _self.pixelRatio,
  383. dataLabel: true,
  384. dataPointShape: true,
  385. extra: {
  386. lineStyle: 'straight'
  387. },
  388. });
  389. },
  390. showColumn1(canvasId, chartData) {
  391. canvaColumn = new uCharts({
  392. $this: _self,
  393. canvasId: canvasId,
  394. type: 'line',
  395. legend: true,
  396. fontSize: 8,
  397. background: '#55ff00',
  398. // pixelRatio: _self.pixelRatio,
  399. // animation: true,
  400. rotate: true,
  401. legend: {
  402. show: false
  403. },
  404. // rotateLabel: true,
  405. categories: chartData.categories,
  406. series: chartData.series,
  407. xAxis: {
  408. rotateLabel: true,
  409. disableGrid: true,
  410. itemCount: chartData.length,
  411. labelCount: 30,
  412. gridType: 'dash',
  413. },
  414. yAxis: {
  415. //disabled:true
  416. },
  417. dataLabel: true,
  418. width: _self.cWidth * _self.pixelRatio,
  419. height: _self.cHeight * _self.pixelRatio,
  420. // extra: {
  421. // column: {
  422. // type: 'group',
  423. // width: _self.cWidth * _self.pixelRatio * 0.45 / chartData.categories.length
  424. // }
  425. // },
  426. extra: {
  427. lineStyle: 'straight'
  428. }
  429. });
  430. },
  431. // touchColumn(e) {
  432. // canvaColumn.showToolTip(e, {
  433. // format: function(item, category) {
  434. // if (typeof item.data === 'object') {
  435. // return category + ' ' + item.name + ':' + item.data.value
  436. // } else {
  437. // return category + ' ' + item.name + ':' + item.data
  438. // }
  439. // }
  440. // });
  441. // },
  442. }
  443. }
  444. </script>
  445. <style>/* top: 10%; */
  446. .qiun-charts-rotate {
  447. width: 500upx;
  448. height: 1400upx;
  449. background-color: #FFFFFF;
  450. padding: 25upx;
  451. }
  452. .charts-rotate {
  453. width: 500upx;
  454. height: 1400upx;
  455. background-color: #FFFFFF;
  456. }
  457. page {
  458. background: #F2F2F2;
  459. width: 750upx;
  460. overflow-x: hidden;
  461. }
  462. .bt {
  463. width: 20%;
  464. /* margin-top: 21%upx; */
  465. }
  466. .bt1 {
  467. height: 50upx;
  468. width: 180upx;
  469. line-height: 50upx;
  470. }
  471. .bt button {
  472. font-size: 24upx;
  473. text-align: center;
  474. display: inline-block;
  475. vertical-align: bottom;
  476. height: 50upx;
  477. width: 180upx;
  478. line-height: 50upx;
  479. margin-top: 80upx;
  480. margin-bottom: 80upx;
  481. transform: rotate(90deg);
  482. -ms-transform: rotate(90deg);
  483. /* Internet Explorer 9*/
  484. -moz-transform: rotate(90deg);
  485. /* Firefox */
  486. -webkit-transform: rotate(90deg);
  487. /* Safari 和 Chrome */
  488. -o-transform: rotate(90deg);
  489. /* Opera */
  490. filter: progid:DXImageTransform.Microsoft.BasicImage(rotation=1);
  491. }
  492. ..bt button:first-child {
  493. /* margin-top: 300upx; */
  494. }
  495. .text {
  496. font-size: 36upx;
  497. height: 20upx;
  498. font-weight: 550;
  499. line-height: 280upx;
  500. width: 350upx;
  501. border-top: solid 2upx #004FB6;
  502. margin-top: 21%;
  503. /* height: 600upx;
  504. width: 200upx; */
  505. /* background-color: #004FB6; */
  506. color: #004FB6 !important;
  507. text-align: center;
  508. transform: rotate(90deg);
  509. -ms-transform: rotate(90deg);
  510. /* Internet Explorer 9*/
  511. -moz-transform: rotate(90deg);
  512. /* Firefox */
  513. -webkit-transform: rotate(90deg);
  514. /* Safari 和 Chrome */
  515. -o-transform: rotate(90deg);
  516. /* Opera */
  517. filter: progid:DXImageTransform.Microsoft.BasicImage(rotation=1);
  518. }
  519. /* .qiun-padding {
  520. padding: 2%;
  521. width: 96%;
  522. }
  523. .qiun-wrap {
  524. display: flex;
  525. flex-wrap: wrap;
  526. }
  527. .qiun-rows {
  528. display: flex;
  529. flex-direction: row !important;
  530. }
  531. .qiun-columns {
  532. display: flex;
  533. flex-direction: column !important;
  534. }
  535. .qiun-common-mt {
  536. margin-top: 10upx;
  537. }
  538. .qiun-bg-white {
  539. background: #FFFFFF;
  540. }
  541. .qiun-title-bar {
  542. width: 96%;
  543. padding: 10upx 2%;
  544. flex-wrap: nowrap;
  545. }
  546. .qiun-title-dot-light {
  547. border-left: 10upx solid #0ea391;
  548. padding-left: 10upx;
  549. font-size: 32upx;
  550. color: #000000
  551. }
  552. .qiun-charts {
  553. width: 750upx;
  554. height: 500upx;
  555. background-color: #FFFFFF;
  556. }
  557. .charts {
  558. width: 750upx;
  559. height: 500upx;
  560. background-color: #FFFFFF;
  561. } */
  562. </style>