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.
<template>
<div class="sample-tutorial">
<gc-spread-sheets class="sample-spreadsheets" @workbookInitialized="initSpread" :newTabVisible=false>
<gc-worksheet></gc-worksheet>
<gc-worksheet> </gc-worksheet>
</gc-spread-sheets>
</div>
</template>
<script setup>
import { ref } from "vue";
import GC from "@mescius/spread-sheets";
import '@mescius/spread-sheets-vue'
let initHorizontalSparkline = function (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(GC.Spread.Sheets.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();
}
let initVerticalSparkline = function (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(GC.Spread.Sheets.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();
}
let initSpread = function (spread) {
initHorizontalSparkline(spread.sheets[0], "Horizontal");
initVerticalSparkline(spread.sheets[1], "Vertical");
}
</script>
<style scoped>
#app {
height: 100%;
}
.sample-tutorial {
position: relative;
height: 100%;
overflow: hidden;
}
.sample-spreadsheets {
width: 100%;
height: 100%;
overflow: hidden;
float: left;
}
body {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
}
</style>
<!DOCTYPE html>
<html style="height:100%;font-size:14px;">
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title>SpreadJS VUE</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" type="text/css"
href="$DEMOROOT$/en/vue3/node_modules/@mescius/spread-sheets/styles/gc.spread.sheets.excel2013white.css">
<script src="$DEMOROOT$/en/vue3/node_modules/systemjs/dist/system.src.js"></script>
<script src="./systemjs.config.js"></script>
<script src="./compiler.js" type="module"></script>
<script>
var System = SystemJS;
System.import("./src/app.js");
System.import('$DEMOROOT$/en/lib/vue3/license.js');
</script>
</head>
<body>
<div id="app"></div>
</body>
</html>
(function (global) {
SystemJS.config({
transpiler: 'plugin-babel',
babelOptions: {
es2015: true
},
paths: {
// paths serve as alias
'npm:': 'node_modules/'
},
packageConfigPaths: [
'./node_modules/*/package.json',
"./node_modules/@mescius/*/package.json",
"./node_modules/@babel/*/package.json",
"./node_modules/@vue/*/package.json"
],
map: {
'vue': "npm:vue/dist/vue.esm-browser.js",
'tiny-emitter': 'npm:tiny-emitter/index.js',
'plugin-babel': 'npm:systemjs-plugin-babel/plugin-babel.js',
"systemjs-babel-build": "npm:systemjs-plugin-babel/systemjs-babel-browser.js",
'@mescius/spread-sheets': 'npm:@mescius/spread-sheets/index.js',
'@mescius/spread-sheets-vue': 'npm:@mescius/spread-sheets-vue/index.js'
},
meta: {
'*.css': { loader: 'systemjs-plugin-css' },
'*.vue': { loader: "../plugin-vue/index.js" }
}
});
})(this);