|
@@ -215,10 +215,10 @@ const chartOption = computed(() => {
|
|
}
|
|
}
|
|
},
|
|
},
|
|
grid: {
|
|
grid: {
|
|
- left: '3%',
|
|
|
|
- right: '4%',
|
|
|
|
- bottom: '3%',
|
|
|
|
- top: '10%',
|
|
|
|
|
|
+ left: '10%',
|
|
|
|
+ right: '5%',
|
|
|
|
+ bottom: '15%',
|
|
|
|
+ top: '15%',
|
|
containLabel: true
|
|
containLabel: true
|
|
},
|
|
},
|
|
...props.options
|
|
...props.options
|
|
@@ -244,7 +244,8 @@ const chartOption = computed(() => {
|
|
|
|
|
|
// 图表生成方法
|
|
// 图表生成方法
|
|
const generateLineChart = (baseOption) => {
|
|
const generateLineChart = (baseOption) => {
|
|
- const xData = props.data.map(item => item[props.xAxisKey])
|
|
|
|
|
|
+ // 获取唯一的X轴数据(日期)
|
|
|
|
+ const xData = [...new Set(props.data.map(item => item[props.xAxisKey]))].sort()
|
|
const series = extractSeries()
|
|
const series = extractSeries()
|
|
|
|
|
|
return {
|
|
return {
|
|
@@ -258,7 +259,11 @@ const generateLineChart = (baseOption) => {
|
|
}
|
|
}
|
|
},
|
|
},
|
|
axisLabel: {
|
|
axisLabel: {
|
|
- color: 'var(--sa-subfont)'
|
|
|
|
|
|
+ color: 'var(--sa-subfont)',
|
|
|
|
+ rotate: 45,
|
|
|
|
+ interval: 'auto',
|
|
|
|
+ fontSize: 12,
|
|
|
|
+ margin: 8
|
|
}
|
|
}
|
|
},
|
|
},
|
|
yAxis: {
|
|
yAxis: {
|
|
@@ -269,14 +274,18 @@ const generateLineChart = (baseOption) => {
|
|
}
|
|
}
|
|
},
|
|
},
|
|
axisLabel: {
|
|
axisLabel: {
|
|
- color: 'var(--sa-subfont)'
|
|
|
|
|
|
+ color: 'var(--sa-subfont)',
|
|
|
|
+ fontSize: 12,
|
|
|
|
+ margin: 12
|
|
},
|
|
},
|
|
splitLine: {
|
|
splitLine: {
|
|
lineStyle: {
|
|
lineStyle: {
|
|
color: 'var(--sa-space)',
|
|
color: 'var(--sa-space)',
|
|
type: 'dashed'
|
|
type: 'dashed'
|
|
}
|
|
}
|
|
- }
|
|
|
|
|
|
+ },
|
|
|
|
+ // 优化Y轴刻度间隔
|
|
|
|
+ minInterval: 1
|
|
},
|
|
},
|
|
series: series.map(s => ({
|
|
series: series.map(s => ({
|
|
...s,
|
|
...s,
|
|
@@ -295,7 +304,8 @@ const generateLineChart = (baseOption) => {
|
|
}
|
|
}
|
|
|
|
|
|
const generateBarChart = (baseOption) => {
|
|
const generateBarChart = (baseOption) => {
|
|
- const xData = props.data.map(item => item[props.xAxisKey])
|
|
|
|
|
|
+ // 获取唯一的X轴数据(日期)
|
|
|
|
+ const xData = [...new Set(props.data.map(item => item[props.xAxisKey]))].sort()
|
|
const series = extractSeries()
|
|
const series = extractSeries()
|
|
|
|
|
|
return {
|
|
return {
|
|
@@ -309,7 +319,11 @@ const generateBarChart = (baseOption) => {
|
|
}
|
|
}
|
|
},
|
|
},
|
|
axisLabel: {
|
|
axisLabel: {
|
|
- color: 'var(--sa-subfont)'
|
|
|
|
|
|
+ color: 'var(--sa-subfont)',
|
|
|
|
+ rotate: 45,
|
|
|
|
+ interval: 'auto',
|
|
|
|
+ fontSize: 12,
|
|
|
|
+ margin: 8
|
|
}
|
|
}
|
|
},
|
|
},
|
|
yAxis: {
|
|
yAxis: {
|
|
@@ -320,14 +334,18 @@ const generateBarChart = (baseOption) => {
|
|
}
|
|
}
|
|
},
|
|
},
|
|
axisLabel: {
|
|
axisLabel: {
|
|
- color: 'var(--sa-subfont)'
|
|
|
|
|
|
+ color: 'var(--sa-subfont)',
|
|
|
|
+ fontSize: 12,
|
|
|
|
+ margin: 12
|
|
},
|
|
},
|
|
splitLine: {
|
|
splitLine: {
|
|
lineStyle: {
|
|
lineStyle: {
|
|
color: 'var(--sa-space)',
|
|
color: 'var(--sa-space)',
|
|
type: 'dashed'
|
|
type: 'dashed'
|
|
}
|
|
}
|
|
- }
|
|
|
|
|
|
+ },
|
|
|
|
+ // 优化Y轴刻度间隔
|
|
|
|
+ minInterval: 1
|
|
},
|
|
},
|
|
series: series.map(s => ({
|
|
series: series.map(s => ({
|
|
...s,
|
|
...s,
|
|
@@ -456,27 +474,38 @@ const generateFunnelChart = (baseOption) => {
|
|
const extractSeries = () => {
|
|
const extractSeries = () => {
|
|
if (!props.data || props.data.length === 0) return []
|
|
if (!props.data || props.data.length === 0) return []
|
|
|
|
|
|
|
|
+ // 获取唯一的X轴数据(日期)
|
|
|
|
+ const xData = [...new Set(props.data.map(item => item[props.xAxisKey]))].sort()
|
|
|
|
+
|
|
// 如果数据中有series字段,按series分组
|
|
// 如果数据中有series字段,按series分组
|
|
if (props.data[0][props.seriesKey]) {
|
|
if (props.data[0][props.seriesKey]) {
|
|
const seriesMap = new Map()
|
|
const seriesMap = new Map()
|
|
|
|
|
|
|
|
+ // 初始化所有系列
|
|
props.data.forEach(item => {
|
|
props.data.forEach(item => {
|
|
const seriesName = item[props.seriesKey]
|
|
const seriesName = item[props.seriesKey]
|
|
if (!seriesMap.has(seriesName)) {
|
|
if (!seriesMap.has(seriesName)) {
|
|
- seriesMap.set(seriesName, [])
|
|
|
|
|
|
+ seriesMap.set(seriesName, new Map())
|
|
}
|
|
}
|
|
- seriesMap.get(seriesName).push(item[props.yAxisKey])
|
|
|
|
|
|
+ // 按X轴值存储Y轴值
|
|
|
|
+ seriesMap.get(seriesName).set(item[props.xAxisKey], item[props.yAxisKey])
|
|
})
|
|
})
|
|
|
|
|
|
- return Array.from(seriesMap.entries()).map(([name, data]) => ({
|
|
|
|
|
|
+ // 根据X轴顺序构建数据
|
|
|
|
+ return Array.from(seriesMap.entries()).map(([name, dataMap]) => ({
|
|
name,
|
|
name,
|
|
- data
|
|
|
|
|
|
+ data: xData.map(xValue => dataMap.get(xValue) || 0)
|
|
}))
|
|
}))
|
|
} else {
|
|
} else {
|
|
// 单系列数据
|
|
// 单系列数据
|
|
|
|
+ const dataMap = new Map()
|
|
|
|
+ props.data.forEach(item => {
|
|
|
|
+ dataMap.set(item[props.xAxisKey], item[props.yAxisKey])
|
|
|
|
+ })
|
|
|
|
+
|
|
return [{
|
|
return [{
|
|
name: props.title,
|
|
name: props.title,
|
|
- data: props.data.map(item => item[props.yAxisKey])
|
|
|
|
|
|
+ data: xData.map(xValue => dataMap.get(xValue) || 0)
|
|
}]
|
|
}]
|
|
}
|
|
}
|
|
}
|
|
}
|