增加折线
This commit is contained in:
parent
a42c3f5824
commit
06a4324b90
|
|
@ -70,6 +70,7 @@
|
||||||
<template #title>
|
<template #title>
|
||||||
<div class="card-header">
|
<div class="card-header">
|
||||||
<span class="chart-title">{{ item.title || `图表 ${index + 1}` }}</span>
|
<span class="chart-title">{{ item.title || `图表 ${index + 1}` }}</span>
|
||||||
|
<!-- 保持您原来的写法,不做任何修改 -->
|
||||||
<a-tag color="blue" size="small">{{ item.data?.length || 0 }} 项</a-tag>
|
<a-tag color="blue" size="small">{{ item.data?.length || 0 }} 项</a-tag>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
@ -288,9 +289,6 @@ const loadCategories = async () => {
|
||||||
const loadChartData = async (deployId, summaryMode, startTime) => {
|
const loadChartData = async (deployId, summaryMode, startTime) => {
|
||||||
if (!deployId) return;
|
if (!deployId) return;
|
||||||
|
|
||||||
// ✅ 先清空数据,让 tag 显示 0 项
|
|
||||||
chartDataList.value = [];
|
|
||||||
|
|
||||||
loading.value = true;
|
loading.value = true;
|
||||||
try {
|
try {
|
||||||
// 格式化日期
|
// 格式化日期
|
||||||
|
|
@ -398,7 +396,7 @@ const calculateYAxisRange = (data, markLines) => {
|
||||||
const range = allMax - allMin;
|
const range = allMax - allMin;
|
||||||
const padding = range * 0.15 || 10;
|
const padding = range * 0.15 || 10;
|
||||||
|
|
||||||
// ✅ 保留两位小数
|
// 保留两位小数
|
||||||
return {
|
return {
|
||||||
min: roundToTwo(allMin - padding),
|
min: roundToTwo(allMin - padding),
|
||||||
max: roundToTwo(allMax + padding),
|
max: roundToTwo(allMax + padding),
|
||||||
|
|
@ -476,7 +474,6 @@ const getChartOption = (item) => {
|
||||||
},
|
},
|
||||||
yAxis: {
|
yAxis: {
|
||||||
type: 'value',
|
type: 'value',
|
||||||
// ✅ 设置 y 轴范围,确保 markLine 可见(已保留两位小数)
|
|
||||||
min: yAxisRange.min !== null ? yAxisRange.min : undefined,
|
min: yAxisRange.min !== null ? yAxisRange.min : undefined,
|
||||||
max: yAxisRange.max !== null ? yAxisRange.max : undefined,
|
max: yAxisRange.max !== null ? yAxisRange.max : undefined,
|
||||||
splitLine: {
|
splitLine: {
|
||||||
|
|
@ -488,13 +485,13 @@ const getChartOption = (item) => {
|
||||||
axisLabel: {
|
axisLabel: {
|
||||||
fontSize: 11,
|
fontSize: 11,
|
||||||
color: '#888',
|
color: '#888',
|
||||||
// ✅ y轴标签也保留两位小数
|
|
||||||
formatter: (value) => {
|
formatter: (value) => {
|
||||||
return roundToTwo(value);
|
return roundToTwo(value);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
series: [
|
series: [
|
||||||
|
// ========== 柱状图(保持不变) ==========
|
||||||
{
|
{
|
||||||
name: item.title || '数据',
|
name: item.title || '数据',
|
||||||
type: 'bar',
|
type: 'bar',
|
||||||
|
|
@ -534,9 +531,9 @@ const getChartOption = (item) => {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
// ✅ 新增:折线图
|
// ========== ✅ 新增:折线图 ==========
|
||||||
{
|
{
|
||||||
name: item.title || '趋势',
|
name: `${item.title || '数据'}趋势`,
|
||||||
type: 'line',
|
type: 'line',
|
||||||
data: item.data || [],
|
data: item.data || [],
|
||||||
smooth: true,
|
smooth: true,
|
||||||
|
|
@ -557,14 +554,11 @@ const getChartOption = (item) => {
|
||||||
x2: 0,
|
x2: 0,
|
||||||
y2: 1,
|
y2: 1,
|
||||||
colorStops: [
|
colorStops: [
|
||||||
{ offset: 0, color: 'rgba(255, 107, 107, 0.3)' },
|
{ offset: 0, color: 'rgba(255, 107, 107, 0.25)' },
|
||||||
{ offset: 1, color: 'rgba(255, 107, 107, 0.05)' },
|
{ offset: 1, color: 'rgba(255, 107, 107, 0.02)' },
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
emphasis: {
|
|
||||||
focus: 'series',
|
|
||||||
},
|
|
||||||
label: {
|
label: {
|
||||||
show: true,
|
show: true,
|
||||||
position: 'top',
|
position: 'top',
|
||||||
|
|
@ -575,7 +569,9 @@ const getChartOption = (item) => {
|
||||||
return params.value;
|
return params.value;
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
// 将折线图与柱状图关联,共享 x 轴
|
emphasis: {
|
||||||
|
focus: 'series',
|
||||||
|
},
|
||||||
xAxisIndex: 0,
|
xAxisIndex: 0,
|
||||||
yAxisIndex: 0,
|
yAxisIndex: 0,
|
||||||
},
|
},
|
||||||
|
|
@ -592,8 +588,9 @@ const getChartOption = (item) => {
|
||||||
name: item.title || '数据',
|
name: item.title || '数据',
|
||||||
icon: 'roundRect',
|
icon: 'roundRect',
|
||||||
},
|
},
|
||||||
|
// ✅ 新增:折线图图例
|
||||||
{
|
{
|
||||||
name: item.title || '趋势',
|
name: `${item.title || '数据'}趋势`,
|
||||||
icon: 'line',
|
icon: 'line',
|
||||||
itemStyle: {
|
itemStyle: {
|
||||||
color: '#ff6b6b',
|
color: '#ff6b6b',
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue