F2.ts 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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 { softData, hardData } = this.data.DayList;
  11. softData = softData.map((v: any, i: number) => {
  12. v.index = i;
  13. v.timeSize = Number((v.timeSize/60).toFixed(2))
  14. v.dataKeyTypt = '软广';
  15. return v
  16. })
  17. hardData = hardData.map((v: any, i: number) => {
  18. v.index = i;
  19. v.timeSize = Number((v.timeSize/60).toFixed(2))
  20. v.dataKeyTypt = '硬广';
  21. return v
  22. })
  23. const data = [ ...hardData,...softData], week = ['一','二','三','四','五','六','日'];
  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: '周' + week[Number(text)]
  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].dataKeyTypt;
  60. items[1].name = data[index + this.data.DayList.softData.length].dataKeyTypt;
  61. console.log(data[index])
  62. items[0].value = formmaterValueZhou(items[0].value, 2);
  63. items[1].value = formmaterValueZhou(items[1].value, 2);
  64. }
  65. });
  66. chartCatch.toufangfenxiChart.interval().position('index*' + key).shape('smooth').color("dataKeyTypt", ["#1b9ade", "#fd5555"]).adjust({
  67. type: 'dodge',
  68. marginRatio: 0 // 设置分组间柱子的间距
  69. });
  70. chartCatch.toufangfenxiChart.render();
  71. },
  72. line(F2: any, config: any) {
  73. if (chartCatch.toufangfenxiChart !== undefined) chartCatch.toufangfenxiChart.destroy(), chartCatch.toufangfenxiChart = undefined;
  74. let sys = wx.getSystemInfoSync();
  75. config.height = sys.windowWidth / 16 * 9;
  76. chartCatch.toufangfenxiChart = new F2.Chart(config);
  77. let { softData, hardData } = this.data.DayList;
  78. softData = softData.map((v: any, i: number) => {
  79. v.index = i;
  80. v.timeSize = Number((v.timeSize/60).toFixed(2))
  81. v.dataKeyTypt = '软广';
  82. return v
  83. })
  84. hardData = hardData.map((v: any, i: number) => {
  85. v.index = i;
  86. v.timeSize = Number((v.timeSize/60).toFixed(2))
  87. v.dataKeyTypt = '硬广';
  88. return v
  89. })
  90. const data = [ ...hardData,...softData], week = ['一','二','三','四','五','六','日'];
  91. if (chartCatch.toufangfenxiChart === undefined) return;
  92. let key = this.data.select[this.data.select_act].proportionType;
  93. chartCatch.toufangfenxiChart.legend('gender', {
  94. position: 'right'
  95. });
  96. chartCatch.toufangfenxiChart.source(data);
  97. chartCatch.toufangfenxiChart.scale('index', {
  98. tickCount: 7
  99. });
  100. chartCatch.toufangfenxiChart.axis('index', {
  101. label: (text: string, index: number, total: number) => {
  102. let align = 'center';
  103. if (index === 0) align = 'left';
  104. if (index === total - 1) align = 'right';
  105. return {
  106. textAlign: align,
  107. text: '周' + week[Number(text)]
  108. }
  109. }
  110. });
  111. chartCatch.toufangfenxiChart.axis(key, {
  112. label: (text: string, index: number, total: number) => {
  113. return {
  114. text: formmaterValueZhou(text, 0)
  115. }
  116. }
  117. });
  118. chartCatch.toufangfenxiChart.tooltip({
  119. showCrosshairs: true,
  120. triggerOn: ['touchstart', 'touchmove'],
  121. onShow: (ev: tooltipOnShow) => {
  122. const items = ev.items;
  123. const { tooltip: { title } } = ev;
  124. let index = Number(title || 0);
  125. index < 0 ? index = 0 : "";
  126. items[0].name = data[index].dataKeyTypt;
  127. items[1].name = data[index + this.data.DayList.softData.length].dataKeyTypt;
  128. console.log(data[index])
  129. items[0].value = formmaterValueZhou(items[0].value, 2);
  130. items[1].value = formmaterValueZhou(items[1].value, 2);
  131. }
  132. });
  133. chartCatch.toufangfenxiChart.interval().position('index*' + key).shape('smooth').color("dataKeyTypt", ["#1b9ade", "#fd5555"]).adjust({
  134. type: 'dodge',
  135. marginRatio: 0 // 设置分组间柱子的间距
  136. });
  137. chartCatch.toufangfenxiChart.render();
  138. return chartCatch.toufangfenxiChart;
  139. }
  140. };
  141. module.exports = F2Chart;
  142. }