+
@@ -26,4 +72,7 @@ useSetPieChart(pieChart, series, { title: false, legend: false });
border-radius: 8px;
box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
}
+.charts {
+ width: calc(100vw - 50px);
+}
diff --git a/src/hooks/chart/data/pie.ts b/src/hooks/chart/data/pie.ts
index 93bd70e..e4c7b7e 100644
--- a/src/hooks/chart/data/pie.ts
+++ b/src/hooks/chart/data/pie.ts
@@ -11,18 +11,14 @@ const option = {
// orient: 'vertical',
// left: 'left'
// },
+ label: {
+ formatter: '{b},{c}'
+ },
series: [
{
name: 'Access From',
type: 'pie',
- radius: '50%',
- data: [
- { value: 1048, name: 'Search Engine' },
- { value: 735, name: 'Direct' },
- { value: 580, name: 'Email' },
- { value: 484, name: 'Union Ads' },
- { value: 300, name: 'Video Ads' }
- ],
+ data: [],
emphasis: {
itemStyle: {
shadowBlur: 10,
@@ -34,4 +30,4 @@ const option = {
]
};
-export const pieOption = option;
\ No newline at end of file
+export const pieOption = option;
diff --git a/src/hooks/chart/usePieChart.ts b/src/hooks/chart/usePieChart.ts
index 0ff9b31..0cbf91f 100644
--- a/src/hooks/chart/usePieChart.ts
+++ b/src/hooks/chart/usePieChart.ts
@@ -23,16 +23,24 @@ function useSetPieChart(
// 在 dom 挂载之后,显示饼图
chartInstance = chart.init(dom.value);
pieOption.series = JSON.parse(JSON.stringify(series.value));
-
- console.log(pieOption);
-
// 设置图表选项
chartInstance.setOption(pieOption, opts);
});
// 如果 data 变动,重新生成图表w
watch(series, (value) => {
- chartInstance.setOption(value, opts);
+ console.log(value);
+
+ const currentOptions = chartInstance.getOption();
+
+ // 合并新的 series 数据到现有配置中
+ chartInstance.setOption(
+ {
+ ...currentOptions,
+ series: JSON.parse(JSON.stringify(value)) // 确保深拷贝防止引用污染
+ },
+ opts
+ );
});
}
diff --git a/src/views/Survey/views/Analysis/components/AnalysisInfo/Index.vue b/src/views/Survey/views/Analysis/components/AnalysisInfo/Index.vue
index 13e66bf..b211b34 100644
--- a/src/views/Survey/views/Analysis/components/AnalysisInfo/Index.vue
+++ b/src/views/Survey/views/Analysis/components/AnalysisInfo/Index.vue
@@ -6,11 +6,15 @@
}}
{{ analysis.stem }}
-
+
@@ -23,21 +27,39 @@
import { questionAnalysis } from '../../hooks/useAnalysis';
import { questionTypeMap } from '@/utils/question/typeMapping';
import ChartMsg from '@/components/Analysis/Index.vue';
-import { formatData } from './hooks/pieSeries';
+import { getTableData } from './hooks/pieSeries';
import YlTable from '@/components/YlTable/Index.vue';
import { ref } from 'vue';
// questionTypeMap 自己去对应
-const showChart = ref([1, 2, 5, 106, 8, 9, 10]);
+const showChart = ref([1, 2, 5, 106, 9, 10]);
// const showTable = ref([1,2,4])
-const getTableHeadProps = (values: any[]) => {
- return values.map((item: Object) => {
- return {
- label: item.title,
- prop: item.key
- };
- });
+
+// 构建表头
+const getTableHeadProps = (values: any[], option) => {
+ const head = [];
+
+ if (values && values.length > 0) {
+ values.forEach((item: any) => {
+ if (item.key !== 'option') {
+ head.push({
+ label: item.title,
+ prop: item.key,
+ width: 120
+ });
+ }
+ });
+ }
+ if (option && option.length > 0 && option[0].option) {
+ head.unshift({
+ label: '选项',
+ prop: 'option',
+ width: 150
+ });
+ }
+ return head;
};
+// 构建表格数据