JavaScript
// 월별 매출액(백만원)과 전년 대비 증감률(비율)
const data = [
{ month: '1월', sales: 320, growth: 0.05 },
{ month: '2월', sales: 345, growth: 0.07 },
{ month: '3월', sales: 360, growth: 0.06 },
{ month: '4월', sales: 410, growth: 0.12 },
{ month: '5월', sales: 395, growth: 0.09 },
{ month: '6월', sales: 440, growth: 0.13 },
{ month: '7월', sales: 470, growth: 0.15 },
{ month: '8월', sales: 455, growth: 0.11 },
{ month: '9월', sales: 500, growth: 0.16 },
{ month: '10월', sales: 520, growth: 0.18 },
{ month: '11월', sales: 505, growth: 0.14 },
{ month: '12월', sales: 560, growth: 0.21 }
];
// 1) 컬럼 + 라인 혼합 차트 생성
const chart = new wijmo.chart.FlexChart('#salesChart', {
itemsSource: data,
bindingX: 'month',
chartType: 'Column',
legendToggle: true,
series: [
{ name: '매출액', binding: 'sales' },
{ name: '증감률', binding: 'growth', chartType: 'LineSymbols' }
]
});
// 2) 보조 Y축 생성 후 두 번째 시리즈에 연결
const axisY2 = new wijmo.chart.Axis();
axisY2.position = 'Right';
axisY2.title = '전년 대비 증감률';
axisY2.format = 'p0';
axisY2.min = 0;
axisY2.max = 0.24; // 6칸
axisY2.majorUnit = 0.04;
axisY2.axisLine = true;
axisY2.majorGrid = false; // 눈금선은 기본 축에만 표시
chart.series[1].axisY = axisY2;
// 3) 기본(왼쪽) Y축 설정
chart.axisY.title = '매출액 (백만원)';
chart.axisY.format = 'n0';
chart.axisY.min = 0;
chart.axisY.max = 600; // 6칸 — 보조 축과 눈금 개수를 맞춤
chart.axisY.majorUnit = 100;
// 4) 시리즈 색상 및 축 라벨 색상 매칭
chart.series[0].style = { fill: '#4e79a7' };
chart.series[1].style = { stroke: '#e15759', strokeWidth: 3 };
chart.series[1].symbolStyle = { fill: '#e15759', stroke: '#e15759' };
chart.axisY.itemFormatter = function (engine, label) {
engine.textFill = '#4e79a7';
label.cls = null;
return label;
};
axisY2.itemFormatter = function (engine, label) {
engine.textFill = '#e15759';
label.cls = null;
return label;
};