adShareData.vue 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <template>
  2. <div class="content">
  3. <header>分享数据</header>
  4. <div class="chart">
  5. <div class="box">
  6. <div class="title-box">
  7. <div class="title">分享次数</div>
  8. <el-radio-group v-model="tabPosition" style="margin-right:33px;" size="small">
  9. <el-radio-button label="year">年</el-radio-button>
  10. <el-radio-button label="month">月</el-radio-button>
  11. <el-radio-button label="day">日</el-radio-button>
  12. </el-radio-group>
  13. </div>
  14. <div id="container" style="width: calc(100% - 33px); height: 374px; margin-top: 40px;"></div>
  15. </div>
  16. <div class="box">
  17. <div class="title-box">
  18. <div class="title">分享渠道</div>
  19. </div>
  20. <div id="pie" style="width: calc(100% - 33px); height: 374px; margin-top: 40px;"></div>
  21. </div>
  22. </div>
  23. </div>
  24. </template>
  25. <script>
  26. import { Line, Pie } from '@antv/g2plot';
  27. export default {
  28. name: "adShareData",
  29. data() {
  30. return {
  31. tabPosition: "year",
  32. }
  33. },
  34. mounted() {
  35. /* 折线图 */
  36. fetch('https://gw.alipayobjects.com/os/bmw-prod/1d565782-dde4-4bb6-8946-ea6a38ccf184.json')
  37. .then((res) => res.json())
  38. .then((data) => {
  39. const line = new Line('container', {
  40. data,
  41. padding: '0',
  42. xField: 'Date',
  43. yField: 'scales',
  44. xAxis: {
  45. // type: 'timeCat',
  46. tickCount: 12,
  47. },
  48. yAxis: {
  49. tickCount: 9,
  50. }
  51. });
  52. line.render();
  53. });
  54. /* 饼状图 */
  55. const data = [
  56. { type: '分类一', value: 27 },
  57. { type: '分类二', value: 25 },
  58. ];
  59. const piePlot = new Pie('pie', {
  60. appendPadding: 10,
  61. data,
  62. angleField: 'value',
  63. colorField: 'type',
  64. radius: 0.75,
  65. legend: {
  66. position: 'leftTop'
  67. },
  68. label: {
  69. type: 'spider',
  70. labelHeight: 28,
  71. content: '{name}\n{percentage}',
  72. },
  73. interactions: [{ type: 'element-selected' }, { type: 'element-active' }],
  74. });
  75. piePlot.render();
  76. }
  77. }
  78. </script>
  79. <style scoped>
  80. @import url('./public.css');
  81. .chart {
  82. display: flex;
  83. justify-content: space-between;
  84. width: 100%;
  85. margin-top: 22rpx;
  86. height: 450px;
  87. }
  88. .chart .box {
  89. flex: 1;
  90. height: 50px;
  91. }
  92. </style>