This section explains how to use TreeMap component in Vue 3 application.
System requirements for Syncfusion Vue UI components
The easiest way to create a Vue application is to use the Vue CLI
. Vue CLI versions above 4.5.0
are mandatory for creating applications using Vue 3. Use the following command to uninstall older versions of the Vue CLI.
npm uninstall vue-cli -g
Use the following commands to install the latest version of Vue CLI.
npm install -g @vue/cli
npm install -g @vue/cli-init
Create a new project using the command below.
vue create quickstart
Initiating a new project prompts us to choose the type of project to be used for the current application. Select the option Default (Vue 3)
from the menu.
Syncfusion Vue packages are maintained in the npmjs.com
registry. The TreeMap component will be used in this example. To install it in the quickstart folder use the following command.
npm install @syncfusion/ej2-vue-treemap --save
You have completed all the necessary configurations needed for rendering the Syncfusion Vue component. Now, you are going to add the TreeMap component using following steps.
<script>
section of the src/App.vue
file.<script>
import { TreeMapComponent, TreeMapLegend } from "@syncfusion/ej2-vue-treemap";
</script>
Directive Name | Tag Name |
---|---|
LevelsDirective |
e-levels |
LevelDirective |
e-level |
ColorMappingsDirective |
e-colorMappings |
ColorMappingDirective |
e-colorMapping |
import { TreeMapComponent, TreeMapLegend } from "@syncfusion/ej2-vue-treemap";
//Component registration.
export default {
name: "App",
components: {
"ejs-treemap": TreeMapComponent
}
}
<template>
<ejs-treemap id="treemap" :dataSource="dataSource" :weightValuePath="weightValuePath" :leafItemSettings="leafItemSettings" :equalColorValuePath="equalColorValuePath" :legendSettings="legendSettings"></ejs-treemap>
</template>
Above is the TreeMap component definition with dataSource
, weightValuePath
, leafItemSettings
, equalColorValuePath
and legendSettings
properties.
script
section.export default {
name: "App",
components: {
"ejs-treemap": TreeMapComponent
},
data() {
return {
dataSource: [
{ Title: 'State wise International Airport count in South America', State: "Brazil", Count: 25 },
{ Title: 'State wise International Airport count in South America', State: "Colombia", Count: 12 },
{ Title: 'State wise International Airport count in South America', State: "Argentina", Count: 9 },
{ Title: 'State wise International Airport count in South America', State: "Ecuador", Count: 7 },
{ Title: 'State wise International Airport count in South America', State: "Chile", Count: 6 },
{ Title: 'State wise International Airport count in South America', State: "Peru", Count: 3 },
{ Title: 'State wise International Airport count in South America', State: "Venezuela", Count: 3 },
{ Title: 'State wise International Airport count in South America', State: "Bolivia", Count: 2 },
{ Title: 'State wise International Airport count in South America', State: "Paraguay", Count: 2 },
{ Title: 'State wise International Airport count in South America', State: "Uruguay", Count: 2 },
{ Title: 'State wise International Airport count in South America', State: "Falkland Islands",Count: 1 },
{ Title: 'State wise International Airport count in South America', State: "French Guiana", Count:1 },
{ Title: 'State wise International Airport count in South America', State: "Guyana", Count: 1 },
{ Title: 'State wise International Airport count in South America', State: "Suriname", Count: 1 }
],
weightValuePath: 'Count',
equalColorValuePath: "Count",
leafItemSettings: {
labelPath: "State",
colorMapping: [
{ value: "25", color: "#634D6F" },
{ value: "12", color: "#B34D6D" },
{ value: "9", color: "#557C5C" },
{ value: "7", color: "#44537F" },
{ value: "6", color: "#637392" },
{ value: "3", color: "#7C754D" },
{ value: "2", color: "#2E7A64" },
{ value: "1", color: "#95659A" }
]
},
legendSettings: {
visible: true
}
};
},
provide: {
treemap: [TreeMapLegend]
},
};
src/App.vue
file with following code.<template>
<ejs-treemap id="treemap" :dataSource="dataSource" :weightValuePath="weightValuePath" :leafItemSettings="leafItemSettings" :equalColorValuePath="equalColorValuePath" :legendSettings="legendSettings"></ejs-treemap>
</template>
<script>
import { TreeMapComponent, TreeMapLegend } from "@syncfusion/ej2-vue-treemap";
export default {
name: "App",
components: {
"ejs-treemap": TreeMapComponent
},
data() {
return {
dataSource: [
{ Title: 'State wise International Airport count in South America', State: "Brazil", Count: 25 },
{ Title: 'State wise International Airport count in South America', State: "Colombia", Count: 12 },
{ Title: 'State wise International Airport count in South America', State: "Argentina", Count: 9 },
{ Title: 'State wise International Airport count in South America', State: "Ecuador", Count: 7 },
{ Title: 'State wise International Airport count in South America', State: "Chile", Count: 6 },
{ Title: 'State wise International Airport count in South America', State: "Peru", Count: 3 },
{ Title: 'State wise International Airport count in South America', State: "Venezuela", Count: 3 },
{ Title: 'State wise International Airport count in South America', State: "Bolivia", Count: 2 },
{ Title: 'State wise International Airport count in South America', State: "Paraguay", Count: 2 },
{ Title: 'State wise International Airport count in South America', State: "Uruguay", Count: 2 },
{ Title: 'State wise International Airport count in South America', State: "Falkland Islands",Count: 1 },
{ Title: 'State wise International Airport count in South America', State: "French Guiana", Count:1 },
{ Title: 'State wise International Airport count in South America', State: "Guyana", Count: 1 },
{ Title: 'State wise International Airport count in South America', State: "Suriname", Count: 1 }
],
weightValuePath: 'Count',
equalColorValuePath: "Count",
leafItemSettings: {
labelPath: "State",
colorMapping: [
{ value: "25", color: "#634D6F" },
{ value: "12", color: "#B34D6D" },
{ value: "9", color: "#557C5C" },
{ value: "7", color: "#44537F" },
{ value: "6", color: "#637392" },
{ value: "3", color: "#7C754D" },
{ value: "2", color: "#2E7A64" },
{ value: "1", color: "#95659A" }
]
},
legendSettings: {
visible: true
}
};
},
provide: {
treemap: [TreeMapLegend]
}
};
</script>
npm run serve
The web server will be initiated and open the quickstart app in the browser at port localhost:8080
.
Refer the following sample, vue3-treemap-getting-started.