SpreadJS는 폭포 차트를 지원합니다. GC.Spread.Sheets.Charts.ChartType.waterfall 속성을 사용하여 차트 유형을 가져옵니다. 값을 더하거나 빼면 폭포 차트에 누계가 표시됩니다. 폭포 차트는 초기 값(예: 순 수입)이 일련의 양수 및 음수 값에 어떤 영향을 받는지 파악하는 데 유용합니다. SpreadJS에 폭포 차트를 추가하고 차트 API를 사용하여 스타일을 변경할 수 있습니다.
window.onload = function () {
let spread = new GC.Spread.Sheets.Workbook(document.getElementById("ss"), {
sheetCount: 2
});
initSpread(spread);
};
function initSpread(spread) {
let sheets = spread.sheets;
spread.suspendPaint();
spread.fromJSON(data);
let customWaterfallChart = sheets[0].charts.add("customWaterfallChart", GC.Spread.Sheets.Charts.ChartType.waterfall, 400, 0, 700, 450, "B2:C15");
let baseWaterfallChart = sheets[1].charts.add("baseWaterfallChart", GC.Spread.Sheets.Charts.ChartType.waterfall, 400, 0, 700, 450, "B2:C15");
setCustomStyle(customWaterfallChart);
setBaseStyle(baseWaterfallChart);
spread.resumePaint();
}
function setCustomStyle(chart) {
let chartArea = chart.chartArea();
chartArea.fontSize = 14;
chart.chartArea(chartArea);
let dataLabels = chart.dataLabels();
dataLabels.showValue = true;
dataLabels.color = 'rgb(64,60,61)';
dataLabels.position = GC.Spread.Sheets.Charts.DataLabelPosition.center;
chart.dataLabels(dataLabels);
let legend = chart.legend();
legend.position = GC.Spread.Sheets.Charts.LegendPosition.bottom;
chart.legend(legend)
let title = chart.title();
title.text = "Monthly Income";
title.fontSize = 16;
chart.title(title);
let series = chart.series().get(0);
series.showConnectorLines = true;
series.gapWidth = 0.2;
series.subtotals = [0, 13];
chart.series().set(0, series);
chart.formatOvers({
0: {
backColor: "rgb(61,198,147)",
},
1: {
backColor: "rgb(225,128,99)",
},
2: {
backColor: "rgb(91,188,214)",
}
});
}
function setBaseStyle(chart) {
let title = chart.title();
title.text = "Monthly Income";
title.fontSize = 16;
chart.title(title);
let series = chart.series().get(0);
series.showConnectorLines = true;
series.subtotals = [13];
chart.series().set(0, series);
}
<!doctype html>
<html style="height:100%;font-size:14px;">
<head>
<meta charset="utf-8" />
<meta name="spreadjs culture" content="ko-kr"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" type="text/css" href="$DEMOROOT$/ko/purejs/node_modules/@mescius/spread-sheets/styles/gc.spread.sheets.excel2013white.css">
<script src="$DEMOROOT$/ko/purejs/node_modules/@mescius/spread-sheets/dist/gc.spread.sheets.all.min.js" type="text/javascript"></script>
<script src="$DEMOROOT$/ko/purejs/node_modules/@mescius/spread-sheets-shapes/dist/gc.spread.sheets.shapes.min.js" type="text/javascript"></script>
<script src="$DEMOROOT$/ko/purejs/node_modules/@mescius/spread-sheets-charts/dist/gc.spread.sheets.charts.min.js" type="text/javascript"></script>
<script src="$DEMOROOT$/ko/purejs/node_modules/@mescius/spread-sheets-resources-ko/dist/gc.spread.sheets.resources.ko.min.js" type="text/javascript"></script>
<script src="$DEMOROOT$/spread/source/js/license.js" type="text/javascript"></script>
<script src="$DEMOROOT$/spread/source/data/waterfallData.js" type="text/javascript"></script>
<script src="app.js" type="text/javascript"></script>
<link rel="stylesheet" type="text/css" href="styles.css">
</head>
<body>
<div class="sample-tutorial">
<div id="ss" class="sample-tutorial"></div>
</div>
</body>
</html>
.sample-tutorial {
position: relative;
height: 100%;
overflow: hidden;
}
body {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
}