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.
import { Component, NgModule, enableProdMode } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { SpreadSheetsModule } from '@mescius/spread-sheets-angular';
import GC from '@mescius/spread-sheets';
import './styles.css';
@Component({
selector: 'app-component',
templateUrl: 'src/app.component.html'
})
export class AppComponent {
spread: GC.Spread.Sheets.Workbook;
hostStyle = {
width: '100%',
height: '100%',
overflow: 'hidden',
float: 'left'
}
initHorizontalSparkline(sheet: GC.Spread.Sheets.Worksheet, name: string) {
sheet.suspendPaint();
sheet.name(name);
let spreadNS = GC.Spread.Sheets;
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();
}
initVerticalSparkline(sheet: GC.Spread.Sheets.Worksheet, name: string) {
sheet.suspendPaint();
sheet.name(name);
let spreadNS = GC.Spread.Sheets;
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();
}
initSpread($event: any) {
this.spread = $event.spread;
let spread = this.spread;
this.initHorizontalSparkline(spread.sheets[0], "Horizontal");
this.initVerticalSparkline(spread.sheets[1], "Vertical");
}
}
@NgModule({
imports: [BrowserModule, SpreadSheetsModule],
declarations: [AppComponent],
exports: [AppComponent],
bootstrap: [AppComponent]
})
export class AppModule { }
enableProdMode();
// Bootstrap application with hash style navigation and global services.
platformBrowserDynamic().bootstrapModule(AppModule);
<!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/angular/node_modules/@mescius/spread-sheets/styles/gc.spread.sheets.excel2013white.css">
<!-- Polyfills -->
<script src="$DEMOROOT$/en/angular/node_modules/core-js/client/shim.min.js"></script>
<script src="$DEMOROOT$/en/angular/node_modules/zone.js/fesm2015/zone.min.js"></script>
<!-- SystemJS -->
<script src="$DEMOROOT$/en/angular/node_modules/systemjs/dist/system.js"></script>
<script src="systemjs.config.js"></script>
<script>
// workaround to load 'rxjs/operators' from the rxjs bundle
System.import('rxjs').then(function (m) {
System.import('@angular/compiler');
System.set(SystemJS.resolveSync('rxjs/operators'), System.newModule(m.operators));
System.import('$DEMOROOT$/en/lib/angular/license.ts');
System.import('./src/app.component');
});
</script>
</head>
<body>
<app-component></app-component>
</body>
</html>
<div class="sample-tutorial">
<gc-spread-sheets [hostStyle]="hostStyle" (workbookInitialized)="initSpread($event)" [newTabVisible] = false>
<gc-worksheet>
</gc-worksheet>
<gc-worksheet>
</gc-worksheet>
</gc-spread-sheets>
</div>
.sample-tutorial {
position: relative;
height: 100%;
overflow: hidden;
}
body {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
}
.sample-spreadsheets {
height: 100%;
}
(function (global) {
System.config({
transpiler: 'ts',
typescriptOptions: {
tsconfig: true
},
meta: {
'typescript': {
"exports": "ts"
},
'*.css': { loader: 'css' }
},
paths: {
// paths serve as alias
'npm:': 'node_modules/'
},
// map tells the System loader where to look for things
map: {
'core-js': 'npm:core-js/client/shim.min.js',
'zone': 'npm:zone.js/fesm2015/zone.min.js',
'rxjs': 'npm:rxjs/dist/bundles/rxjs.umd.min.js',
'@angular/core': 'npm:@angular/core/fesm2022',
'@angular/common': 'npm:@angular/common/fesm2022/common.mjs',
'@angular/compiler': 'npm:@angular/compiler/fesm2022/compiler.mjs',
'@angular/platform-browser': 'npm:@angular/platform-browser/fesm2022/platform-browser.mjs',
'@angular/platform-browser-dynamic': 'npm:@angular/platform-browser-dynamic/fesm2022/platform-browser-dynamic.mjs',
'@angular/common/http': 'npm:@angular/common/fesm2022/http.mjs',
'@angular/router': 'npm:@angular/router/fesm2022/router.mjs',
'@angular/forms': 'npm:@angular/forms/fesm2022/forms.mjs',
'jszip': 'npm:jszip/dist/jszip.min.js',
'typescript': 'npm:typescript/lib/typescript.js',
'ts': './plugin.js',
'tslib':'npm:tslib/tslib.js',
'css': 'npm:systemjs-plugin-css/css.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-angular': 'npm:@mescius/spread-sheets-angular/fesm2020/mescius-spread-sheets-angular.mjs',
'@grapecity/jsob-test-dependency-package/react-components': 'npm:@grapecity/jsob-test-dependency-package/react-components/index.js'
},
// packages tells the System loader how to load when no filename and/or no extension
packages: {
src: {
defaultExtension: 'ts'
},
rxjs: {
defaultExtension: 'js'
},
"node_modules": {
defaultExtension: 'js'
},
"node_modules/@angular": {
defaultExtension: 'mjs'
},
"@mescius/spread-sheets-angular": {
defaultExtension: 'mjs'
},
'@angular/core': {
defaultExtension: 'mjs',
main: 'core.mjs'
}
}
});
})(this);