F2.ts 5.4 KB

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