fix: add defensive checks to BudgetChartAnalysis chart data
- Added null checks for overallStats.month/year in gauge charts - Added null checks for burndown and year burndown charts - Fixed BaseChart.vue template using undefined 'chartData' variable - Changed :data="chartData" to :data="data" to use prop directly Fixes console errors when viewing /budget-v2 page Verified: 0 errors, only 1 harmless plugin warning Refs: openspec/changes/migrate-remaining-echarts-to-chartjs
This commit is contained in:
@@ -261,6 +261,19 @@ const formatMoney = (val) => {
|
||||
|
||||
// 月度仪表盘数据
|
||||
const monthGaugeData = computed(() => {
|
||||
// 防御性检查:如果数据未加载,返回默认结构
|
||||
if (!props.overallStats || !props.overallStats.month) {
|
||||
return {
|
||||
datasets: [{
|
||||
data: [0, 100],
|
||||
backgroundColor: [getCssVar('--chart-axis'), getCssVar('--chart-axis')],
|
||||
borderWidth: 0,
|
||||
circumference: 180,
|
||||
rotation: 270
|
||||
}]
|
||||
}
|
||||
}
|
||||
|
||||
const rate = parseFloat(props.overallStats.month.rate || 0)
|
||||
const isExpense = props.activeTab === BudgetCategory.Expense
|
||||
|
||||
@@ -329,6 +342,19 @@ const monthGaugeOptions = computed(() => {
|
||||
|
||||
// 年度仪表盘数据
|
||||
const yearGaugeData = computed(() => {
|
||||
// 防御性检查:如果数据未加载,返回默认结构
|
||||
if (!props.overallStats || !props.overallStats.year) {
|
||||
return {
|
||||
datasets: [{
|
||||
data: [0, 100],
|
||||
backgroundColor: [getCssVar('--chart-axis'), getCssVar('--chart-axis')],
|
||||
borderWidth: 0,
|
||||
circumference: 180,
|
||||
rotation: 270
|
||||
}]
|
||||
}
|
||||
}
|
||||
|
||||
const rate = parseFloat(props.overallStats.year.rate || 0)
|
||||
const isExpense = props.activeTab === BudgetCategory.Expense
|
||||
|
||||
@@ -493,6 +519,14 @@ const varianceChartOptions = computed(() => {
|
||||
|
||||
// 月度燃尽图数据
|
||||
const burndownChartData = computed(() => {
|
||||
// 防御性检查
|
||||
if (!props.overallStats || !props.overallStats.month || !props.selectedDate) {
|
||||
return {
|
||||
labels: [],
|
||||
datasets: []
|
||||
}
|
||||
}
|
||||
|
||||
const refDate = props.selectedDate
|
||||
const year = refDate.getFullYear()
|
||||
const month = refDate.getMonth()
|
||||
@@ -623,6 +657,14 @@ const burndownChartOptions = computed(() => {
|
||||
|
||||
// 年度燃尽图数据
|
||||
const yearBurndownChartData = computed(() => {
|
||||
// 防御性检查
|
||||
if (!props.overallStats || !props.overallStats.year || !props.selectedDate) {
|
||||
return {
|
||||
labels: [],
|
||||
datasets: []
|
||||
}
|
||||
}
|
||||
|
||||
const refDate = props.selectedDate
|
||||
const year = refDate.getFullYear()
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<component
|
||||
v-else
|
||||
:is="chartComponent"
|
||||
:data="chartData"
|
||||
:data="data"
|
||||
:options="mergedOptions"
|
||||
:plugins="chartPlugins"
|
||||
@chart:render="onChartRender"
|
||||
|
||||
Reference in New Issue
Block a user