μ°¨νΈλ³λ‘ μ¬μ©ν μ μλ APIλ μ΄ κ°μ΄λμμ λ€λ£¨μ§ μλλ€. μ¬μ© κ°λ₯ν APIκ° κΆκΈνλ€λ©΄ API κ°μ΄λλ₯Ό μ°Έκ³ νμ.
NestedPie μ°¨νΈμ μμ± λ°©λ²μ λ κ°μ§κ° μλ€. μμ±μ ν¨μμ μ μ ν¨μλ₯Ό ν΅ν΄ μμ±ν μ μλ€. κ²°κ³Όλ λͺ¨λ μ°¨νΈμ μΈμ€ν΄μ€κ° λ°νλλ€. λ§€κ° λ³μλ μ°¨νΈκ° κ·Έλ €μ§λ μμμΈ HTML μμ el
, λ°μ΄ν°κ°μΈ data
, μ΅μ
κ° options
κ° κ°μ²΄λ‘ λ€μ΄κ°λ€. el
κ°μ μ°¨νΈμ 컨ν
μ΄λ μμμ΄λ―λ‘ μ°¨νΈ μΈμ λ€λ₯Έ μμλ€μ΄ ν¬ν¨λμ΄ μμΌλ©΄ μ°¨νΈμ μν₯μ μ€ μ μμμΌλ‘ λΉμ΄μλ HTML μμλ₯Ό μ¬μ©νλ κ²μ κΆμ₯νλ€.
import { NestedPieChart } from '@toast-ui/chart';
const chart = new NestedPieChart({el, data, options});
// νΉμ
import Chart from '@toast-ui/chart';
const chart = Chart.nestedPieChart({el, data, options});
λ°μ΄ν°λ series
λ₯Ό ν΅ν΄ μ
λ ₯λ°λλ€. μ€μ²©λ νμ΄ μ°¨νΈλ λ³μΉμ΄ λλ name
κ°μ μ
λ ₯λ°κ³ , data
μ μΉν°λ₯Ό ννν μ μλ λ°μ΄ν°λ₯Ό name
, data
μμΌλ‘ μ
λ ₯λ°λλ€. μ
λ ₯ν λͺ¨λ data
κ°μ΄ λ²λ‘μ νμλλ€.
const data = {
series: [
{
name: 'browsers',
data: [
{
name: 'Chrome',
data: 50,
},
{
name: 'Safari',
data: 20,
},
{
name: 'IE',
data: 10,
},
{
name: 'Firefox',
data: 10,
},
{
name: 'Opera',
data: 3,
},
{
name: 'Etc',
data: 7,
},
],
},
{
name: 'versions',
data: [
{
name: 'Chrome 64',
data: 40,
},
{
name: 'Chrome 63',
data: 10,
},
{
name: 'Safari 13',
data: 15,
},
{
name: 'Safari 12',
data: 5,
},
{
name: 'IE 11',
data: 4,
},
{
name: 'IE 10',
data: 3,
},
{
name: 'IE 9',
data: 2,
},
{
name: 'IE 8',
data: 1,
},
{
name: 'Firefox 13',
data: 8,
},
{
name: 'Firefox 12',
data: 2,
},
{
name: 'Opera 15',
data: 2,
},
{
name: 'Opera 12',
data: 1,
},
{
name: 'Etc - 2020',
data: 7,
},
],
},
]
}
parentName
μ μ§μ νλ©΄ λ°μ΄ν°μ λΆλͺ¨ μ리μ¦λ₯Ό μ€μ ν΄μ£Όμ΄ κ·Έλ£Ή λ°μ΄ν°λ‘ νννλ€. κ·Έλ£Ή λ°μ΄ν°λ μ리μ¦μ μκΉμ΄ κ°μΌλ©° ν¬λͺ
λλ‘ κ΅¬λΆλλ€. series
μ 첫λ²μ§Έ μΈλ±μ€μ μλ data
κ°λ§ λ²λ‘λ‘ νμνλ€.
const data = {
categories: ['A', 'B'],
series: [
{
name: 'browsers',
data: [
{
name: 'Chrome',
data: 50,
},
{
name: 'Safari',
data: 20,
},
{
name: 'IE',
data: 10,
},
{
name: 'Firefox',
data: 10,
},
{
name: 'Opera',
data: 3,
},
{
name: 'Etc',
data: 7,
},
],
},
{
name: 'versions',
data: [
{
name: 'Chrome 64',
parentName: 'Chrome',
data: 40,
},
{
name: 'Chrome 63',
parentName: 'Chrome',
data: 10,
},
{
name: 'Safari 13',
parentName: 'Safari',
data: 15,
},
{
name: 'Safari 12',
parentName: 'Safari',
data: 5,
},
{
name: 'IE 11',
parentName: 'IE',
data: 4,
},
{
name: 'IE 10',
parentName: 'IE',
data: 3,
},
{
name: 'IE 9',
parentName: 'IE',
data: 2,
},
{
name: 'IE 8',
parentName: 'IE',
data: 1,
},
{
name: 'Firefox 13',
parentName: 'Firefox',
data: 8,
},
{
name: 'Firefox 12',
parentName: 'Firefox',
data: 2,
},
{
name: 'Opera 15',
parentName: 'Opera',
data: 2,
},
{
name: 'Opera 12',
parentName: 'Opera',
data: 1,
},
{
name: 'Etc 1',
parentName: 'Etc',
data: 3,
},
{
name: 'Etc 2',
parentName: 'Etc',
data: 2,
},
{
name: 'Etc 3',
parentName: 'Etc',
data: 1,
},
{
name: 'Etc 4',
parentName: 'Etc',
data: 1,
},
],
},
],
};
κ°κ°μ series
λ visible
μ΅μ
μ κ°μ§ μ μλ€. visible
μ΅μ
μ μ²μ μ°¨νΈκ° κ·Έλ €μ‘μ λ μ리μ¦λ₯Ό λνλΌμ§μ λν μ¬λΆλ₯Ό κ²°μ νλ€. κΈ°λ³Έκ°μ true
μ΄λ€.
κΈ°λ³Έ μ°¨νΈμ κ·Έλ£Ή λ°μ΄ν° μ°¨νΈμ μ¬μ©λ²μ λμΌνλ€.
const data = {
series: [
{
name: 'browsers',
data: [
{
name: 'Chrome',
data: 50,
visible: false,
},
{
name: 'Safari',
data: 20,
},
{
name: 'IE',
data: 10,
},
{
name: 'Firefox',
data: 10,
visible: false,
},
{
name: 'Opera',
data: 3,
},
{
name: 'Etc',
data: 7,
},
],
},
{
name: 'versions',
data: [
{
name: 'Chrome 64',
data: 40,
},
{
name: 'Chrome 63',
data: 10,
},
{
name: 'Safari 13',
data: 15,
},
{
name: 'Safari 12',
data: 5,
},
{
name: 'IE 11',
data: 4,
},
{
name: 'IE 10',
data: 3,
},
{
name: 'IE 9',
data: 2,
},
{
name: 'IE 8',
data: 1,
},
{
name: 'Firefox 13',
data: 8,
},
{
name: 'Firefox 12',
data: 2,
},
{
name: 'Opera 15',
data: 2,
},
{
name: 'Opera 12',
data: 1,
},
{
name: 'Etc - 2020',
data: 7,
},
],
},
]
}
μ μ΅μ μ μ μ©ν΄ μ°¨νΈλ₯Ό μμ±ν΄λ³΄λ©΄ 체ν¬λ°μ€κ° ν΄μ λμ΄ μμ±λλ κ²μ νμΈν μ μμ΅λλ€.
options
λ κ°μ²΄λ‘ μμ±νλ€. series
μ΅μ
μ κΈ°λ³Έμ μΌλ‘ Pie μ°¨νΈμ μλ¦¬μ¦ μ΅μ
κ³Ό κ°κ³ radiusRange
λ κ° μ리μ¦μ λ°μ§λ¦ λ²μλ₯Ό μ€μ νκΈ° μν΄ [name]
μ΅μ
μΌλ‘ μ΄λνλ€. [name]
μ μ
λ ₯λ°μ λ°μ΄ν°μμ seriesμ name
μ΄ μ΄μ ν΄λΉνλ€. μ€μ²©λ λͺ¨λ μ리μ¦μ 곡ν΅μΌλ‘ μ μ©ν μ΅μ
μ series
μ λ°λ‘ μμ±νκ³ , κ° μ리μ¦λ³λ‘ μ μ©ν μ΅μ
μ [name]
μ μμ±νλ€.
type options = {
chart?: {
//...
}
legend?: {
//...
}
exportMenu?: {
//...
}
tooltip?: {
//...
}
responsive?: {
//...
}
theme?: {
// μλ ν
λ§ μ±ν°μμ μ€λͺ
}
series?: {
selectable?: boolean;
clockwise?: boolean;
angleRange?: {
start?: number;
end?: number;
};
dataLabels?: {
visible?: boolean;
anchor?: DataLabelAnchor;
offsetX?: number;
offsetY?: number;
formatter?: (value) => string;
pieSeriesName?: {
visible: boolean;
anchor?: 'center' | 'outer';
};
};
[name]: {
selectable?: boolean;
clockwise?: boolean;
angleRange?: {
start?: number;
end?: number;
};
radiusRange?: {
inner?: number | string;
outer?: number | string;
};
dataLabels?: {
visible?: boolean;
anchor?: DataLabelAnchor;
offsetX?: number;
offsetY?: number;
formatter?: (value) => string;;
pieSeriesName?: {
visible: boolean;
anchor?: 'center' | 'outer';
};
};
}
}
}
μ΄ μ°¨νΈμμ μ¬μ©ν μ μλ κ³΅ν΅ μ΅μ μ λν΄μλ μ΄ κ°μ΄λμμ λ€λ£¨μ§ μλλ€. νμνλ€λ©΄ ν΄λΉ μ΅μ μ κ°μ΄λλ₯Ό μ°Έκ³ νμ. (λ§ν¬:
chart
μ΅μ , λ²λ‘, λ΄λ³΄λ΄κΈ°, ν΄ν,responsive
μ΅μ )
ν΄λΉ μ리μ¦λ₯Ό μ νν μ μλ€.
- κΈ°λ³Έκ°:
false
const options = {
series: {
selectable: true
}
};
κ° μλ¦¬μ¦ name
μ ν΄λΉνλ μ΅μ
μ μ€μ ν μ μλ€. μλμ κ°μ΄ μμ±νλ©΄, 'browsers'
μ ν΄λΉνλ Pie μ°¨νΈλ μ νν μ μκ³ , versions
μ ν΄λΉνλ Pie μ°¨νΈλ μ νν μ μλ€.
const options = {
series: {
browsers: {
selectable: true
},
versions: {
selectable: false
}
}
};
κ·Έλ£Ή λ°μ΄ν°λ₯Ό μ ννλ©΄ parentName
μΌλ‘ μ°κ²°λ λͺ¨λ μ리μ¦λ₯Ό μ ννλ€.
selectable
μ΅μ
κ³Ό on
APIμ selectSeries
, unselectSeries
λ₯Ό ν¨κ» μ¬μ©ν κ²½μ° ν΄λΉ μ리μ¦μ λν μ μ΄λ₯Ό μΆκ°λ‘ ν μ μλ€.
μ리μ¦κ° κ·Έλ €μ§λ λ°©ν₯μ μ€μ νλ€. κΈ°λ³Έμ μΌλ‘ μκ³ λ°©ν₯μΌλ‘ κ·Έλ €μ§κ³ , false
λ‘ μ€μ νλ©΄ μκ³ λ°λ λ°©ν₯μΌλ‘ κ·Έλ €μ§λ€.
- κΈ°λ³Έκ°:
true
const options = {
series: {
clockwise: false
}
};
κ° μλ¦¬μ¦ name
μ ν΄λΉνλ μ΅μ
μ μ€μ ν μ μλ€. μλμ κ°μ΄ μμ±νλ©΄, 'browsers'
μ ν΄λΉνλ Pie μ°¨νΈλ μκ³ λ°©ν₯μΌλ‘ κ·Έλ €μ§κ³ , versions
μ ν΄λΉνλ Pie μ°¨νΈλ μκ³ λ°λ λ°©ν₯μΌλ‘ κ·Έλ €μ§λ€.
const options = {
series: {
browsers: {
clockwise: true
},
versions: {
clockwise: false
}
}
};
radiusRange
λ inner
μ outer
μ΅μ
μ μ§μ νμ¬ μμͺ½ μμ λ°μ§λ¦κ³Ό λ°κΉ₯μͺ½ μμ λ°μ§λ¦μ μ€μ νλ€. inner
μ κΈ°λ³Έκ°μ 0
μ΄λ€. 0λ³΄λ€ ν° κ°μ μ
λ ₯νλ©΄ λλ λͺ¨μμ μ°¨νΈλ₯Ό λ§λ€ μ μλ€. κ° μλ¦¬μ¦ name
μ ν΄λΉνλ μ΅μ
μ μ€μ ν μ μλ€. λ§μ½ series.radiusRange
λ₯Ό μ€μ νμ§ μλλ€λ©΄ κ° μ€μ²©λ μ리μ¦κ° κ· μΌν λ°μ§λ¦μ κ°λλ‘ μ€μ λλ€.
μμ± | μ€λͺ |
---|---|
radiusRange.inner |
μμͺ½μ λ°μ§λ¦ μ€μ |
radiusRange.outer |
λ°κΉ₯μͺ½μ λ°μ§λ¦ μ€μ |
κ°μ %
λ₯Ό ν¬ν¨ν λ¬Έμμ΄ νμ
μΌλ‘ μ
λ ₯νλ©΄ λΉμ¨λ‘ κ³μ°νλ€.
const options = {
series: {
browsers: {
radiusRange: {
inner: '20%',
outer: '50%'
}
},
versions: {
radiusRange: {
inner: '55%',
outer: '85%'
}
}
}
};
κ°μ μ«μ νμ μΌλ‘ μ λ ₯νλ©΄ λ°μ§λ¦μ μ λκ°μΌλ‘ κ³μ°λλ€.
const options = {
series: {
browsers: {
radiusRange: {
inner: 50,
outer: 130
},
},
versions: {
radiusRange: {
inner: 150,
outer: 230
}
}
}
};
angleRange
λ start
μ end
μ΅μ
μ μ¬μ©νμ¬ νΈμ λ²μλ₯Ό μ€μ νλ€.
μμ± | μ€λͺ |
---|---|
angleRange.start |
νΈμ μμ κ°λ (κΈ°λ³Έκ°: 0 ) |
angleRange.end |
νΈμ λ κ°λ (κΈ°λ³Έκ°: 360 ) |
const options = {
series: {
angleRange: {
start: -90,
end: 90
}
}
};
κ° μλ¦¬μ¦ name
μ ν΄λΉνλ μ΅μ
μ μ€μ ν μ μλ€.
const options = {
series: {
browsers: {
angleRange: {
start: 0,
end: 180
}
},
versions: {
angleRange: {
start: 180,
end: 360
}
}
}
};
series.dataLabels
μ΅μ
μ μ§μ νλ©΄ λͺ¨λ μ€μ²©λ Pie μ°¨νΈμμ λ°μ΄ν° λΌλ²¨μ΄ νμν μ μλ€.
const options = {
...
series: {
dataLabels: {
visible: true;
}
}
};
series
μ΅μ
μ κ° κ³μΈ΅λ³λ‘ Pie μλ¦¬μ¦ μ΅μ
μ μ μν μ μμΌλ©°, λ°μ΄ν° λΌλ²¨ κ΄λ ¨ μ΅μ
λ μ’ λ μΈλ°νκ² μ€μ ν μ μλ€.
type options = {
...
series?: {
[name]: {
...
dataLabels: {
// Pie μλ¦¬μ¦ λ°μ΄ν° λΌλ²¨ μ΅μ
};
},
...
};
};
μλ μ½λλ μμͺ½μ μλ Pie μ리μ¦('browsers')μλ λ°μ΄ν° λΌλ²¨λ§ νμνκ³ , λ°κΉ₯μͺ½μ μλ Pie μ리μ¦('versions')μλ μλ¦¬μ¦ μ΄λ¦ λΌλ²¨κΉμ§ νμνλλ‘ μ€μ ν μ΅μ μ΄λ€.
const options = {
series: {
browsers: {
radiusRange: {
inner: '20%',
outer: '50%'
},
dataLabels: {
visible: true,
pieSeriesName: {
visible: false
}
}
},
versions: {
radiusRange: {
inner: '55%',
outer: '85%'
},
dataLabels: {
visible: true,
pieSeriesName: {
visible: true,
anchor: 'outer'
}
}
}
}
};
NestedPie μ°¨νΈμμ κ° μ리μ¦λ³λ‘ μμ ν μ μλ μλ¦¬μ¦ ν
λ§μ΄λ€. κ° Pie μ리μ¦μ λ°μ΄ν° λΌλ²¨ μ€νμΌμ μ§μ ν κ²½μ° series[name].dataLabels
λ₯Ό μ μνλ€.
interface NestedPieChartSeriesTheme {
colors?: string[];
areaOpacity?: number;
lineWidth?: number;
strokeStyle?: string;
hover?: {
color?: string;
lineWidth?: number;
strokeStyle?: string;
shadowColor?: string;
shadowBlur?: number;
shadowOffsetX?: number;
shadowOffsetY?: number;
};
select?: {
color?: string;
lineWidth?: number;
strokeStyle?: string;
shadowColor?: string;
shadowBlur?: number;
shadowOffsetX?: number;
shadowOffsetY?: number;
restSeries?: {
areaOpacity?: number;
};
areaOpacity?: number;
};
dataLabels?: CommonDataLabelBoxTheme & {
pieSeriesName?: CommonDataLabelBoxTheme;
callout?: {
useSeriesColor?: boolean;
lineWidth?: number;
lineColor?: string;
};
};
}
type CommonDataLabelBoxTheme = {
useSeriesColor?: boolean;
lineWidth?: number;
textStrokeColor?: string;
shadowColor?: string;
shadowBlur?: number;
fontSize?: number;
fontFamily?: string;
fontWeight?: string | number;
color?: string;
textBubble?: {
visible?: boolean;
paddingX?: number;
paddingY?: number;
backgroundColor?: string;
borderRadius?: number;
borderColor?: string;
borderWidth?: number;
shadowColor?: string;
shadowOffsetX?: number;
shadowOffsetY?: number;
shadowBlur?: number;
};
};
μ΄λ¦ | νμ | μ€λͺ |
---|---|---|
colors |
string[] | μ리μ¦μ μμ |
areaOpacity |
number | λͺ¨λ μ리μ¦κ° νμ± λμ΄ μμ λμ μ 체 μμ ν¬λͺ λ |
lineWidth |
number | μ리μ¦μ ν λ리 μ λλΉ |
strokeStyle |
string | μ리μ¦μ ν λ리 μ μ |
hover |
object | λ°μ΄ν°μ λ§μ°μ€λ₯Ό μ¬λ Έμ λ μ€νμΌ |
select |
object | μ΅μ
series.selectable: true λ‘ μ€μ λμ΄ μμ λ μ리μ¦κ° μ ν λλ©΄ μ μ©λλ μ€νμΌ |
dataLabels |
object | λ°μ΄ν° λΌλ²¨ μ€νμΌ. Pie μ°¨νΈμ theme.dataLabels μ΅μ
κ³Ό κ°λ€. |
ν
λ§λ μ΅μ
μμ theme
μ΅μ
μ μ§μ νκ³ μλ¦¬μ¦ ν
λ§λ theme.series
λ‘ μ€μ νλ€. κ°λ¨ν μμλ‘ μ리μ¦μ μ€νμΌμ λ°κΏλ³΄μ.
μλ μ½λλ lineWidth
, strokeStyle
μ μ€μ νμ¬ μ€μ²©λ λͺ¨λ μ리μ¦μ μ λκ»μ μκΉμ λ³κ²½ν μ΅μ
μ΄λ€.
const options = {
theme: {
series: {
colors: ['#eef4c4', '#77543f', '#b7c72e', '#5b9aa0', '#30076f', '#622569', '#f75294'],
lineWidth: 5,
strokeStyle: '#cccccc',
}
}
}
[name]
μ ν΄λΉνλ κ° μ리μ¦λ³λ‘ μ€νμΌμ μ μ©ν μ μλ€. μλ μ½λλ μλ¦¬μ¦ μμ, ν
λ리 λκ», ν
λ리 μμκ³Ό λ§μ°μ€λ₯Ό μ¬λ Έμ λ μ€νμΌμ λ³κ²½ν μ΅μ
μ΄λ€.
const options = {
theme: {
series: {
browsers: {
colors: ['#eef4c4', '#77543f', '#b7c72e', '#5b9aa0', '#30076f', '#622569'],
lineWidth: 5,
strokeStyle: '#0000ff',
hover: {
color: '#0000ff',
lineWidth: 5,
strokeStyle: '#000000',
shadowColor: 'rgba(0, 0, 0, 0.5)',
shadowBlur: 10
},
},
versions: {
colors: [
'#cddbda',
'#efd1d1',
'#ea005e',
'#fece2f',
'#fc6104',
'#dd2429',
'#ebc7ff',
'#fece2f',
'#dd2429',
'#ff8d3a',
'#fc6104',
'#5ac18e',
'#8570ff'
],
lineWidth: 2,
strokeStyle: '#ff0000',
hover: {
color: '#ff0000',
lineWidth: 2,
strokeStyle: '#000000',
shadowColor: 'rgba(0, 0, 0, 0.5)',
shadowBlur: 10
}
}
}
}
};
[name]
μ ν΄λΉνλ κ° μ리μ¦λ³λ‘ λΌλ²¨ μ€νμΌμ μ μ©ν μ μλ€. μλ μ½λλ κΈμ μ€νμΌκ³Ό λ§νμ μ μ¬μ©νμ¬ ν
λ§λ₯Ό μ μ©ν μ΅μ
μ΄λ€.
const options = {
series: {
browsers: {
dataLabels: {
visible: true
}
},
versions: {
dataLabels: {
visible: true,
pieSeriesName: { visible: true, anchor: 'outer' }
}
}
},
theme: {
series: {
browsers: {
dataLabels: {
fontFamily: 'fantasy',
fontSize: 13,
useSeriesColor: true,
textBubble: {
visible: true,
backgroundColor: '#333333',
borderRadius: 5,
borderColor: '#ff0000',
borderWidth: 3,
shadowOffsetX: 0,
shadowOffsetY: 0,
shadowBlur: 0,
shadowColor: 'rgba(0, 0, 0, 0)',
},
},
},
versions: {
dataLabels: {
fontFamily: 'monaco',
useSeriesColor: true,
lineWidth: 2,
textStrokeColor: '#ffffff',
shadowColor: '#ffffff',
shadowBlur: 4,
callout: {
lineWidth: 3,
lineColor: '#f44336',
useSeriesColor: false
},
pieSeriesName: {
useSeriesColor: false,
color: '#f44336',
fontFamily: 'fantasy',
fontSize: 13,
textBubble: {
visible: true,
paddingX: 1,
paddingY: 1,
backgroundColor: 'rgba(158, 158, 158, 0.3)',
shadowOffsetX: 0,
shadowOffsetY: 0,
shadowBlur: 0,
shadowColor: 'rgba(0, 0, 0, 0)'
}
}
}
}
}
}
};