Data Charts support waterfall type. To use the Waterfall Chart, you can set the data chart type to GC.Spread.Sheets.DataCharts.DataChartType.waterfall.
For example, you can insert a waterfall data chart and configure the data chart by method setChartConfig.
Notes: before using the data chart, tables in data manager should be initialized.
window.onload = async () => {
const { spread, designer } = createSpreadAndDesigner();
await initDataManager(spread);
const sheet = spread.getSheet(0);
sheet.name('Waterfall');
const dataChart1 = sheet.dataCharts.add('chart1', 20, 20, 450, 300, GC.Spread.Sheets.DataCharts.DataChartType.waterfall);
dataChart1.setChartConfig({
tableName: 'Profits',
plots: [{
type: GC.Spread.Sheets.DataCharts.DataChartType.waterfall,
encodings: {
values: [{ field: 'Profits', aggregate: GC.Spread.Sheets.DataCharts.Aggregate.sum }],
category: { field: 'Month' },
},
}],
config: {
header: {
title: 'Waterfall Chart',
padding: {
left: 10,
right: 10,
top: 10,
bottom: 10,
},
textStyle: {
fontSize: 19,
fontStyle: GC.Spread.Sheets.DataCharts.FontStyle.italic,
alignment: GC.Spread.Sheets.DataCharts.HAlign.left,
},
},
plotAreas: [{
legends: [{
type: GC.Spread.Sheets.DataCharts.LegendType.color,
textStyle: {
color: 'rgba(51,51,51,1)',
fontFamily: 'Calibri',
fontSize: 12,
},
}],
}],
},
});
const dataChart2 = sheet.dataCharts.add('chart2', 490, 20, 450, 300, GC.Spread.Sheets.DataCharts.DataChartType.waterfall);
dataChart2.setChartConfig({
tableName: 'Profits',
plots: [{
type: GC.Spread.Sheets.DataCharts.DataChartType.waterfall,
encodings: {
values: [{ field: 'Profits', aggregate: GC.Spread.Sheets.DataCharts.Aggregate.sum }],
category: { field: 'Month' },
},
config: {
waterfall: {
showTotal: false,
},
},
}],
config: {
header: {
title: 'Waterfall Chart',
padding: {
left: 10,
right: 10,
top: 10,
bottom: 10,
},
textStyle: {
fontSize: 19,
fontStyle: GC.Spread.Sheets.DataCharts.FontStyle.italic,
alignment: GC.Spread.Sheets.DataCharts.HAlign.left,
},
},
plotAreas: [{
legends: [{
type: GC.Spread.Sheets.DataCharts.LegendType.color,
textStyle: {
color: 'rgba(51,51,51,1)',
fontFamily: 'Calibri',
fontSize: 12,
},
}],
}],
},
});
const dataChart3 = sheet.dataCharts.add('chart3', 20, 340, 450, 300, GC.Spread.Sheets.DataCharts.DataChartType.waterfall);
dataChart3.setChartConfig({
tableName: 'Profits',
plots: [{
type: GC.Spread.Sheets.DataCharts.DataChartType.waterfall,
encodings: {
values: [{ field: 'Profits', aggregate: GC.Spread.Sheets.DataCharts.Aggregate.sum }],
category: { field: 'Month' },
},
config: {
palette: ['#81c995', '#f28b82', '#bdbdbd'],
style: {
strokeWidth: 2,
},
waterfall: {
totalLabel: 'Total Profits',
connectingLineStyle: {
stroke: { type: 'CssColor', color: '#c3c3c3' },
strokeWidth: 2,
},
},
},
}],
config: {
header: {
title: 'Waterfall Chart',
padding: {
left: 10,
right: 10,
top: 10,
bottom: 10,
},
textStyle: {
fontSize: 19,
fontStyle: GC.Spread.Sheets.DataCharts.FontStyle.italic,
alignment: GC.Spread.Sheets.DataCharts.HAlign.left,
},
},
plotAreas: [{
legends: [{
type: GC.Spread.Sheets.DataCharts.LegendType.color,
textStyle: {
color: 'rgba(51,51,51,1)',
fontFamily: 'Calibri',
fontSize: 12,
},
}],
}],
},
});
const dataChart4 = sheet.dataCharts.add('chart4', 490, 340, 450, 300, GC.Spread.Sheets.DataCharts.DataChartType.waterfall);
dataChart4.setChartConfig({
tableName: 'Profits',
plots: [{
type: GC.Spread.Sheets.DataCharts.DataChartType.waterfall,
encodings: {
values: [{ field: 'Profits', aggregate: GC.Spread.Sheets.DataCharts.Aggregate.sum }],
category: { field: 'Month' },
},
config: {
waterfall: {
orientation: GC.Spread.Sheets.DataCharts.Orientation.horizontal,
},
},
}],
config: {
header: {
title: 'Waterfall Chart',
padding: {
left: 10,
right: 10,
top: 10,
bottom: 10,
},
textStyle: {
fontSize: 19,
fontStyle: GC.Spread.Sheets.DataCharts.FontStyle.italic,
alignment: GC.Spread.Sheets.DataCharts.HAlign.left,
},
},
plotAreas: [{
legends: [{
type: GC.Spread.Sheets.DataCharts.LegendType.color,
textStyle: {
color: 'rgba(51,51,51,1)',
fontFamily: 'Calibri',
fontSize: 12,
},
}],
}],
},
});
spread.getActiveSheet().dataCharts.all()[0].isSelected(true);
if (designer) {
designer.refresh();
}
}
function createSpreadAndDesigner() {
const demoHost = document.getElementById('demo-host');
if (window !== top) {
const spread = new GC.Spread.Sheets.Workbook('spread-host', { sheetCount: 1 });
new GC.Spread.Sheets.DataCharts.DataChartConfigPanel('panel-host', spread);
return {
spread
}
} else {
const designer = new GC.Spread.Sheets.Designer.Designer(demoHost, undefined, undefined, { sheetCount: 1 });
return {
designer,
spread: designer.getWorkbook(),
}
}
}
async function initDataManager(spread) {
const records = [
['Jan', 100],
['Feb', -30],
['Mar', 130],
['Apr', 60],
['May', -110],
['Jun', 210],
['Jul', 90],
['Aug', 30],
['Sep', -100],
['Oct', -30],
['Nov', 90],
['Dec', 150],
];
const columns = ['Month', 'Profits'];
await spread.dataManager().addTable('Profits', {
data: records.map(record => {
const item = {};
columns.forEach((column, index) => {
item[column] = record[index];
});
return item;
}),
}).fetch();
}
<!doctype html>
<html style="height:100%;font-size:14px;">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" type="text/css" href="$DEMOROOT$/en/purejs/node_modules/@mescius/spread-sheets/styles/gc.spread.sheets.excel2013white.css">
<link rel="stylesheet" type="text/css" href="$DEMOROOT$/en/purejs/node_modules/@mescius/spread-sheets-designer/styles/gc.spread.sheets.designer.light.min.css">
<link rel="stylesheet" type="text/css" href="styles.css">
<script src="$DEMOROOT$/en/purejs/node_modules/@mescius/spread-sheets/dist/gc.spread.sheets.all.min.js" type="text/javascript"></script>
<script src="$DEMOROOT$/en/purejs/node_modules/@mescius/spread-sheets-print/dist/gc.spread.sheets.print.min.js" type="text/javascript"></script>
<script src="$DEMOROOT$/en/purejs/node_modules/@mescius/spread-sheets-shapes/dist/gc.spread.sheets.shapes.min.js" type="text/javascript"></script>
<script src="$DEMOROOT$/en/purejs/node_modules/@mescius/spread-sheets-datacharts-addon/dist/gc.spread.sheets.datacharts.min.js" type="text/javascript"></script>
<script src="$DEMOROOT$/en/purejs/node_modules/@mescius/spread-sheets-tablesheet/dist/gc.spread.sheets.tablesheet.min.js" type="text/javascript"></script>
<script src="$DEMOROOT$/spread/source/js/license.js" type="text/javascript"></script>
<script>
const designerDependencyScripts = [
'$DEMOROOT$/en/purejs/node_modules/@mescius/spread-sheets-charts/dist/gc.spread.sheets.charts.min.js',
'$DEMOROOT$/en/purejs/node_modules/@mescius/spread-sheets-barcode/dist/gc.spread.sheets.barcode.min.js',
'$DEMOROOT$/en/purejs/node_modules/@mescius/spread-sheets-pdf/dist/gc.spread.sheets.pdf.min.js',
'$DEMOROOT$/en/purejs/node_modules/@mescius/spread-sheets-pivot-addon/dist/gc.spread.pivot.pivottables.min.js',
'$DEMOROOT$/en/purejs/node_modules/@mescius/spread-sheets-slicers/dist/gc.spread.sheets.slicers.min.js',
'$DEMOROOT$/en/purejs/node_modules/@mescius/spread-sheets-reportsheet-addon/dist/gc.spread.report.reportsheet.min.js',
'$DEMOROOT$/en/purejs/node_modules/@mescius/spread-sheets-ganttsheet/dist/gc.spread.sheets.ganttsheet.min.js',
'$DEMOROOT$/en/purejs/node_modules/@mescius/spread-sheets-formula-panel/dist/gc.spread.sheets.formulapanel.min.js',
'$DEMOROOT$/en/purejs/node_modules/@mescius/spread-sheets-io/dist/gc.spread.sheets.io.min.js',
'$DEMOROOT$/en/purejs/node_modules/@mescius/spread-sheets-designer-resources-en/dist/gc.spread.sheets.designer.resource.en.min.js',
'$DEMOROOT$/en/purejs/node_modules/@mescius/spread-sheets-designer/dist/gc.spread.sheets.designer.all.min.js',
'$DEMOROOT$/spread/source/js/designer/license.js',
]
function appendScriptNode (src) {
const script = document.createElement('script');
script.src = src;
script.async = false;
script.type = 'text/javascript';
document.head.appendChild(script);
}
if (top === window) { // not in iframe
designerDependencyScripts.forEach(appendScriptNode);
}
</script>
<script src="app.js" type="text/javascript"></script>
</head>
<body>
<div class="sample-tutorial">
<div id="demo-host">
<div id="spread-host"></div>
<div id="panel-host"></div>
</div>
</div>
</body>
</html>
body {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
}
.sample-tutorial {
position: relative;
height: 100%;
overflow: hidden;
}
#demo-host {
width: 100%;
height: 100%;
overflow: hidden;
float: left;
}
#spread-host {
position: absolute;
top: 0;
left: 0;
width: calc(100% - 380px);
height: 100%;
}
#panel-host {
position: absolute;
top: 0;
right: 0;
width: 380px;
height: 100%;
}