monthReport.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380
  1. import F2 from '@antv/f2';
  2. // 建议统一从 lib 下引入
  3. const PieLabel = require('@antv/f2/lib/plugin/pie-label'); // 引入 PieLabel 模块
  4. // 方式一:全局注册
  5. F2.Chart.plugins.register(PieLabel);
  6. import request from '../../../util/http'
  7. import apiUrl from '../../../util/apiUrl'
  8. var app = getApp();
  9. Page({
  10. data: {
  11. reportDate: '',
  12. servantName: '',
  13. serviceDay: '',
  14. percentTop: '',
  15. expendTotal: '',
  16. taskNum: '',
  17. reportInfo:'',
  18. chartShow:true,
  19. },
  20. onLoad() {
  21. let reportInfo=app.globalData.reportInfo;
  22. let serviceTime=JSON.parse(reportInfo.serviceTime);
  23. let year=(serviceTime.year==null?'':serviceTime.year);
  24. let month=(serviceTime.month==null?'':serviceTime.month);
  25. console.log(reportInfo);
  26. if(reportInfo.attrOne=='3'){
  27. this.setData({
  28. chartShow:false,
  29. })
  30. }else{
  31. this.setData({
  32. chartShow:true,
  33. })
  34. }
  35. this.setData({
  36. reportInfo:reportInfo,
  37. reportDate:year+'年'+month+'月',
  38. servantName:serviceTime.nickName,
  39. serviceDay:serviceTime.serviceDays,
  40. percentTop:serviceTime.serviceQuality,
  41. expendTotal:reportInfo.expenses
  42. })
  43. },
  44. onInitChart(F2, config) {
  45. // 饼状图
  46. const chart = new F2.Chart(config);
  47. const data = [
  48. { name: '打扫房间', proportion: 0.4, a: '1' },
  49. { name: '打扫厨房', proportion: 0.2, a: '1' },
  50. { name: '带孩子', proportion: 0.18, a: '1' },
  51. { name: '照顾老人', proportion: 0.15, a: '1' },
  52. { name: '清洁厨房', proportion: 0.05, a: '1' },
  53. { name: '其他', proportion: 0.02, a: '1' },
  54. ];
  55. chart.source(data);
  56. chart.legend({
  57. position: 'right'
  58. });
  59. chart.coord('polar', {
  60. transposed: true,
  61. innerRadius: 0.7,
  62. });
  63. chart.axis(false);
  64. chart
  65. .interval()
  66. .position('a*proportion')
  67. .color('name', [
  68. '#1890FF',
  69. '#13C2C2',
  70. '#2FC25B',
  71. '#FACC14',
  72. '#F04864',
  73. '#8543E0',
  74. ])
  75. .adjust('stack');
  76. chart.render();
  77. // 注意:需要把chart return 出来
  78. return chart;
  79. },
  80. onInitChart1(F2, config) {
  81. // 本月任务分布饼状图
  82. const chart = new F2.Chart(config);
  83. let taskNum = JSON.parse(this.data.reportInfo.pieChart).taskSum;
  84. let dataList=JSON.parse(this.data.reportInfo.pieChart).randList;
  85. dataList.forEach(item => {
  86. item.percentage=(item.percentage)*1;
  87. });
  88. const data =dataList;
  89. // const data = JSON.parse(this.data.reportInfo.pieChart).randList;
  90. // const data=[{"taskName":"洗护类","percentage":0.2},{"taskName":"洗e类","percentage":0.8}]
  91. chart.source(data);
  92. chart.legend(false);
  93. chart.coord('polar', {
  94. transposed: true,
  95. innerRadius: 0.6,
  96. });
  97. chart.axis(false);
  98. chart
  99. .interval()
  100. .position('1*percentage')
  101. .color('taskName', [
  102. '#EB6F49',
  103. '#00D98B',
  104. '#FDB628',
  105. '#0091F1',
  106. '#00E4EC',
  107. '#8256E8',
  108. ])
  109. .adjust('stack');
  110. chart.guide()
  111. .text({
  112. position: ['50%', '50%'],
  113. style: {
  114. fill: '#7ED4F6',
  115. fontSize: '12',
  116. },
  117. content: ` 本月共
  118. ${taskNum}条任务`,
  119. limitInPlot: true,
  120. });
  121. chart.pieLabel({
  122. sidePadding: 30,
  123. activeShape: true,
  124. label1: function label1(data) {
  125. return {
  126. text: data.taskName,
  127. fill: '#7ED4F6',
  128. fontWeight: 'bold'
  129. };
  130. },
  131. label2: function label2(data) {
  132. return {
  133. text: data.percentage+'%',
  134. fill: '#7ED4F6'
  135. };
  136. },
  137. onClick: function onClick(ev) {
  138. console.log(ev.data);
  139. }
  140. });
  141. chart.render();
  142. // 注意:需要把chart return 出来
  143. return chart;
  144. },
  145. onInitChart2(F2, config) {
  146. // 本月任务完成情况
  147. const chart = new F2.Chart(config);
  148. let dataList=JSON.parse(this.data.reportInfo.finishInfo);
  149. dataList.forEach(item => {
  150. item.percent=(item.percent)*1;
  151. item.const='const';
  152. });
  153. const data =dataList;
  154. // const data=[{"name":"完成","percent":100,"const":'const'},{"name":"无法完成","percent":200,"const":'const'},{"name":"未完成","percent":300,"const":'const'},{"name":"补打卡","percent":400,"const":'const'}]
  155. // const data = JSON.parse(this.data.reportInfo.finishInfo);
  156. chart.source(data);
  157. chart.legend(false);
  158. chart.coord('polar', {
  159. transposed: true,
  160. });
  161. chart.axis(false);
  162. chart
  163. .interval()
  164. .position('const*percent')
  165. .color('name', [
  166. '#EB6F49',
  167. '#00D98B',
  168. '#FDB628',
  169. '#0091F1',
  170. '#00E4EC',
  171. '#8256E8',
  172. ])
  173. .adjust('stack');
  174. chart.pieLabel({
  175. sidePadding: 30,
  176. activeShape: true,
  177. label1: function label1(data) {
  178. return {
  179. text: data.name,
  180. fill: '#7ED4F6',
  181. fontWeight: 'bold'
  182. };
  183. },
  184. label2: function label2(data) {
  185. return {
  186. text: data.percent+'%',
  187. fill: '#7ED4F6'
  188. };
  189. },
  190. onClick: function onClick(ev) {
  191. console.log(ev.data);
  192. }
  193. });
  194. chart.render();
  195. // 注意:需要把chart return 出来
  196. return chart;
  197. },
  198. onInitChart3(F2, config) {
  199. //任务完成趋势图
  200. const chart = new F2.Chart(config);
  201. const data = JSON.parse(this.data.reportInfo.taskTrend);
  202. chart.source(data, {
  203. workDay: {
  204. type: 'timeCat',
  205. tickCount: 5,
  206. // mask: 'hh:mm',
  207. range: [ 0, 1 ]
  208. },
  209. taskNum: {
  210. tickCount: 3,
  211. // formatter: function formatter(ivalue) {
  212. // return ivalue + '%';
  213. // }
  214. }
  215. });
  216. // chart.tooltip({
  217. // showItemMarker: false,
  218. // onShow: function onShow(ev) {
  219. // const items = ev.items;
  220. // items[0].name = null;
  221. // items[0].name = items[0].title;
  222. // items[0].value = '¥ ' + items[0].value;
  223. // }
  224. // });
  225. chart.axis('workDay', {
  226. line: null,
  227. label: function label(text, index, total) {
  228. const textCfg = {};
  229. if (index === 0) {
  230. textCfg.textAlign = 'left';
  231. } else if (index === total - 1) {
  232. textCfg.textAlign = 'right';
  233. }
  234. return textCfg;
  235. }
  236. });
  237. chart.axis('tem', {
  238. grid: function grid(text) {
  239. if (text === '0%') {
  240. return {
  241. lineDash: null,
  242. lineWidth: 1
  243. };
  244. }
  245. }
  246. });
  247. chart.legend({
  248. position: 'bottom',
  249. offsetY: -5
  250. });
  251. chart.line()
  252. .position('workDay*taskNum')
  253. .color('name');
  254. chart.render();
  255. // 注意:需要把chart return 出来
  256. return chart;
  257. },
  258. onInitChart4(F2, config) {
  259. // 任务类完成详细情况
  260. const chart = new F2.Chart(config);
  261. let dataList=JSON.parse(this.data.reportInfo.classfInish).lefts;
  262. dataList.forEach(item => {
  263. item.finishRate=(item.finishRate)*1;
  264. });
  265. const data =dataList;
  266. // const data = [{"taskClass":"洗护类","finishRate":100.00,"type":"1","name":null},{"taskClass":"做饭类","finishRate":66.67,"type":"2","name":null},{"taskClass":"打扫类","finishRate":83.33,"type":"3","name":null},{"taskClass":"照顾老人类","finishRate":100.00,"type":"4","name":null},{"taskClass":"照顾孩子类","finishRate":66.67,"type":"5","name":null}];
  267. // const data=JSON.parse(this.data.reportInfo.classfInish).lefts;
  268. chart.source(data, {
  269. finishRate: {
  270. tickCount: 3,
  271. range: [ 0, 1 ],
  272. formatter: function formatter(ivalue) {
  273. return ivalue + '%';
  274. }
  275. }
  276. });
  277. // chart.tooltip({
  278. // showItemMarker: false,
  279. // onShow: function onShow(ev) {
  280. // const items = ev.items;
  281. // items[0].name = null;
  282. // items[0].name = items[0].title;
  283. // items[0].value = '¥ ' + items[0].value;
  284. // }
  285. // });
  286. chart.interval()
  287. .position('taskClass*finishRate')
  288. .color('l(90) 0:#1890ff 1:#70cdd0'); // 定义柱状图渐变色
  289. chart.render();
  290. // 注意:需要把chart return 出来
  291. return chart;
  292. },
  293. onInitChart5(F2, config) {
  294. //任务无法完成原因
  295. const chart = new F2.Chart(config);
  296. // const data = [{"number":"20","typeName":"任务太多"},{"number":"0","typeName":"我不会"},{"number":"10","typeName":"任务不详细"}];
  297. let dataList=JSON.parse(this.data.reportInfo.unfinishd);
  298. dataList.forEach(item => {
  299. item.number=(item.number)*1;
  300. });
  301. const data =dataList;
  302. // const data=JSON.parse(this.data.reportInfo.unfinishd);
  303. chart.source(data, {
  304. sales: {
  305. tickCount: 5
  306. }
  307. });
  308. // chart.tooltip({
  309. // showItemMarker: false,
  310. // onShow: function onShow(ev) {
  311. // const items = ev.items;
  312. // items[0].name = null;
  313. // items[0].name = items[0].title;
  314. // items[0].value = '¥ ' + items[0].value;
  315. // }
  316. // });
  317. chart.interval()
  318. .position('typeName*number')
  319. .color('l(90) 0:#FBEC9F 1:#F3D34D'); // 定义柱状图渐变色
  320. chart.render();
  321. // 注意:需要把chart return 出来
  322. return chart;
  323. },
  324. onInitChart0(F2, config) {
  325. //折线图
  326. const chart = new F2.Chart(config);
  327. const data = [
  328. { value: 63.4, city: 'New York', date: '2011-10-01' },
  329. { value: 62.7, city: 'Alaska', date: '2011-10-01' },
  330. { value: 72.2, city: 'Austin', date: '2011-10-01' },
  331. { value: 58, city: 'New York', date: '2011-10-02' },
  332. { value: 59.9, city: 'Alaska', date: '2011-10-02' },
  333. { value: 67.7, city: 'Austin', date: '2011-10-02' },
  334. { value: 53.3, city: 'New York', date: '2011-10-03' },
  335. { value: 59.1, city: 'Alaska', date: '2011-10-03' },
  336. { value: 69.4, city: 'Austin', date: '2011-10-03' },
  337. ];
  338. chart.source(data, {
  339. date: {
  340. range: [0, 1],
  341. type: 'timeCat',
  342. mask: 'MM-DD'
  343. },
  344. value: {
  345. max: 300,
  346. tickCount: 4
  347. }
  348. });
  349. chart.area().position('date*value').color('city').adjust('stack');
  350. chart.line().position('date*value').color('city').adjust('stack');
  351. chart.render();
  352. // 注意:需要把chart return 出来
  353. return chart;
  354. },
  355. });