-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHomeContent.vue
More file actions
99 lines (89 loc) · 3.08 KB
/
Copy pathHomeContent.vue
File metadata and controls
99 lines (89 loc) · 3.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<script setup lang="ts">
import { ref } from 'vue';
import 'devextreme/dist/css/dx.fluent.blue.light.css';
import DxChart, { DxBackgroundColor, DxCommonPaneSettings, DxConstantLine, DxLabel, DxSeries, DxTooltip, DxValueAxis } from 'devextreme-vue/chart';
import { registerGradient } from 'devextreme-vue/common/charts';
import { formatNumber } from 'devextreme/localization';
const chartData = [
{ month: 'January', targetSpend: 12000, actualSpend: 9500 },
{ month: 'February', targetSpend: 15500, actualSpend: 16500 },
{ month: 'March', targetSpend: 13500, actualSpend: 12000 },
{ month: 'April', targetSpend: 16000, actualSpend: 14000 },
{ month: 'May', targetSpend: 17000, actualSpend: 18500 },
{ month: 'June', targetSpend: 20000, actualSpend: 17500 },
{ month: 'July', targetSpend: 14500, actualSpend: 11000 },
{ month: 'August', targetSpend: 21000, actualSpend: 22500 },
{ month: 'September', targetSpend: 19000, actualSpend: 18000 },
{ month: 'October', targetSpend: 22000, actualSpend: 25000 },
{ month: 'November', targetSpend: 16000, actualSpend: 14500 },
{ month: 'December', targetSpend: 25000, actualSpend: 27000 },
];
function calculateAverageSpend() {
const sum = chartData.reduce((accumulator, { actualSpend }) => accumulator + actualSpend, 0);
return sum / chartData.length;
}
const averageSpend = ref(calculateAverageSpend());
function customizeTooltip(data: { value?: number | string | Date; seriesName?: string }) {
const numValue = typeof data.value === 'number' ? data.value : 0;
if (data.seriesName === 'Budget') {
return { text: formatNumber(numValue, 'currency') };
}
const isValueAboveAverage = numValue > calculateAverageSpend();
if (isValueAboveAverage) {
return { text: `${formatNumber(numValue, 'currency')}\n${formatNumber(numValue - averageSpend.value, 'currency')} above average spending.` };
}
return { text: `${formatNumber(numValue, 'currency')}\n${formatNumber(averageSpend.value - numValue, 'currency')} below average spending.` };
}
const chartGradient = registerGradient('linear', {
colors: [{
offset: '20%',
color: '#dee4ff',
}, {
offset: '90%',
color: '#ffdeff',
}],
});
</script>
<template>
<div>
<DxChart
title="Target vs Actual Spending 2025"
:data-source="chartData"
>
<DxSeries
type="bar"
argument-field="month"
value-field="targetSpend"
name="Budget"
color="#5996ff"
/>
<DxSeries
type="spline"
argument-field="month"
value-field="actualSpend"
name="Amount Spent"
color="#cb4bfa"
/>
<DxValueAxis>
<DxConstantLine
:value="averageSpend"
color="#0000c7"
>
<DxLabel
text="Yearly Spend Average"
/>
</DxConstantLine>
</DxValueAxis>
<DxTooltip
:enabled="true"
:customize-tooltip="customizeTooltip"
/>
<DxCommonPaneSettings>
<DxBackgroundColor
base="#ffffff"
:fill-id="chartGradient"
/>
</DxCommonPaneSettings>
</DxChart>
</div>
</template>