-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHomeContent.vue
More file actions
94 lines (88 loc) · 2.98 KB
/
Copy pathHomeContent.vue
File metadata and controls
94 lines (88 loc) · 2.98 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
<script setup lang="ts">
import 'devextreme/dist/css/dx.material.blue.light.compact.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() {
let sum = 0;
chartData.forEach((data) => {
sum += data.actualSpend;
});
return sum / chartData.length;
}
function customizeTooltip(data: { value: number; seriesName: string }) {
if (data.seriesName === 'Budget') {
return { text: formatNumber(data.value, 'currency') };
}
const isValueAboveAverage = data.value > calculateAverageSpend();
const aboveText = `${formatNumber(data.value, 'currency')}\n${formatNumber(data.value - calculateAverageSpend(), 'currency')} above average spending.`;
const belowText = `${formatNumber(data.value, 'currency')}\n${formatNumber(calculateAverageSpend() - data.value, 'currency')} below average spending.`;
return { text: isValueAboveAverage ? aboveText : belowText };
}
const chartGradient = registerGradient('linear', {
colors: [{
offset: '20%',
color: '#dee4ff',
}, {
offset: '90%',
color: '#ffdeff',
}],
});
</script>
<template>
<div>
<DxChart
title="Target vs Actual Spending 2024"
: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="calculateAverageSpend()"
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>