F2.ts 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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 title = this.data.DayList.length ? `${this.data.DayList[0].dt}至${this.data.DayList[0].dt}` : "";
  11. const data = this.data.DayList.map((v: any, i: number) => {
  12. v.type = title
  13. v.index = i
  14. v.timeSize = v.timeSize * 100
  15. return v
  16. });
  17. if (chartCatch.toufangfenxiChart === undefined) return;
  18. chartCatch.toufangfenxiChart.legend('gender', {
  19. position: 'right'
  20. });
  21. chartCatch.toufangfenxiChart.source(data);
  22. chartCatch.toufangfenxiChart.scale('index', {
  23. tickCount: 3
  24. });
  25. chartCatch.toufangfenxiChart.axis('index', {
  26. label: (text: string, index: number, total: number) => {
  27. let align = 'center';
  28. if (index === 0) align = 'left';
  29. if (index === total - 1) align = 'right';
  30. return {
  31. textAlign: align,
  32. text: data[Number(text)].hour + '点'
  33. }
  34. }
  35. });
  36. chartCatch.toufangfenxiChart.axis('timeSize', {
  37. label: (text: string, index: number, total: number) => {
  38. return {
  39. text: formmaterValueZhou(text, 0) + '%'
  40. }
  41. }
  42. });
  43. chartCatch.toufangfenxiChart.tooltip({
  44. showCrosshairs: true,
  45. triggerOn: ['touchstart', 'touchmove'],
  46. onShow: (ev: tooltipOnShow) => {
  47. const items = ev.items;
  48. const { tooltip: { title } } = ev;
  49. let index = Number(title || 0);
  50. index < 0 ? index = 0 : "";
  51. let nT = data[index].hour > 9 ? Number(data[index].hour) + 1 : '0' + (Number(data[index].hour) + 1);
  52. items[0].name = data[index].hour + '~' + nT;
  53. items[0].value = formmaterValueZhou(items[0].value, 2) + '%';
  54. }
  55. });
  56. chartCatch.toufangfenxiChart.interval().position('index*timeSize').shape('smooth').color("index", ["#1b9ade"]).adjust({
  57. type: 'dodge',
  58. marginRatio: 0.05 // 设置分组间柱子的间距
  59. });
  60. chartCatch.toufangfenxiChart.render();
  61. },
  62. line(F2: any, config: any) {
  63. if (chartCatch.toufangfenxiChart !== undefined) chartCatch.toufangfenxiChart.destroy(), chartCatch.toufangfenxiChart = undefined;
  64. let sys = wx.getSystemInfoSync();
  65. config.height = sys.windowWidth / 16 * 9;
  66. chartCatch.toufangfenxiChart = new F2.Chart(config);
  67. let title = this.data.DayList.length ? `${this.data.DayList[0].dt}至${this.data.DayList[0].dt}` : "";
  68. const data = this.data.DayList.map((v: any, i: number) => {
  69. v.type = title
  70. v.index = i
  71. v.timeSize = v.timeSize * 100
  72. return v
  73. });
  74. if (chartCatch.toufangfenxiChart === undefined) return;
  75. chartCatch.toufangfenxiChart.legend('gender', {
  76. position: 'right'
  77. });
  78. chartCatch.toufangfenxiChart.source(data);
  79. chartCatch.toufangfenxiChart.scale('index', {
  80. tickCount: 3
  81. });
  82. chartCatch.toufangfenxiChart.axis('index', {
  83. label: (text: string, index: number, total: number) => {
  84. let align = 'center';
  85. if (index === 0) align = 'left';
  86. if (index === total - 1) align = 'right';
  87. return {
  88. textAlign: align,
  89. text: data[Number(text)].hour + '点'
  90. }
  91. }
  92. });
  93. chartCatch.toufangfenxiChart.axis('timeSize', {
  94. label: (text: string, index: number, total: number) => {
  95. return {
  96. text: formmaterValueZhou(text, 0) + '%'
  97. }
  98. }
  99. });
  100. chartCatch.toufangfenxiChart.tooltip({
  101. showCrosshairs: true,
  102. triggerOn: ['touchstart', 'touchmove'],
  103. onShow: (ev: tooltipOnShow) => {
  104. const items = ev.items;
  105. const { tooltip: { title } } = ev;
  106. let index = Number(title || 0);
  107. index < 0 ? index = 0 : "";
  108. let nT = data[index].hour > 9 ? Number(data[index].hour) + 1 : '0' + (Number(data[index].hour) + 1);
  109. if (data[index].hour === '平均值') {
  110. items[0].name = data[index].hour;
  111. } else items[0].name = data[index].hour + '~' + nT;
  112. items[0].value = formmaterValueZhou(items[0].value, 2) + '%';
  113. }
  114. });
  115. chartCatch.toufangfenxiChart.interval().position('index*timeSize').shape('smooth').color("index", ["#1b9ade"]).adjust({
  116. type: 'dodge',
  117. marginRatio: 0.05 // 设置分组间柱子的间距
  118. });
  119. let linkey = data[data.length - 1].timeSize || 0
  120. chartCatch.toufangfenxiChart.guide().line({
  121. start: [ 'min', linkey ],
  122. end: [ 'max', linkey ],
  123. style: {
  124. stroke: '#1b9ade',
  125. lineWidth: 1,
  126. lineCap: 'round'
  127. }
  128. });
  129. chartCatch.toufangfenxiChart.render();
  130. return chartCatch.toufangfenxiChart;
  131. }
  132. };
  133. module.exports = F2Chart;
  134. }