monthReport.js 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  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. Page({
  7. data: {
  8. reportDate:'2020年11月',
  9. servantName:'王阿姨',
  10. serviceDay:'28',
  11. percentTop:'88%',
  12. expendTotal:'1888',
  13. taskNum:'60',
  14. },
  15. onLoad() {
  16. },
  17. onInitChart(F2, config) {
  18. // 饼状图
  19. const chart = new F2.Chart(config);
  20. const data = [
  21. { name: '打扫房间', proportion: 0.4, a: '1' },
  22. { name: '打扫厨房', proportion: 0.2, a: '1' },
  23. { name: '带孩子', proportion: 0.18, a: '1' },
  24. { name: '照顾老人', proportion: 0.15, a: '1' },
  25. { name: '清洁厨房', proportion: 0.05, a: '1' },
  26. { name: '其他', proportion: 0.02, a: '1' },
  27. ];
  28. chart.source(data);
  29. chart.legend({
  30. position: 'right'
  31. });
  32. chart.coord('polar', {
  33. transposed: true,
  34. innerRadius: 0.7,
  35. });
  36. chart.axis(false);
  37. chart
  38. .interval()
  39. .position('a*proportion')
  40. .color('name', [
  41. '#1890FF',
  42. '#13C2C2',
  43. '#2FC25B',
  44. '#FACC14',
  45. '#F04864',
  46. '#8543E0',
  47. ])
  48. .adjust('stack');
  49. chart.render();
  50. // 注意:需要把chart return 出来
  51. return chart;
  52. },
  53. onInitChart1(F2, config) {
  54. // 本月任务分布饼状图
  55. const chart = new F2.Chart(config);
  56. let taskNum=this.data.taskNum;
  57. // chart.plugins.register([ PieLabel ]);
  58. const data = [
  59. { name: '打扫房间', proportion: 0.4, a: '1' },
  60. { name: '打扫厨房', proportion: 0.2, a: '1' },
  61. { name: '带孩子', proportion: 0.18, a: '1' },
  62. { name: '照顾老人', proportion: 0.15, a: '1' },
  63. { name: '清洁厨房', proportion: 0.05, a: '1' },
  64. { name: '其他', proportion: 0.02, a: '1' },
  65. ];
  66. chart.source(data);
  67. chart.legend(false);
  68. chart.coord('polar', {
  69. transposed: true,
  70. innerRadius: 0.5,
  71. });
  72. chart.axis(false);
  73. chart
  74. .interval()
  75. .position('a*proportion')
  76. .color('name', [
  77. '#EB6F49',
  78. '#00D98B',
  79. '#FDB628',
  80. '#0091F1',
  81. '#00E4EC',
  82. '#8256E8',
  83. ])
  84. .adjust('stack');
  85. chart.guide()
  86. .text({
  87. position: [ '50%', '50%' ],
  88. style:{
  89. fill:'#7ED4F6',
  90. fontSize:'12',
  91. },
  92. content: ` 本月共
  93. ${taskNum}条任务`,
  94. limitInPlot:true,
  95. });
  96. chart.pieLabel({
  97. sidePadding: 30,
  98. activeShape: true,
  99. label1: function label1(data) {
  100. return {
  101. text: data.name,
  102. fill: '#7ED4F6',
  103. fontWeight: 'bold'
  104. };
  105. },
  106. label2: function label2(data) {
  107. return {
  108. text: data.proportion,
  109. fill: '#7ED4F6'
  110. };
  111. },
  112. onClick: function onClick(ev) {
  113. console.log(ev.data) ;
  114. }
  115. });
  116. chart.render();
  117. // 注意:需要把chart return 出来
  118. return chart;
  119. },
  120. onInitChart2(F2, config) {
  121. // 本月任务完成情况
  122. const chart = new F2.Chart(config);
  123. let taskNum=this.data.taskNum;
  124. // chart.plugins.register([ PieLabel ]);
  125. const data = [
  126. { name: '打扫房间', proportion: 0.4, a: '1' },
  127. { name: '打扫厨房', proportion: 0.2, a: '1' },
  128. { name: '带孩子', proportion: 0.18, a: '1' },
  129. { name: '照顾老人', proportion: 0.15, a: '1' },
  130. { name: '清洁厨房', proportion: 0.05, a: '1' },
  131. { name: '其他', proportion: 0.02, a: '1' },
  132. ];
  133. chart.source(data);
  134. chart.legend(false);
  135. chart.coord('polar', {
  136. transposed: true,
  137. });
  138. chart.axis(false);
  139. chart
  140. .interval()
  141. .position('a*proportion')
  142. .color('name', [
  143. '#EB6F49',
  144. '#00D98B',
  145. '#FDB628',
  146. '#0091F1',
  147. '#00E4EC',
  148. '#8256E8',
  149. ])
  150. .adjust('stack');
  151. chart.pieLabel({
  152. sidePadding: 30,
  153. activeShape: true,
  154. label1: function label1(data) {
  155. return {
  156. text: data.name,
  157. fill: '#7ED4F6',
  158. fontWeight: 'bold'
  159. };
  160. },
  161. label2: function label2(data) {
  162. return {
  163. text: data.proportion,
  164. fill: '#7ED4F6'
  165. };
  166. },
  167. onClick: function onClick(ev) {
  168. console.log(ev.data) ;
  169. }
  170. });
  171. chart.render();
  172. // 注意:需要把chart return 出来
  173. return chart;
  174. },
  175. onInitChart4(F2, config) {
  176. // 任务类完成详细情况
  177. // 本月任务分布饼状图
  178. const chart = new F2.Chart(config);
  179. let taskNum=this.data.taskNum;
  180. // chart.plugins.register([ PieLabel ]);
  181. const data = [
  182. { name: '打扫房间', proportion: 0.4, a: '1' },
  183. { name: '打扫厨房', proportion: 0.2, a: '1' },
  184. { name: '带孩子', proportion: 0.18, a: '1' },
  185. { name: '照顾老人', proportion: 0.15, a: '1' },
  186. { name: '清洁厨房', proportion: 0.05, a: '1' },
  187. { name: '其他', proportion: 0.02, a: '1' },
  188. ];
  189. chart.source(data);
  190. chart.legend({
  191. position: 'left'
  192. });
  193. chart.coord('polar', {
  194. transposed: true,
  195. innerRadius: 0.5,
  196. });
  197. chart.axis(false);
  198. chart
  199. .interval()
  200. .position('a*proportion')
  201. .color('name', [
  202. '#EB6F49',
  203. '#00D98B',
  204. '#FDB628',
  205. '#0091F1',
  206. '#00E4EC',
  207. '#8256E8',
  208. ])
  209. .adjust('stack')
  210. .style({
  211. lineWidth: 1,
  212. stroke: '#4413A0',
  213. lineJoin: 'round',
  214. lineCap: 'round'
  215. });
  216. chart.guide()
  217. .text({
  218. position: [ '50%', '50%' ],
  219. style:{
  220. fill:'#7ED4F6',
  221. fontSize:'12',
  222. backgroundColor:'#fff',
  223. },
  224. content: `完成
  225. 占比`,
  226. limitInPlot:true,
  227. });
  228. chart.render();
  229. // 注意:需要把chart return 出来
  230. return chart;
  231. },
  232. onInitChart5(F2, config) {
  233. //任务无法完成原因
  234. const chart = new F2.Chart(config);
  235. const data = [
  236. { value: 63.4, city: 'New York', date: '2011-10-01' },
  237. { value: 62.7, city: 'Alaska', date: '2011-10-01' },
  238. { value: 72.2, city: 'Austin', date: '2011-10-01' },
  239. { value: 58, city: 'New York', date: '2011-10-02' },
  240. { value: 59.9, city: 'Alaska', date: '2011-10-02' },
  241. { value: 67.7, city: 'Austin', date: '2011-10-02' },
  242. { value: 53.3, city: 'New York', date: '2011-10-03' },
  243. { value: 59.1, city: 'Alaska', date: '2011-10-03' },
  244. { value: 69.4, city: 'Austin', date: '2011-10-03' },
  245. ];
  246. chart.source(data, {
  247. date: {
  248. range: [0, 1],
  249. type: 'timeCat',
  250. mask: 'MM-DD'
  251. },
  252. value: {
  253. max: 300,
  254. tickCount: 4
  255. }
  256. });
  257. chart.area().position('date*value').color('city').adjust('stack');
  258. chart.line().position('date*value').color('city').adjust('stack');
  259. chart.render();
  260. // 注意:需要把chart return 出来
  261. return chart;
  262. },
  263. onInitChart0(F2, config) {
  264. //折线图
  265. const chart = new F2.Chart(config);
  266. const data = [
  267. { value: 63.4, city: 'New York', date: '2011-10-01' },
  268. { value: 62.7, city: 'Alaska', date: '2011-10-01' },
  269. { value: 72.2, city: 'Austin', date: '2011-10-01' },
  270. { value: 58, city: 'New York', date: '2011-10-02' },
  271. { value: 59.9, city: 'Alaska', date: '2011-10-02' },
  272. { value: 67.7, city: 'Austin', date: '2011-10-02' },
  273. { value: 53.3, city: 'New York', date: '2011-10-03' },
  274. { value: 59.1, city: 'Alaska', date: '2011-10-03' },
  275. { value: 69.4, city: 'Austin', date: '2011-10-03' },
  276. ];
  277. chart.source(data, {
  278. date: {
  279. range: [0, 1],
  280. type: 'timeCat',
  281. mask: 'MM-DD'
  282. },
  283. value: {
  284. max: 300,
  285. tickCount: 4
  286. }
  287. });
  288. chart.area().position('date*value').color('city').adjust('stack');
  289. chart.line().position('date*value').color('city').adjust('stack');
  290. chart.render();
  291. // 注意:需要把chart return 出来
  292. return chart;
  293. },
  294. });