monthReport.js 8.3 KB

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