WEB/기타
[echart.js] 라벨 2개
silverline79
2024. 12. 17. 20:20
<!--
THIS EXAMPLE WAS DOWNLOADED FROM https://echarts.apache.org/examples/en/editor.html?c=bar-label-rotation
-->
<!doctype html>
<html>
<head>
<meta charset="utf-8">
</head>
<body style="width:1200px;height: 400px; margin: 0">
<div id="container" style="height: 100%"></div>
<script type="text/javascript" src="echarts.min.js"></script>
<script type="text/javascript">
var dom = document.getElementById('container');
var myChart = echarts.init(dom, null, {
renderer: 'canvas',
useDirtyRect: false
});
var app = {};
var option;
const posList = [
'left',
'right',
'top',
'bottom',
'inside',
'insideTop',
'insideLeft',
'insideRight',
'insideBottom',
'insideTopLeft',
'insideTopRight',
'insideBottomLeft',
'insideBottomRight'
];
app.configParameters = {
rotate: {
min: -90,
max: 90
},
align: {
options: {
left: 'left',
center: 'center',
right: 'right'
}
},
verticalAlign: {
options: {
top: 'top',
middle: 'middle',
bottom: 'bottom'
}
},
position: {
options: posList.reduce(function (map, pos) {
map[pos] = pos;
return map;
}, {})
},
distance: {
min: 0,
max: 100
}
};
app.config = {
rotate: 90,
align: 'left',
verticalAlign: 'middle',
position: 'insideBottom',
distance: 15,
onChange: function () {
const labelOption = {
rotate: app.config.rotate,
align: app.config.align,
verticalAlign: app.config.verticalAlign,
position: app.config.position,
distance: app.config.distance
};
myChart.setOption({
series: [
{
label: labelOption
},
{
label: labelOption
}
]
});
}
};
const labelOption = {
show: true,
position: app.config.position,
distance: app.config.distance,
align: app.config.align,
verticalAlign: app.config.verticalAlign,
rotate: app.config.rotate,
formatter: '{c} {name|{a}}',
fontSize: 16,
rich: {
name: {}
}
};
option = {
tooltip: {
trigger: 'axis',
axisPointer: {
type: 'shadow'
}
},
legend: {
data: ['라벨1', '라벨2']
},
xAxis: [
{
type: 'category',
axisTick: { show: false },
data: ['본부1', '본부2', '본부3', '본부4', '본부5', '본부6', '본부7', '본부8', '본부9', '본부10', '본부11', '본부12', '본부13', '본부14', '본부15']
}
],
yAxis: [
{
type: 'value'
}
],
series: [
{
name: '라벨1',
type: 'bar',
barGap: 0,
//label: labelOption,
emphasis: {
focus: 'series'
},
data: [320, 332, 301, 334, 390, 320, 332, 301, 334, 390, 320, 332, 301, 334, 390],
itemStyle:{
color: '#c0e6ff',
},
},
{
name: '라벨2',
type: 'bar',
//label: labelOption,
emphasis: {
focus: 'series'
},
data: [220, 182, 191, 234, 290, 220, 182, 191, 234, 290, 220, 182, 191, 234, 50],
itemStyle:{
color: '#d6e9ce',
},
}
]
};
if (option && typeof option === 'object') {
myChart.setOption(option);
}
window.addEventListener('resize', myChart.resize);
</script>
</body>
</html>