JSFiddle - React, Tailwind, and code Playground
HTML
<!DOCTYPE html><html><head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>파이 차트</title>
<style>
html {
margin: 0px;
}
body {
margin: 20px 30px;
}
#realmap {
width: 850px;
height: 750px;
border: 1px solid lightgray;
margin-bottom: 20px;
}
</style>
<link href="https://unpkg.com/realmap/realmap-style.css" rel="stylesheet" crossorigin="anonymous">
<link href="https://unpkg.com/realmap/realmap-export-style.css" rel="stylesheet" crossorigin="anonymous">
<style>
.green-layout {
background-color: #00880020;
}
.red-button {
color: red;
}
</style>
<script type="text/javascript" src="https://unpkg.com/realmap/export.js"></script>
<script type="text/javascript" src="https://unpkg.com/realmap/index.js"></script>
<script type="text/javascript">
window.addEventListener('DOMContentLoaded', function () {
try {
init();
} catch (err) {
alert(err);
console.error(err);
}
});
</script>
<script>
var realMapLic = "upVcPE+wPOl3H1t2EmYDS2ZHHsIGhYOFvAiOqCN7jMScsYfjJ8xYHvcnjNP/alBGvwgv6MHcLk1itlg31ZMil9o5hU+SYjm4Y36LXWAlUU4zFfHLyfJrYkJ/CQ8eAe9knEDoO6g6qItm79yHT0KSfOj61RRag6zMyWEhOl7O9n/Hwl6Ih/mjqr3cLQlHWabvEhVyY82R38U=";
</script>
</head>
<body>
<div id="realmap"></div>
<div id="actions"></div>
</body></html>
JavaScript
const config = {
title: false,
credits: {
visible: false
},
map: [{
url: 'https://unpkg.com/realmap-collection/kr-sido-low.geo.json',
padding: '0.1 0'
}],
body: {
projection: 'mercator'
},
annotations: [{
front: true,
type: 'shape',
shape: 'rectangle',
offsetX: 20,
offsetY: 20,
width: 10,
height: 28,
style: {
fill: '#FFD5A3'
}
}, {
front: true,
// scope: 'body',
type: 'text',
text: '시도별 남녀 인구 구조',
offsetX: 40,
offsetY: 20,
height: 28,
style: {
fontSize: '15pt',
fontWeight: 700
}
}],
legend: {
location: 'bottom'
},
series: [{
name: '행정구역경계(시도)',
dataUrl: 'https://www.realmap.co.kr/assets/data/kr-gender-ratio.json',
mapKeys: ['b-code', 'code'],
// hoverColor: '#DBD4CE',
tooltipText: false,
style: {
stroke: '#6d6d6d',
strokeWidth: 0.7
},
hoverStyle: {
filter: 'brightness(0.95)'
},
pointColors: args => {
const ratio = args.source.genderRatio;
if (ratio < 1) return '#FFD5A3';
return '#FCE7C8';
},
legend: -1
}, {
type: "pie",
name: '시도별 남녀 인구 비율(남/녀)',
minSize: 0.5,
legendByCategory: true,
categories: [{
name: '남자',
color: '#65AAEB'
}, {
name: '여자',
color: '#FD787F'
}],
pointLabel: {
textCallback: args => {
const {
name,
total,
malePopulation,
femalePopulation
} = args.source;
const left = (malePopulation / total * 100).toFixed(2);
const right = (femalePopulation / total * 100).toFixed(2);
return `${name}<br />${left} / ${right}`;
}
},
tooltipText: false,
mapKeys: ['b-code', 'code'],
dataUrl: 'https://www.realmap.co.kr/assets/data/kr-gender-ratio.json'
}]
};
let chart;
async function init() {
chart = await RealMap.createChartAsync(document, 'realmap', config, true);
}