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 * as React from 'react';
import * as ReactDOM from 'react-dom';
import './styles.css';
import { AppFunc } from './app-func';
// import { App } from './app-class';
// 1. Functional Component sample
ReactDOM.render(<AppFunc />, document.getElementById('app'));
// 2. Class Component sample
// ReactDOM.render(<App />, document.getElementById('app'));
import * as React from 'react';
import GC from '@mescius/spread-sheets';
import { SpreadSheets, Worksheet } from '@mescius/spread-sheets-react';
export function AppFunc() {
let spread = null;
const 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(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();
}
const 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(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();
}
const initSpread = (currSpread) => {
spread = currSpread;
initHorizontalSparkline(spread.sheets[0], "Horizontal");
initVerticalSparkline(spread.sheets[1], "Vertical");
}
return (
<div class="sample-tutorial">
<div class="sample-spreadsheets">
<SpreadSheets workbookInitialized={spread => initSpread(spread)} newTabVisible={false}>
<Worksheet></Worksheet>
<Worksheet> </Worksheet>
</SpreadSheets>
</div>
</div>
);
}
import * as React from 'react';
import GC from '@mescius/spread-sheets';
import { SpreadSheets, Worksheet } from '@mescius/spread-sheets-react';
const Component = React.Component;
export class App extends Component {
constructor(props) {
super(props);
this.spread = null;
}
render() {
return (
<div class="sample-tutorial">
<div class="sample-spreadsheets">
<SpreadSheets workbookInitialized={spread => this.initSpread(spread)} newTabVisible={false}>
<Worksheet></Worksheet>
<Worksheet> </Worksheet>
</SpreadSheets>
</div>
</div>
)
}
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(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();
}
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(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();
}
initSpread(spread) {
this.spread = spread;
this.initHorizontalSparkline(spread.sheets[0], "Horizontal");
this.initVerticalSparkline(spread.sheets[1], "Vertical");
}
}
<!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/react/node_modules/@mescius/spread-sheets/styles/gc.spread.sheets.excel2013white.css">
<!-- SystemJS -->
<script src="$DEMOROOT$/en/react/node_modules/systemjs/dist/system.src.js"></script>
<script src="systemjs.config.js"></script>
<script>
System.import('$DEMOROOT$/en/lib/react/license.js').then(function () {
System.import('./src/app');
});
</script>
</head>
<body>
<div id="app" style="height: 100%;"></div>
</body>
</html>
.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: 'plugin-babel',
babelOptions: {
es2015: true,
react: true
},
meta: {
'*.css': { loader: 'css' }
},
paths: {
// paths serve as alias
'npm:': 'node_modules/'
},
// map tells the System loader where to look for things
map: {
'@mescius/spread-sheets': 'npm:@mescius/spread-sheets/index.js',
'@mescius/spread-sheets-react': 'npm:@mescius/spread-sheets-react/index.js',
'@grapecity/jsob-test-dependency-package/react-components': 'npm:@grapecity/jsob-test-dependency-package/react-components/index.js',
'react': 'npm:react/umd/react.production.min.js',
'react-dom': 'npm:react-dom/umd/react-dom.production.min.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'
},
// packages tells the System loader how to load when no filename and/or no extension
packages: {
src: {
defaultExtension: 'jsx'
},
"node_modules": {
defaultExtension: 'js'
},
}
});
})(this);