Skip to content

Commit 5a757bf

Browse files
Merge pull request #3 from DevExpress-Examples/vue
Add Vue
2 parents a412a00 + 0ea7151 commit 5a757bf

3 files changed

Lines changed: 168 additions & 80 deletions

File tree

Vue/package-lock.json

Lines changed: 79 additions & 63 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Vue/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
"lint": "eslint . --ext .vue,.js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --fix --ignore-path .gitignore"
1313
},
1414
"dependencies": {
15-
"devextreme": "24.2.3",
16-
"devextreme-vue": "24.2.3",
15+
"devextreme": "25.1.3",
16+
"devextreme-vue": "25.1.3",
1717
"vue": "^3.2.45",
1818
"vue-router": "^4.1.6"
1919
},

Vue/src/components/HomeContent.vue

Lines changed: 87 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,97 @@
11
<script setup lang="ts">
2-
import { computed, ref } from 'vue';
2+
import { ref } from 'vue';
33
44
import 'devextreme/dist/css/dx.material.blue.light.compact.css';
5-
import DxButton from 'devextreme-vue/button';
5+
import DxChart, { DxBackgroundColor, DxCommonPaneSettings, DxConstantLine, DxLabel, DxSeries, DxTooltip, DxValueAxis } from 'devextreme-vue/chart';
6+
import { registerGradient } from 'devextreme-vue/common/charts';
7+
import { formatNumber } from 'devextreme/localization';
68
7-
const props = defineProps({
8-
text: String,
9-
});
10-
const count = ref(0);
11-
const buttonText = computed<string>(
12-
() => `Click ${props.text}: ${count.value}`
13-
);
14-
function clickHandler() {
15-
count.value += 1;
9+
const chartData = [
10+
{ month: 'January', targetSpend: 12000, actualSpend: 9500 },
11+
{ month: 'February', targetSpend: 15500, actualSpend: 16500 },
12+
{ month: 'March', targetSpend: 13500, actualSpend: 12000 },
13+
{ month: 'April', targetSpend: 16000, actualSpend: 14000 },
14+
{ month: 'May', targetSpend: 17000, actualSpend: 18500 },
15+
{ month: 'June', targetSpend: 20000, actualSpend: 17500 },
16+
{ month: 'July', targetSpend: 14500, actualSpend: 11000 },
17+
{ month: 'August', targetSpend: 21000, actualSpend: 22500 },
18+
{ month: 'September', targetSpend: 19000, actualSpend: 18000 },
19+
{ month: 'October', targetSpend: 22000, actualSpend: 25000 },
20+
{ month: 'November', targetSpend: 16000, actualSpend: 14500 },
21+
{ month: 'December', targetSpend: 25000, actualSpend: 27000 },
22+
];
23+
24+
function calculateAverageSpend() {
25+
const sum = chartData.reduce((accumulator, { actualSpend }) => accumulator + actualSpend, 0);
26+
27+
return sum / chartData.length;
28+
}
29+
30+
const averageSpend = ref(calculateAverageSpend());
31+
32+
function customizeTooltip(data: { value: number; seriesName: string }) {
33+
if (data.seriesName === 'Budget') {
34+
return { text: formatNumber(data.value, 'currency') };
35+
}
36+
const isValueAboveAverage = data.value > calculateAverageSpend();
37+
if (isValueAboveAverage) {
38+
return { text: `${formatNumber(data.value, 'currency')}\n${formatNumber(data.value - averageSpend.value, 'currency')} above average spending.` };
39+
}
40+
41+
return { text: `${formatNumber(data.value, 'currency')}\n${formatNumber(averageSpend.value - data.value, 'currency')} below average spending.` };
1642
}
43+
44+
const chartGradient = registerGradient('linear', {
45+
colors: [{
46+
offset: '20%',
47+
color: '#dee4ff',
48+
}, {
49+
offset: '90%',
50+
color: '#ffdeff',
51+
}],
52+
});
53+
1754
</script>
1855
<template>
1956
<div>
20-
<DxButton
21-
:text="buttonText"
22-
@click="clickHandler"
23-
/>
57+
<DxChart
58+
title="Target vs Actual Spending 2024"
59+
:data-source="chartData"
60+
>
61+
<DxSeries
62+
type="bar"
63+
argument-field="month"
64+
value-field="targetSpend"
65+
name="Budget"
66+
color="#5996ff"
67+
/>
68+
<DxSeries
69+
type="spline"
70+
argument-field="month"
71+
value-field="actualSpend"
72+
name="Amount Spent"
73+
color="#cb4bfa"
74+
/>
75+
<DxValueAxis>
76+
<DxConstantLine
77+
:value="averageSpend"
78+
color="#0000c7"
79+
>
80+
<DxLabel
81+
text="Yearly Spend Average"
82+
/>
83+
</DxConstantLine>
84+
</DxValueAxis>
85+
<DxTooltip
86+
:enabled="true"
87+
:customize-tooltip="customizeTooltip"
88+
/>
89+
<DxCommonPaneSettings>
90+
<DxBackgroundColor
91+
base="#ffffff"
92+
:fill-id="chartGradient"
93+
/>
94+
</DxCommonPaneSettings>
95+
</DxChart>
2496
</div>
2597
</template>

0 commit comments

Comments
 (0)