F2.ts 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. namespace shiduan {
  2. const { formmaterValueZhou } = require("../../../../utils/util")
  3. const chartCatch: antvChart = {
  4. toufangfenxiChart: undefined
  5. }
  6. const F2Chart = {
  7. upLine() {
  8. if (chartCatch.toufangfenxiChart === undefined) return
  9. chartCatch.toufangfenxiChart.clear()
  10. let { before, now } = this.data.DayList;
  11. let beforeString = before.length ? `${before[0].dts}至${before[0].dte}` : "";
  12. let nowString = now.length ? `${now[0].dts}至${now[0].dte}` : "";
  13. before = before.map((v: any, i: number) => {
  14. v.index = i;
  15. v.dataKeyTypt = beforeString;
  16. return v
  17. })
  18. now = now.map((v: any, i: number) => {
  19. v.index = i;
  20. v.dataKeyTypt = nowString;
  21. return v
  22. })
  23. const data = [...before, ...now];
  24. if (chartCatch.toufangfenxiChart === undefined) return;
  25. let key = this.data.select[this.data.select_act].proportionType;
  26. chartCatch.toufangfenxiChart.legend('gender', {
  27. position: 'right'
  28. });
  29. chartCatch.toufangfenxiChart.source(data);
  30. chartCatch.toufangfenxiChart.scale('index', {
  31. tickCount: 6
  32. });
  33. chartCatch.toufangfenxiChart.axis('index', {
  34. label: (text: string, index: number, total: number) => {
  35. let align = 'center';
  36. if (index === 0) align = 'left';
  37. if (index === total - 1) align = 'right';
  38. let hour :string|number = Number(data[Number(text)].hour)
  39. if(hour >= 24) hour = '24';
  40. else hour = data[Number(text)].hour
  41. return {
  42. textAlign: align,
  43. text: hour
  44. }
  45. }
  46. });
  47. chartCatch.toufangfenxiChart.axis(key, {
  48. label: (text: string, index: number, total: number) => {
  49. return {
  50. text: formmaterValueZhou(text, 0)
  51. }
  52. }
  53. });
  54. chartCatch.toufangfenxiChart.tooltip({
  55. showCrosshairs: true,
  56. triggerOn: ['touchstart', 'touchmove'],
  57. onShow: (ev: tooltipOnShow) => {
  58. const items = ev.items;
  59. const { tooltip: { title } } = ev;
  60. let index = Number(title || 0);
  61. index < 0 ? index = 0 : "";
  62. items[0].name = data[index].hour;
  63. items[1].name = data[index + this.data.DayList.before.length].hour;
  64. items[0].value = formmaterValueZhou(items[0].value, 2);
  65. items[1].value = formmaterValueZhou(items[1].value, 2);
  66. }
  67. });
  68. chartCatch.toufangfenxiChart.interval().position('index*' + key).shape('smooth').color("dataKeyTypt", ["#1b9ade", "#fd5555"]).adjust({
  69. type: 'dodge',
  70. marginRatio: 0.05 // 设置分组间柱子的间距
  71. });
  72. chartCatch.toufangfenxiChart.render();
  73. },
  74. line(F2: any, config: any) {
  75. if (chartCatch.toufangfenxiChart !== undefined) chartCatch.toufangfenxiChart.destroy(), chartCatch.toufangfenxiChart = undefined;
  76. let sys = wx.getSystemInfoSync();
  77. config.height = sys.windowWidth / 16 * 9;
  78. chartCatch.toufangfenxiChart = new F2.Chart(config);
  79. let { before, now } = this.data.DayList;
  80. let beforeString = before.length ? `${before[0].dts}至${before[0].dte}` : "";
  81. let nowString = now.length ? `${now[0].dts}至${now[0].dte}` : "";
  82. before = before.map((v: any, i: number) => {
  83. v.index = i;
  84. v.dataKeyTypt = beforeString;
  85. return v
  86. })
  87. now = now.map((v: any, i: number) => {
  88. v.index = i;
  89. v.dataKeyTypt = nowString;
  90. return v
  91. })
  92. const data = [...before, ...now];
  93. if (chartCatch.toufangfenxiChart === undefined) return;
  94. let key = this.data.select[this.data.select_act].proportionType;
  95. chartCatch.toufangfenxiChart.legend('gender', {
  96. position: 'right'
  97. });
  98. chartCatch.toufangfenxiChart.source(data);
  99. chartCatch.toufangfenxiChart.scale('index', {
  100. tickCount: 6
  101. });
  102. chartCatch.toufangfenxiChart.axis('index', {
  103. label: (text: string, index: number, total: number) => {
  104. let align = 'center';
  105. if (index === 0) align = 'left';
  106. if (index === total - 1) align = 'right';
  107. let hour :string|number = Number(data[Number(text)].hour)
  108. if(hour >= 24) hour = '24';
  109. else hour = data[Number(text)].hour
  110. return {
  111. textAlign: align,
  112. text: hour
  113. }
  114. }
  115. });
  116. chartCatch.toufangfenxiChart.axis(key, {
  117. label: (text: string, index: number, total: number) => {
  118. return {
  119. text: formmaterValueZhou(text, 0)
  120. }
  121. }
  122. });
  123. chartCatch.toufangfenxiChart.tooltip({
  124. showCrosshairs: true,
  125. triggerOn: ['touchstart', 'touchmove'],
  126. onShow: (ev: tooltipOnShow) => {
  127. const items = ev.items;
  128. const { tooltip: { title } } = ev;
  129. let index = Number(title || 0);
  130. index < 0 ? index = 0 : "";
  131. items[0].name = data[index].hour;
  132. items[1].name = data[index + this.data.DayList.before.length].hour;
  133. items[0].value = formmaterValueZhou(items[0].value, 2);
  134. items[1].value = formmaterValueZhou(items[1].value, 2);
  135. }
  136. });
  137. chartCatch.toufangfenxiChart.interval().position('index*' + key).shape('smooth').color("dataKeyTypt", ["#1b9ade", "#fd5555"]).adjust({
  138. type: 'dodge',
  139. marginRatio: 0.05 // 设置分组间柱子的间距
  140. });
  141. chartCatch.toufangfenxiChart.render();
  142. return chartCatch.toufangfenxiChart;
  143. }
  144. };
  145. module.exports = F2Chart;
  146. }