ChartConfig.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <!--
  2. - Copyright (c) 2024 LangChat. TyCoding All Rights Reserved.
  3. -
  4. - Licensed under the GNU Affero General Public License, Version 3 (the "License");
  5. - you may not use this file except in compliance with the License.
  6. - You may obtain a copy of the License at
  7. -
  8. - https://www.gnu.org/licenses/agpl-3.0.html
  9. -
  10. - Unless required by applicable law or agreed to in writing, software
  11. - distributed under the License is distributed on an "AS IS" BASIS,
  12. - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. - See the License for the specific language governing permissions and
  14. - limitations under the License.
  15. -->
  16. <script lang="ts" setup>
  17. import { use } from 'echarts/core';
  18. import { CanvasRenderer } from 'echarts/renderers';
  19. import { PieChart, LineChart } from 'echarts/charts';
  20. import {
  21. TitleComponent,
  22. TooltipComponent,
  23. LegendComponent,
  24. GridComponent,
  25. ToolboxComponent,
  26. } from 'echarts/components';
  27. import VChart from 'vue-echarts';
  28. import { ref, watch } from 'vue';
  29. import BaseConfig from './component/BaseConfig.vue';
  30. import PieConfig from './component/PieConfig.vue';
  31. import LineConfig from './component/LineConfig.vue';
  32. import CodeConfig from '@/views/modules/chart/components/component/CodeConfig.vue';
  33. import { useChartStore } from '@/views/modules/chart/store';
  34. use([
  35. CanvasRenderer,
  36. PieChart,
  37. LineChart,
  38. TitleComponent,
  39. GridComponent,
  40. TooltipComponent,
  41. LegendComponent,
  42. ToolboxComponent,
  43. ]);
  44. const chartStore = useChartStore();
  45. const option = ref({
  46. title: {
  47. text: 'Title',
  48. left: 'center',
  49. },
  50. legend: {
  51. orient: 'vertical',
  52. left: 'left',
  53. data: ['Direct', 'Email', 'Ad Networks', 'Video Ads', 'Search Engines'],
  54. },
  55. tooltip: {
  56. show: true,
  57. },
  58. series: [
  59. {
  60. name: 'Traffic Sources',
  61. type: 'pie',
  62. radius: '55%',
  63. center: ['50%', '60%'],
  64. data: [
  65. { value: 335, name: 'Direct' },
  66. { value: 310, name: 'Email' },
  67. { value: 234, name: 'Ad Networks' },
  68. { value: 135, name: 'Video Ads' },
  69. { value: 1548, name: 'Search Engines' },
  70. ],
  71. emphasis: {
  72. itemStyle: {
  73. shadowBlur: 10,
  74. shadowOffsetX: 0,
  75. shadowColor: 'rgba(0, 0, 0, 0.5)',
  76. },
  77. },
  78. },
  79. ],
  80. });
  81. watch(
  82. () => chartStore.data,
  83. (val: Object) => {
  84. console.log(val);
  85. // option.value = val;
  86. }
  87. );
  88. function onUpdate(val: string) {
  89. option.value = JSON.parse(val);
  90. }
  91. </script>
  92. <template>
  93. <div class="w-full h-full p-1 flex flex-row gap-2">
  94. <div
  95. class="w-9/12 flex justify-center items-center border rounded-xl"
  96. style="height: calc(100vh - 200px)"
  97. >
  98. <div class="h-[85%] w-[80%] rounded-md p-6 pt-4">
  99. <VChart :option="option" autoresize />
  100. </div>
  101. </div>
  102. <n-scrollbar class="!w-3/12" style="height: calc(100vh - 200px)">
  103. <div v-if="option" class="flex flex-col gap-2 p-2">
  104. <n-collapse expanded-names="1">
  105. <BaseConfig :option="option" />
  106. <LineConfig :option="option" />
  107. <PieConfig :option="option" />
  108. <CodeConfig :option="option" @update="onUpdate" />
  109. </n-collapse>
  110. </div>
  111. </n-scrollbar>
  112. </div>
  113. </template>
  114. <style lang="less" scoped>
  115. ::v-deep(.n-collapse .n-collapse-item:not(:first-child)) {
  116. border: none !important;
  117. margin: 6px 0 0 0;
  118. }
  119. </style>