-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
85 lines (78 loc) · 2.65 KB
/
Copy pathindex.js
File metadata and controls
85 lines (78 loc) · 2.65 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
const registerGradient = DevExpress.common.charts.registerGradient;
const formatNumber = DevExpress.localization.formatNumber;
$(() => {
$('#chart').dxChart({
dataSource: chartData,
title: 'Target vs Actual Spending 2025',
series: [{
type: 'bar',
argumentField: 'month',
valueField: 'targetSpend',
name: 'Budget',
color: '#5996ff',
}, {
type: 'spline',
argumentField: 'month',
valueField: 'actualSpend',
name: 'Amount Spent',
color: '#cb4bfa',
}],
valueAxis: [{
constantLines: [{
value: averageSpend,
color: '#0000c7',
label: {
text: 'Yearly Spend Average',
},
}],
}],
tooltip: {
enabled: true,
customizeTooltip,
},
commonPaneSettings: {
backgroundColor: {
base: '#ffffff',
fillId: registerGradient('linear', {
colors: [{
offset: '20%',
color: '#dee4ff',
}, {
offset: '90%',
color: '#ffdeff',
}],
}),
},
},
});
});
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 },
];
// A function cannot directly be assigned to the constantLines[].value property of Chart axes.
const averageSpend = calculateAverageSpend();
function calculateAverageSpend() {
const sum = chartData.reduce((accumulator, { actualSpend }) => accumulator + actualSpend, 0);
return sum / chartData.length;
}
function customizeTooltip(data) {
if (data.seriesName === 'Budget') {
return { text: formatNumber(data.value, 'currency') };
}
const isValueAboveAverage = data.value > averageSpend;
if (isValueAboveAverage) {
return { text: `${formatNumber(data.value, 'currency')}\n${formatNumber(data.value - averageSpend, 'currency')} above average spending.` };
}
return { text: `${formatNumber(data.value, 'currency')}\n${formatNumber(averageSpend - data.value, 'currency')} below average spending.` };
}