Stacked

A stacked sparkline is useful for comparing values to each other and across categories.

<p>You can create a stacked sparkline using the StackedSparkline function in a formula: <strong>=STACKEDSPARKLINE(points, colorRange?, labelRange?, maximum?, targetRed?, targetGreen?, targetBlue?, tragetYellow?, color?, highlightPosition?, vertical?, textOrientation?, textSize?)</strong>.</p> <p>The function has the following parameters:</p> <p><strong>points</strong>: Reference that represents the range of cells containing all the values, such as "A1:A4".</p> <p><strong>colorRange</strong>: (optional) Reference that represents the range of cells containing all the colors, such as "B1:B4"; default value is generated by color.</p> <p><strong>labelRange</strong>: (optional) Reference that represents the range of cells containing all the labels, such as "C1:C4"; default value is empty string.</p> <p><strong>maximum</strong>: (optional) Number that represents the maximum value of the sparkline; default value is the summary of all positive values.</p> <p><strong>targetRed</strong>: (optional) Number that represents the location of the red line; default value is empty string.</p> <p><strong>targetGreen</strong>: (optional) Number that represents the location of the green line; default value is empty string.</p> <p><strong>targetBlue</strong>: (optional) Number that represents the location of the blue line; default value is empty string.</p> <p><strong>targetYellow</strong>: (optional) Number that represents the location of the yellow line; default value is empty string.</p> <p><strong>color</strong>: (optional) A string that represents the color for generating colors if colorRange is omitted; default value is "#646464".</p> <p><strong>highlightPosition</strong>: (optional) Number that represents the index of the highlight area; default value is empty string.</p> <p><strong>vertical</strong>: (optional) Boolean that represents whether to display the sparkline vertically. The default value is false.</p> <p><strong>textOrientation</strong>: (optional) Number that represents the orientation of the label text. One of the following:</p> <ul> <li><strong>0: (default) Horizontal</strong></li> <li><strong>1: Vertical</strong></li> </ul> <p><strong>textSize</strong>: (optional) Number that represents the size (in px) of the label text; default value is 10.</p>
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, 5); sheet.getCell(0, 0).value("Sales by State").font("20px Arial").hAlign(spreadNS.HorizontalAlign.center).vAlign(spreadNS.VerticalAlign.center); sheet.getRange(1, 0, 1, 5).foreColor("white").backColor("Accent 4").hAlign(spreadNS.HorizontalAlign.center).vAlign(spreadNS.VerticalAlign.center); sheet.setValue(1, 0, "State"); sheet.setValue(1, 1, "Product 1"); sheet.setValue(1, 2, "Product 2"); sheet.setValue(1, 3, "Product 3"); sheet.setValue(1, 4, "Diagram"); sheet.setValue(2, 0, "Idaho"); sheet.setValue(2, 1, 10000); sheet.setValue(2, 2, 12000); sheet.setValue(2, 3, 15000); sheet.setValue(3, 0, "Montana"); sheet.setValue(3, 1, 11000); sheet.setValue(3, 2, 10000); sheet.setValue(3, 3, 15000); sheet.setValue(4, 0, "Oregon"); sheet.setValue(4, 1, 10000); sheet.setValue(4, 2, 17000); sheet.setValue(4, 3, 12000); sheet.setValue(5, 0, "Washington"); sheet.setValue(5, 1, 15000); sheet.setValue(5, 2, 10000); sheet.setValue(5, 3, 15000); sheet.setValue(6, 0, "Utah"); sheet.setValue(6, 1, 10000); sheet.setValue(6, 2, 15000); sheet.setValue(6, 3, 12000); sheet.setValue(7, 1, "orange"); sheet.setValue(7, 2, "purple"); sheet.setValue(7, 3, "yellowgreen"); sheet.setFormatter(-1, 1, "$#,##0"); sheet.setFormatter(-1, 2, "$#,##0"); sheet.setFormatter(-1, 3, "$#,##0"); sheet.setFormula(2, 4, '=STACKEDSPARKLINE(B3:D3,$B$8:$D$8,$B$2:$D$2,40000)'); sheet.setFormula(3, 4, '=STACKEDSPARKLINE(B4:D4,$B$8:$D$8,$B$2:$D$2,40000)'); sheet.setFormula(4, 4, '=STACKEDSPARKLINE(B5:D5,$B$8:$D$8,$B$2:$D$2,40000)'); sheet.setFormula(5, 4, '=STACKEDSPARKLINE(B6:D6,$B$8:$D$8,$B$2:$D$2,40000)'); sheet.setFormula(6, 4, '=STACKEDSPARKLINE(B7:D7,$B$8:$D$8,$B$2:$D$2,40000)'); sheet.setRowHeight(0, 50); sheet.setRowHeight(1, 25); for (var i = 2; i < 7; i++) { sheet.setRowHeight(i, 45); } sheet.setRowHeight(7, 0); sheet.setColumnWidth(0, 100); sheet.setColumnWidth(1, 120); sheet.setColumnWidth(2, 120); sheet.setColumnWidth(3, 120); sheet.setColumnWidth(4, 200); sheet.resumePaint(); } function initVerticalSparkline(sheet, name) { sheet.suspendPaint(); sheet.name(name); sheet.addSpan(0, 0, 1, 6); sheet.getCell(0, 0).value("Sales by State").font("20px Arial").hAlign(spreadNS.HorizontalAlign.center).vAlign(spreadNS.VerticalAlign.center); sheet.getRange(1, 0, 1, 6).foreColor("white").backColor("Accent 4").hAlign(spreadNS.HorizontalAlign.center).vAlign(spreadNS.VerticalAlign.center); sheet.getRange(2, 0, 4, 6).vAlign(spreadNS.VerticalAlign.center); sheet.setFormatter(-1, 1, "$#,##0"); sheet.setFormatter(-1, 2, "$#,##0"); sheet.setFormatter(-1, 3, "$#,##0"); sheet.setFormatter(-1, 4, "$#,##0"); sheet.setFormatter(-1, 5, "$#,##0"); sheet.setColumnWidth(0, 120); sheet.setColumnWidth(1, 120); sheet.setColumnWidth(2, 120); sheet.setColumnWidth(3, 120); sheet.setColumnWidth(4, 120); sheet.setColumnWidth(5, 120); for (var i = 1; i < 5; i++) { sheet.setRowHeight(i, 45); } sheet.setRowHeight(5, 200); sheet.setColumnWidth(6, 0); sheet.setValue(2, 6, "orange"); sheet.setValue(3, 6, "purple"); sheet.setValue(4, 6, "yellowgreen"); sheet.setValue(1, 0, "state"); sheet.setValue(2, 0, "Product 1"); sheet.setValue(3, 0, "Product 2"); sheet.setValue(4, 0, "Product 3"); sheet.setValue(5, 0, "Diagram"); sheet.setValue(1, 1, "Idaho"); sheet.setValue(2, 1, 10000); sheet.setValue(3, 1, 12000); sheet.setValue(4, 1, 15000); sheet.setFormula(5, 1, '=STACKEDSPARKLINE(B$3:B$5,$G$3:$G$5,$A$3:$A$5,40000,,,,,,,TRUE)'); sheet.setValue(1, 2, "Montana"); sheet.setValue(2, 2, 11000); sheet.setValue(3, 2, 10000); sheet.setValue(4, 2, 15000); sheet.setFormula(5, 2, '=STACKEDSPARKLINE(C$3:C$5,$G$3:$G$5,$A$3:$A$5,40000,,,,,,,TRUE)'); sheet.setValue(1, 3, "Oregon"); sheet.setValue(2, 3, 10000); sheet.setValue(3, 3, 17000); sheet.setValue(4, 3, 12000); sheet.setFormula(5, 3, '=STACKEDSPARKLINE(D$3:D$5,$G$3:$G$5,$A$3:$A$5,40000,,,,,,,TRUE)'); sheet.setValue(1, 4, "Washington"); sheet.setValue(2, 4, 15000); sheet.setValue(3, 4, 10000); sheet.setValue(4, 4, 15000); sheet.setFormula(5, 4, '=STACKEDSPARKLINE(E$3:E$5,$G$3:$G$5,$A$3:$A$5,40000,,,,,,,TRUE)'); sheet.setValue(1, 5, "Utah"); sheet.setValue(2, 5, 10000); sheet.setValue(3, 5, 15000); sheet.setValue(4, 5, 12000); sheet.setFormula(5, 5, '=STACKEDSPARKLINE(F$3:F$5,$G$3:$G$5,$A$3:$A$5,40000,,,,,,,TRUE)'); 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/@grapecity/spread-sheets/styles/gc.spread.sheets.excel2013white.css"> <script src="$DEMOROOT$/en/purejs/node_modules/@grapecity/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; }