ํฐ์คํ ๋ฆฌ ๋ทฐ
Chart
[Echarts] Pie Chart ์์ ์ด๋ฏธ์ง ๋ฃ๊ธฐ, ํด๋ฆญ์ url ์ด๋ํ๊ธฐ
devOhzl 2023. 6. 24. 16:56๐ฌ ๊ตฌํํ๊ณ ์ ํ๋ ๊ธฐ๋ฅ
1. ํ์ด์ฐจํธ ๊ฐ์ด๋ฐ์ ์ด๋ฏธ์ง ์ถ๊ฐํ๊ธฐ
2. ํ์ด์ฐจํธ ํด๋ฆญ ์ url ์ด๋ํ๊ธฐ
๐ ํ์ด์ฐจํธ ๊ฐ์ด๋ฐ ์ด๋ฏธ์ง ์ถ๊ฐํ๊ธฐ
series ์์ฑ ์์ label ์ ์ฌ์ฉํ์ฌ ์ด๋ฏธ์ง๋ฅผ ์ถ๊ฐํ๋ค.
series: [
{
label: {
position: 'center',
// 1. ๋ณ์ 'a' ์ค์
formatter: () => {
return '{a|}'
},
rich: {
// 'a' ๋ณ์์ ๋ค์ด๊ฐ ์์ฑ ์ค์
a: {
backgroundColor: {
image: require(`@common/DashBoard/Content/img/${this.chartId}.png`),
},
height: 35
},
}
},
}
]
๐ ํ์ด์ฐจํธ ํด๋ฆญ์ ์ด๋ฒคํธ ์ถ๊ฐํ๊ธฐ
์ฐจํธ๋ฅผ ์ด๊ธฐํํ ํ, click ์ด๋ฒคํธ๋ฅผ ์ถ๊ฐํ๋ค.
methods: {
setChart(option) {
let pieChart = echarts.init(document.getElementById(this.chartId));
pieChart.setOption(option);
pieChart.on('click', (params) => {
switch(params.seriesName){
case 'MCP':
window.parent.location.href = `${process.env.VUE_APP_ROUTE_TARGET}main/1`
break;
case 'IO Link Master':
window.parent.location.href = `${process.env.VUE_APP_ROUTE_TARGET}main/2`
break;
case 'Robot':
window.parent.location.href = `${process.env.VUE_APP_ROUTE_TARGET}main/3`
break;
}
});
}
},
๐ ์ ์ฒด ์ฝ๋
<template>
<div :id="chartId" class="status-container__chart--chart"></div>
</template>
<script>
import * as echarts from "echarts";
export default {
props: {
chartId: { type: String, default: '' },
stateCountList: { type: Array, default: [] },
},
data() {
return {
cnt: [
{ value: 0, name: 'Normal' },
{ value: 0, name: 'Warning' },
{ value: 0, name: 'Alert' },
],
total: 0
}
},
watch: {
// props ๋ณ๊ฒฝ ๊ฐ์ง
stateCountList() {
console.log('--props',this.stateCountList)
this.cnt = this.stateCountList
this.total = this.cnt[0].value + this.cnt[1].value + this.cnt[2].value // total ๊ฐ ๊ณ์ฐ
this.setChart(this.option)
}
},
computed: {
option() {
return {
tooltip: {
show: false,
trigger: 'item'
},
legend: {
show: false,
top: '5%',
left: 'center',
},
series: [
{
name: this.chartId,
type: 'pie',
radius: ['50%', '80%'],
color: ['rgb(146,208,80)','rgb(255,192,0)','rgb(255,0,0)'],
avoidLabelOverlap: false,
label: {
position: 'center',
formatter: () => {
return '{a|}'
},
rich: {
a: {
backgroundColor: {
image: require(`@common/DashBoard/Content/img/${this.chartId}.png`),
},
height: 35
},
}
},
labelLine: {
show: false
},
data: this.cnt
}
]
}
}
},
methods: {
setChart(option) {
let pieChart = echarts.init(document.getElementById(this.chartId));
pieChart.setOption(option);
pieChart.on('click', (params) => {
switch(params.seriesName){
case 'MCP':
window.parent.location.href = `${process.env.VUE_APP_ROUTE_TARGET}main/E00000201`
break;
case 'IO Link Master':
window.parent.location.href = `${process.env.VUE_APP_ROUTE_TARGET}main/E00000301`
break;
case 'Robot':
window.parent.location.href = `${process.env.VUE_APP_ROUTE_TARGET}main/E00000401`
break;
}
});
}
},
mounted(){
}
}
</script>
<style>
</style>
'Chart' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[ECharts] y์ถ์ด ์ฌ๋ฌ๊ฐ์ผ ๋, ๋ฒ๋ก on/off์ y์ถ๋ ํจ๊ป on/off ํ๊ธฐ (0) | 2023.08.23 |
---|---|
[Chartjs] ๋ผ๋ฒจ ๊ฐฏ์์ ๋ฐ๋ฅธ x์ถ ์คํฌ๋กค (0) | 2023.06.24 |
[Chartjs] ๋ฒ๋ก์ ์ฐจํธ ๊ฐ๊ฒฉ ์กฐ์ ํ๊ธฐ (0) | 2023.06.23 |
[ Chartjs ] vue.js ์ฐจํธ ์์ - Bar&Line Chart, Min&Max (0) | 2023.06.19 |
[ Chartjs ] vue.js์์ ์ฐจํธ ๋ผ์ด๋ธ๋ฌ๋ฆฌ vue-chartjs ์ฌ์ฉํ๊ธฐ (0) | 2023.06.16 |
๊ณต์ง์ฌํญ
์ต๊ทผ์ ์ฌ๋ผ์จ ๊ธ
์ต๊ทผ์ ๋ฌ๋ฆฐ ๋๊ธ
- Total
- Today
- Yesterday
๋งํฌ
TAG
- SCSS
- npm
- javascript
- Legend
- ๊ฐ์ฒด๋ณต์ฌ
- Location
- web
- chartjs
- ๊ฐ์ฒด
- frontend
- Figma ๊ธฐ์ด
- Figma ๋ฒํผ
- package
- echarts
- piechart
- Chart
- ์์๋ณต์ฌ
- package-lock
- npm install
- SASS
- Vscode๋จ์ถํค
- VUE
- vscode
- x์ถ์คํฌ๋กค
- BarChart
- ๊น์๋ณต์ฌ
- ํ๊ฒฝ์ค์
- Figma Style
- ํ๋ก ํธ์๋
- figma
์ผ | ์ | ํ | ์ | ๋ชฉ | ๊ธ | ํ |
---|---|---|---|---|---|---|
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 |
๊ธ ๋ณด๊ดํจ