monthReport.js 8.7 KB

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