μ°¨νΈλ³λ‘ μ¬μ©ν μ μλ APIλ μ΄ κ°μ΄λμμ λ€λ£¨μ§ μλλ€. μ¬μ© κ°λ₯ν APIκ° κΆκΈνλ€λ©΄ API κ°μ΄λλ₯Ό μ°Έκ³ νμ.
ColumnLine μ°¨νΈμ μμ± λ°©λ²μ λ κ°μ§κ° μλ€. μμ±μ ν¨μμ μ μ ν¨μλ₯Ό ν΅ν΄ μμ±ν μ μλ€. κ²°κ³Όλ λͺ¨λ μ°¨νΈμ μΈμ€ν΄μ€κ° λ°νλλ€. λ§€κ° λ³μλ μ°¨νΈκ° κ·Έλ €μ§λ μμμΈ HTML μμ el
, λ°μ΄ν°κ°μΈ data
, μ΅μ
κ° options
κ° κ°μ²΄λ‘ λ€μ΄κ°λ€. el
κ°μ μ°¨νΈμ 컨ν
μ΄λ μμμ΄λ―λ‘ μ°¨νΈ μΈμ λ€λ₯Έ μμλ€μ΄ ν¬ν¨λμ΄ μμΌλ©΄ μ°¨νΈμ μν₯μ μ€ μ μμμΌλ‘ λΉμ΄μλ HTML μμλ₯Ό μ¬μ©νλ κ²μ κΆμ₯νλ€.
import { ColumnLineChart } from '@toast-ui/chart';
const chart = new ColumnLineChart({el, data, options});
// νΉμ
import Chart from '@toast-ui/chart';
const chart = Chart.columnLineChart({el, data, options});
λ°μ΄ν°λ series
λ₯Ό ν΅ν΄ μ
λ ₯λ°λλ€. κ° μ°¨νΈμ μ리μ¦λ column
, line
μ κ°κ° μ
λ ₯λλ©° name
κ³Ό data
μμΌλ‘ μ
λ ₯ λ°λλ€. dataλ κ°μ λνλ΄λ λ°°μ΄λ‘ μ
λ ₯νλ€.
const data = {
categories: ['Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct'],
series: {
column: [
{
name: 'Seoul',
data: [11.3, 17.0, 21.0, 24.4, 25.2, 20.4, 13.9],
},
{
name: 'NewYork',
data: [9.9, 16.0, 21.2, 24.2, 23.2, 19.4, 13.3],
},
{
name: 'Sydney',
data: [18.3, 15.2, 12.8, 11.8, 13.0, 15.2, 17.6],
},
{
name: 'Moscow',
data: [4.4, 12.2, 16.3, 18.5, 16.7, 10.9, 4.2],
},
],
line: [
{
name: 'Average',
data: [11, 15.1, 17.8, 19.7, 19.5, 16.5, 12.3],
},
],
},
};
κ°κ°μ series
λ visible
μ΅μ
μ κ°μ§ μ μλ€. visible
μ΅μ
μ μ²μ μ°¨νΈκ° κ·Έλ €μ‘μ λ μ리μ¦λ₯Ό λνλΌμ§μ λν μ¬λΆλ₯Ό κ²°μ νλ€. κΈ°λ³Έκ°μ true
μ΄λ€.
const data = {
categories: ['Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct'],
series: {
column: [
{
name: 'Seoul',
data: [11.3, 17.0, 21.0, 24.4, 25.2, 20.4, 13.9],
visible: false,
},
{
name: 'NewYork',
data: [9.9, 16.0, 21.2, 24.2, 23.2, 19.4, 13.3],
},
{
name: 'Sydney',
data: [18.3, 15.2, 12.8, 11.8, 13.0, 15.2, 17.6],
},
{
name: 'Moscow',
data: [4.4, 12.2, 16.3, 18.5, 16.7, 10.9, 4.2],
},
],
line: [
{
name: 'Average',
data: [11, 15.1, 17.8, 19.7, 19.5, 16.5, 12.3],
visible: false,
},
],
},
}
μ μ΅μ μ μ μ©ν΄ μ°¨νΈλ₯Ό μμ±ν΄λ³΄λ©΄ 체ν¬λ°μ€κ° ν΄μ λμ΄ μμ±λλ κ²μ νμΈν μ μμ΅λλ€.
λ° κ³μ΄ series
λ colorByCategories
μ΅μ
μ κ°μ§ μ μλ€. colorByCategories
μ΅μ
μ μ°¨νΈμ λ§λ μμ μΉ΄ν
κ³ λ¦¬ λ³λ‘ λ€λ₯΄κ² μΉ ν μ§ κ²°μ νλ€. κΈ°λ³Έκ°μ false
μ΄λ€.
const data = {
categories: ['Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct'],
series: {
column: [
{
name: 'Seoul',
data: [11.3, 17.0, 21.0, 24.4, 25.2, 20.4, 13.9],
colorByCategories: true,
},
],
line: [
{
name: 'Average',
data: [11, 15.1, 17.8, 19.7, 19.5, 16.5, 12.3],
},
],
},
}
options
λ κ°μ²΄λ‘ μμ±νλ€. κ°κ° μ°¨νΈμ μ μ©νκ³ μΆμ μ΅μ
μ column
, line
μ μμ±νλ€. μ¬μ©κ°λ₯ν μ΅μ
μ λ€μκ³Ό κ°λ€.
type options = {
chart?: {
//...
}
xAxis?: {
//...
}
yAxis?: {
//...
}
legend?: {
//...
}
exportMenu?: {
//...
}
tooltip?: {
//...
}
responsive?: {
//...
}
theme?: {
// μλ ν
λ§ μ±ν°μμ μ€λͺ
}
series?: {
selectable?: boolean;
column?: {
selectable?: boolean;
stack?: boolean | {
type: 'normal' | 'percent';
connector?: boolean;
};
dataLabels?: {
visible?: boolean;
anchor?: 'center' | 'start' | 'end' | 'auto';
offsetX?: number;
offsetY?: number;
formatter?: (value) => string;
stackTotal?: {
visible?: boolean;
formatter?: (value) => string;
};
};
};
line?: {
selectable?: boolean;
spline?: boolena;
showDot?: boolean;
dataLabels?: {
visible?: boolean;
anchor?: DataLabelAnchor;
offsetX?: number;
offsetY?: number;
formatter?: (value) => string;
}
}
dataLabels?: {
visible?: boolean;
anchor?: DataLabelAnchor;
offsetX?: number;
offsetY?: number;
formatter?: (value) => string;
stackTotal?: {
visible?: boolean;
formatter?: (value) => string;
};
}
}
}
μ΄ μ°¨νΈμμ μ¬μ©ν μ μλ κ³΅ν΅ μ΅μ μ λν΄μλ μ΄ κ°μ΄λμμ λ€λ£¨μ§ μλλ€. νμνλ€λ©΄ ν΄λΉ μ΅μ μ κ°μ΄λλ₯Ό μ°Έκ³ νμ. λν, column, line μ°¨νΈ μ΅μ μ λν΄ κΆκΈνλ€λ©΄ ν΄λΉ κ°μ΄λλ₯Ό μ°Έκ³ νμ. (λ§ν¬:
chart
μ΅μ , μΆ, λ²λ‘, λ΄λ³΄λ΄κΈ°, ν΄ν,responsive
μ΅μ , μ€μκ° μ λ°μ΄νΈ, Column μ°¨νΈ, Line μ°¨νΈ )
ν΄λΉ μ리μ¦λ₯Ό μ νν μ μλ€.
- κΈ°λ³Έκ°:
false
const options = {
series: {
selectable: true
}
};
selectable
μ΅μ
κ³Ό on
APIμ selectSeries
, unselectSeries
λ₯Ό ν¨κ» μ¬μ©ν κ²½μ° ν΄λΉ μ리μ¦μ λν μ μ΄λ₯Ό μΆκ°λ‘ ν μ μλ€.
ν΄νμ λνλΌ λ λ°μνλ λ§μ°μ€ μ€λ²μ μ리μ¦λ₯Ό μ νν λ λ°μνλ λ§μ°μ€ ν΄λ¦ μ λ°μ΄ν°λ₯Ό νμ§νλ λ°©λ²μ μ μνλ€.
νμ | μ€λͺ |
---|---|
grouped |
YμΆμ κΈ°μ€μΌλ‘ κ°μ΄ κ°μ λͺ¨λ λ°μ΄ν°κ° νμ§λ¨ |
point |
κ°λ³ μλ¦¬μ¦ μμμ λ§μ°μ€κ° λ€κ°κ°μΌ νμ§. νμ¬ λ§μ°μ€κ° κ°λ¦¬ν€κ³ μλ ν¬μΈνΈλ₯Ό κΈ°μ€μΌλ‘ λ¨ ν κ°λ§ νμ§λ¨ |
- κΈ°λ³Έκ°:
'grouped'
eventDetectType: 'point'
λ‘ μ€μ ν κ²½μ° line μ리μ¦μ μ κ³Ό column μ리μ¦μ λ°μ€λ₯Ό κ°κ° λ§μ°μ€ ν¬μΈν° κΈ°μ€μΌλ‘ νμ§νλ€.
μ»¬λΌ μ°¨νΈμ λΌμΈ μ°¨νΈμμ μ¬μ©ν μ μλ μ΅μ
μ κ° series.column
κ³Ό series.line
μ μ€μ νλ€.
const options = {
series: {
column: {
stack: {
type: 'normal'
}
},
line: {
showDot: true,
spline: true
}
}
};
series.dataLabels
μ΅μ
μ μ§μ νλ©΄ Columnκ³Ό Line μ°¨νΈμμ λͺ¨λ λ°μ΄ν° λΌλ²¨μ΄ νμλλ€.
const options = {
...
series: {
dataLabels: {
visible: true;
}
}
};
series
μ΅μ
μ κ° μλ¦¬μ¦ λ³λ‘ μ΅μ
μ μ μν μ μμΌλ©°, λ°μ΄ν° λΌλ²¨ κ΄λ ¨ μ΅μ
λ κ° μλ¦¬μ¦ λ³λ‘ μ’ λ μΈλ°νκ² μ€μ ν΄ μ€ μ μλ€.
type ColumnLineChartSeriesOption = {
column: { // Column μλ¦¬μ¦ μ΅μ
...
dataLabels: {
// Column μλ¦¬μ¦ λ°μ΄ν° λΌλ²¨ μ΅μ
}
},
line: { // Line μλ¦¬μ¦ μ΅μ
...
dataLabels: {
// Line μλ¦¬μ¦ λ°μ΄ν° λΌλ²¨ μ΅μ
}
}
};
μλ μ½λλ Line μ리μ¦μ λ°μ΄ν° λΌλ²¨μ νμν΄μ£Όμ§ μκ³ , Column μ리μ¦μ λ°μ΄ν° λΌλ²¨λ§ νμνλλ‘ μ€μ ν μ΅μ μ΄λ€.
const options = {
series: {
column: {
stack: true,
dataLabels: {
visible: true,
stackTotal: {
visible: false
}
}
}
}
};
κ°κ°μ μ€νμΌμ μ§μ ν κ²½μ° series.column
νΉμ series.line
μ μ μνλ€. μ리μ¦μ μμμ μ§μ νκ³ μΆμ κ²½μ° colors
λ₯Ό μ
λ ₯νκ±°λ κ°κ° μ리μ¦λ₯Ό ꡬλΆν΄ μμμ λΆμ¬νκ³ μΆλ€λ©΄ ꡬλΆν΄μ λ£μ΄μ£Όλ©΄ λλ€.
interface ColumnLineChartSeriesTheme {
colors: string[];
column: {
// column chart μλ¦¬μ¦ ν
λ§
};
line: {
// line chart μλ¦¬μ¦ ν
λ§
};
};
κ°λ¨ν μμλ‘ μ¬λ¬κ°μ§ μ€νμΌμ κ°κ°μ μ°¨νΈμ λ§κ² μμ±ν΄λ³΄μ.
const theme = {
theme: {
series: {
colors: ['#70d6ff', '#ff70a6', '#ff9770', '#ffd670', '#bfe000'],
column: {
barWidth: 18
},
line: {
dot: {
radius: 6,
borderColor: '#ffff00',
borderWidth: 2
}
}
}
}
};
κ²°κ³Όλ λ€μκ³Ό κ°λ€.
κ° μλ¦¬μ¦ λ³λ‘ λ°μ΄ν° λΌλ²¨μ μ€νμΌμ μ§μ ν κ²½μ° series.column.dataLabels
λλ series.line.dataLabels
λ₯Ό μ μνλ€.
type ColumnLineChartDataLabelTheme = {
series: {
column: {
dataLabels: {
// Column μλ¦¬μ¦ λ°μ΄ν° λΌλ²¨ ν
λ§
}
},
line: {
dataLabels: {
// Line μλ¦¬μ¦ λ°μ΄ν° λΌλ²¨ ν
λ§
}
}
}
};
κ°λ¨ν μμλ‘ Column μλ¦¬μ¦ λ°μ΄ν° λΌλ²¨μλ κΈμ μμκ³Ό ν¬κΈ°, κ΅΅κΈ° λ±μ μ‘°μ νκ³ , Line μλ¦¬μ¦ λ°μ΄ν° λΌλ²¨μλ λ§νμ μ€νμΌμ λ³κ²½ν΄λ³΄μλ€.
const options = {
series: {
column: {
dataLabels: { visible: true, anchor: 'start' }
},
line: {
showDot: true,
dataLabels: { visible: true, offsetY: -15 }
}
},
theme: {
series: {
column: {
dataLabels: {
color: '#ffffff',
fontSize: 10,
fontWeight: 600
}
},
line: {
dataLabels: {
fontSize: 10,
fontWeight: 300,
useSeriesColor: true,
textBubble: {
visible: true,
paddingY: 3,
paddingX: 6,
arrow: {
visible: true,
width: 5,
height: 5,
direction: 'bottom'
}
}
}
}
}
}
};
column μ°¨νΈμ line μ°¨νΈμ ν λ§λ κ°κ°μ κ°μ΄λλ₯Ό μ°Έκ³ νλ€.