You can create a Stacked sparkline using the StackedSparkline function in a formula: =STACKEDSPARKLINE(points, colorRange?, labelRange?, maximum?, targetRed?, targetGreen?, targetBlue?, tragetYellow?, color?, highlightPosition?, vertical?, textOrientation?, textSize?).
The function has the following parameters:
points: Reference that represents the range of cells containing all the values, such as "A1:A4".
colorRange: (optional) Reference that represents the range of cells containing all the colors, such as "B1:B4"; default value is generated by color.
labelRange: (optional) Reference that represents the range of cells containing all the labels, such as "C1:C4"; default value is empty string.
maximum: (optional) Number that represents the maximum value of the sparkline; default value is the summary of all positive values.
targetRed: (optional) Number that represents the location of the red line; default value is empty string.
targetGreen: (optional) Number that represents the location of the green line; default value is empty string.
targetBlue: (optional) Number that represents the location of the blue line; default value is empty string.
targetYellow: (optional) Number that represents the location of the yellow line; default value is empty string.
color: (optional) A string that represents the color for generating colors if colorRange is omitted; default value is "#646464".
highlightPosition: (optional) Number that represents the index of the highlight area; default value is empty string.
vertical: (optional) Boolean that represents whether to display the sparkline vertically. The default value is false.
textOrientation: (optional) Number that represents the orientation of the label text. One of the following:
0: (default) Horizontal
1: Vertical
textSize: (optional) Number that represents the size (in px) of the label text; default value is 10.
var spreadNS = GC.Spread.Sheets;
window.onload = function () {
var spread = new GC.Spread.Sheets.Workbook(document.getElementById("ss"), { sheetCount: 2 });
initSpread(spread);
};
function initSpread(spread) {
spread.options.newTabVisible = false;
initHorizontalSparkline(spread.sheets[0], "Horizontal");
initVerticalSparkline(spread.sheets[1], "Vertical");
};
function initHorizontalSparkline(sheet, name) {
sheet.suspendPaint();
sheet.name(name);
sheet.addSpan(0, 0, 1, 7);
sheet.getCell(0, 0).value("Quarterly Sales by Regions 2020").font("20px Arial").vAlign(spreadNS.VerticalAlign.center);
for (var i = 0; i < 7; i++) {
sheet.getCell(1,i).backColor("#E3E3E3");
sheet.setColumnWidth(i, 90);
sheet.setFormatter(-1, i, "$#,##0");
}
sheet.setArray(1, 0, [
["Quarter", "Color Range","East", "West", "North","South","Diagram"],
["Q1","#82BC00", 42000,45000,26000,38000],
["Q2","#AED069", 52000,35000,45000,20000],
["Q3","#D4E3AF", 25000,34000,55000,19000],
["Q4","#F4F8EB", 50000,25000,60000,20000]]);
sheet.setFormula(2, 6, '=STACKEDSPARKLINE(C3:F3,$B$3:$B$6,$C$2:$F$2,170000)');
sheet.setFormula(3, 6, '=STACKEDSPARKLINE(C4:F4,$B$3:$B$6,$C$2:$F$2,170000)');
sheet.setFormula(4, 6, '=STACKEDSPARKLINE(C5:F5,$B$3:$B$6,$C$2:$F$2,170000)');
sheet.setFormula(5, 6, '=STACKEDSPARKLINE(C6:F6,$B$3:$B$6,$C$2:$F$2,170000)');
sheet.setFormula(6, 6, '=STACKEDSPARKLINE(C7:F7,$B$3:$B$6,$C$2:$F$2,170000)');
sheet.setRowHeight(0, 30);
sheet.setRowHeight(1, 25);
for (var i = 2; i < 6; i++) {
sheet.setRowHeight(i, 30);
}
sheet.setColumnWidth(6, 250);
//hide Color Range column
sheet.setColumnWidth(1, 0);
sheet.resumePaint();
}
function initVerticalSparkline(sheet, name) {
sheet.suspendPaint();
sheet.name(name);
sheet.addSpan(0, 0, 1, 5);
sheet.getCell(0, 0).value("Quarterly Sales by Regions 2020").font("20px Arial").vAlign(spreadNS.VerticalAlign.center);
for (var i = 0; i < 5; i++) {
sheet.getCell(1,i).backColor("#E3E3E3");
sheet.setColumnWidth(i, 90);
sheet.setFormatter(-1, i, "$#,##0");
}
sheet.setArray(1, 0, [
["Quarter", "Q1", "Q2", "Q3","Q4"],
["Color Range", "#82BC00","#AED069","#D4E3AF","#F4F8EB"],
["East",42000,52000,25000,50000],
["West",45000,35000,34000,25000],
["North",26000,45000,55000,60000],
["South",38000,20000,19000,20000]]);
sheet.setFormula(7, 1, '=STACKEDSPARKLINE(B$4:B$7,$B$3:$E$3,$A$4:$A$7,170000,,,,,,,TRUE)');
sheet.setFormula(7, 2, '=STACKEDSPARKLINE(C$4:C$7,$B$3:$E$3,$A$4:$A$7,170000,,,,,,,TRUE)');
sheet.setFormula(7, 3, '=STACKEDSPARKLINE(D$4:D$7,$B$3:$E$3,$A$4:$A$7,170000,,,,,,,TRUE)');
sheet.setFormula(7, 4, '=STACKEDSPARKLINE(E$4:E$7,$B$3:$E$3,$A$4:$A$7,170000,,,,,,,TRUE)');
sheet.setFormula(7, 5, '=STACKEDSPARKLINE(F$4:F$7,$B$3:$E$3,$A$4:$A$7,170000,,,,,,,TRUE)');
for (var i = 0; i < 7; i++) {
sheet.setRowHeight(i, 30);
}
sheet.setRowHeight(2, 0);
sheet.setRowHeight(7, 180);
sheet.resumePaint();
}
<!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">
<script src="$DEMOROOT$/en/purejs/node_modules/@mescius/spread-sheets/dist/gc.spread.sheets.all.min.js" type="text/javascript"></script>
<script src="$DEMOROOT$/spread/source/js/license.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" style="width:100%;height:100%"></div>
</div>
</body>
</html>
.sample-tutorial {
position: relative;
height: 100%;
overflow: hidden;
}
body {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
}