NewMediaTrend.jsx 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. import { onMount } from "solid-js";
  2. import { Chart } from '@antv/g2';
  3. // import DataSet from '@antv/data-set';
  4. import "../../../assets/style/CommonBigScreenHome.css"
  5. import utils from "../../../utils/index"
  6. function DataFormmat(timeString) {
  7. if (!timeString || typeof timeString !== 'string') return "";
  8. const y = timeString[0] + timeString[1] + timeString[2] + timeString[3];
  9. const m = timeString[4] + timeString[5];
  10. const d = timeString[6] + timeString[7];
  11. return [y, m, d].join("-");
  12. }
  13. function Usertrend(prop) {
  14. let $canvas = undefined;
  15. function getlist() {
  16. const setli = [];
  17. for (let i = 0; i < (prop.list || []).length; i++) {
  18. const item = (prop.list || [])[i];
  19. (item.data || []).map(v => {
  20. setli.push({
  21. Data: DataFormmat(v.dt),
  22. value: v.readCount,
  23. type: item.name
  24. })
  25. })
  26. }
  27. return setli
  28. }
  29. function TrendChart(width, height, $canvas) {
  30. const data = getlist(), li = {};
  31. const chart = new Chart({
  32. container: $canvas,
  33. autoFit: true,
  34. height,
  35. width,
  36. padding: [
  37. 30,
  38. 40,
  39. 30,
  40. 70,
  41. ]
  42. });
  43. chart.data(data);
  44. chart.legend({
  45. position: "top",
  46. marker: {
  47. symbol: "hyphen"
  48. },
  49. itemName: {
  50. style: {
  51. fill: "#ffffff",
  52. }
  53. }
  54. });
  55. chart.scale('Data', {
  56. range: [0, 1],
  57. tickCount: 10,
  58. type: 'timeCat'
  59. });
  60. chart.axis('Data', {
  61. label: {
  62. style: {
  63. fill: "#fff"
  64. },
  65. },
  66. grid: null
  67. });
  68. chart.tooltip(false);
  69. chart.axis("value", {
  70. label: {
  71. formatter: n => {
  72. return utils.formatNumber(n, 2);
  73. },
  74. style: {
  75. fill: "#fff"
  76. },
  77. },
  78. position: "left",
  79. grid: null
  80. });
  81. chart.line().shape('smooth').color('type', [
  82. '#4fdfff',
  83. '#8b78fa',
  84. '#78d56c',
  85. '#ffcf48',
  86. '#00b2da',
  87. ]).position('Data*value');
  88. chart.area().shape('smooth').color('type', [
  89. 'l(90) 0:#4fdfff 1:rgba(0,0,0,0)',
  90. 'l(90) 0:#8b78fa 1:rgba(0,0,0,0)',
  91. 'l(90) 0:#78d56c 1:rgba(0,0,0,0)',
  92. 'l(90) 0:#ffcf48 1:rgba(0,0,0,0)',
  93. 'l(90) 0:#00b2da 1:rgba(0,0,0,0)',
  94. ]).position('Data*value');
  95. chart.scale(li);
  96. chart.render();
  97. }
  98. onMount(() => {
  99. TrendChart(prop.width, prop.height, $canvas)
  100. })
  101. return (
  102. <div class="livRang" style={{
  103. width: `${prop.width}px`
  104. }}>
  105. <div class="head">{prop.title}</div>
  106. <div ref={$canvas}></div>
  107. </div>
  108. );
  109. }
  110. export default Usertrend;