You can create a Scatter sparkline using the ScatterSparkline function in a formula: =SCATTERSPARKLINE(points1, points2?, minX?, maxX?, minY?, maxY?, hLine?, vLine?, xMinZone?, xMaxZone?, yMinZone?, yMaxZone?, tags?, drawSymbol?, drawLines?, color1?, color2?, dash?).
The function has the following parameters:
points1: The first series of x,y data. It is a range, such as "H1:I3". If the row count is greater than or equal to the column count, get data from the first two columns; the first column contains x values, and the second column contains y values. Otherwise, get data from the first two rows; the first row contains x values, and the second row contains y values.
points2: (optional) The second series of x,y data. It is a range, such as "H4:I6". If the row count is greater than or equal to the column count, get data from the first two columns; the first column contains x values, and the second column contains y values. Otherwise, get data from the first two rows; the first row contains x values, and the second row contains y values.
minX: (optional) x minimum limit of both series; each series has its own value if it is omitted.
maxX: (optional) x maximum limit of both series; each series has its own value if it is omitted.
minY: (optional) y minimum limit of both series; each series has its own value if it is omitted.
maxY: (optional) y maximum limit of both series; each series has its own value if it is omitted.
hLine: (optional) The position of the horizontal axis; there is no line if it is omitted.
vLine: (optional) The position of the vertical axis; there is no line if it is omitted.
xMinZone: (optional) x minimum value of the gray zone; there is no gray zone if any of these four zone params are omitted.
xMaxZone: (optional) x maximum value of the gray zone; there is no gray zone if any of these four zone params are omitted.
yMinZone: (optional) y minimum value of the gray zone; there is no gray zone if any of these four zone params are omitted.
yMaxZone: (optional) y maximum value of the gray zone; there is no gray zone if any of these four zone params are omitted.
tags: (optional) If it is true, mark the point where the y value is the maximum of the first series as "#0000FF", and mark the point where the y value is the minimum of the first series as "#CB0000". The default value is false.
drawSymbol: (optional) If it is true, draw each point as a symbol. The symbol of the first series is a circle, and the symbol of the second series is a square. The default value is true.
drawLines: (optional) If it is true, connect each point with a line by sequence in each series. The default value is false.
color1: (optional) Color string of the first series of points; the default value is "#969696".
color2: (optional) Color string of the second series of points; the default value is "#CB0000".
dash: (optional) If it is true, the line is a dashed line; otherwise, the line is a full line. The default value is false.
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';
let spread = null;
export function AppFunc() {
const [colors, setColors] = React.useState({
color1: "#BBBBBB",
color2: "#82BC00"
});
React.useEffect(() => {
applyChanges();
}, [colors]);
const color1Change = (e) => {
setColors({
...colors,
color1: e.target.value
});
}
const color2Change = (e) => {
setColors({
...colors,
color2: e.target.value
});
}
const initSpread = (currSpread) => {
spread = currSpread;
let spreadNS = GC.Spread.Sheets;
let sheet = spread.sheets[0];
sheet.suspendPaint();
sheet.addSpan(0, 0, 1, 5);
sheet.getCell(0, 0).value("Rainfall effect on Particulate Levels and Temperature").font("15px Arial")
.backColor("#BBBBBB")
.vAlign(spreadNS.VerticalAlign.center);
sheet.setArray(1, 0, [
["Daily Rainfall", "Particulate Level", "Daily Rainfall1", "Temperature", "Diagram"],
[2.0, 100, 2.0, 15],
[2.5, 130, 2.5, 12],
[3.0, 120, 3.0, 11],
[3.5, 140, 3.5, 9],
[4.0, 120, 4.0, 10],
[4.5, 110, 4.5, 10],
[5.0, 110, 5.0, 9],
[5.5, 105, 5.5, 9],
[6.0, 100, 6.0, 8]
]);
sheet.addSpan(2, 4, 9, 1);
sheet.setFormula(2, 4, '=SCATTERSPARKLINE(A3:B11,C3:D11,,,,,AVERAGE(B3:B11),AVERAGE(A3:A11),,,,,'
+ 'TRUE,TRUE,TRUE,"#000000","#82BC00",TRUE)');
for (var i = 0; i < 11; i++) {
sheet.setRowHeight(i, 25);
}
sheet.getRange(1, 0, 1, 5)
.font("bold 13px Arial")
.setBorder(new spreadNS.LineBorder("black", spreadNS.LineStyle.thin), { bottom: true });
sheet.getRange(2, 0, 9, 4).hAlign(spreadNS.HorizontalAlign.left);
sheet.setColumnWidth(0, 120);
sheet.setColumnWidth(1, 120);
sheet.setColumnWidth(3, 120);
sheet.setColumnWidth(4, 200);
//hide 2nd rainfall column data
sheet.setColumnVisible(2, false);
sheet.resumePaint();
}
const applyChanges = () => {
let sheet = spread.getActiveSheet();
console.log("applyChanges: ", colors.color1);
sheet.setFormula(2, 4, '=SCATTERSPARKLINE(A3:B11,C3:D11,,,,,AVERAGE(B3:B11),AVERAGE(A3:A11),,,,,'
+ 'TRUE,TRUE,TRUE,"' +
colors.color1 + '","' +
colors.color2 + '",TRUE)');
}
return (
<div class="sample-tutorial">
<div class="sample-spreadsheets">
<SpreadSheets workbookInitialized={spread => initSpread(spread)}>
<Worksheet>
</Worksheet>
</SpreadSheets>
</div>
<Panel panelInfo={colors}
color1Change={(e) => { color1Change(e) }}
color2Change={(e) => { color2Change(e) }}
/>
</div>
);
}
const Panel = (props) => {
const { panelInfo, color1Change, color2Change } = props;
return (
<div class="options-container">
<div class="option-row">
<label for="color1">Rainfall - Particulate Level Graph Color</label>
</div>
<div class="option-row">
<select value={panelInfo.color1 + ""} select={panelInfo.color1} onChange={(e) => { color1Change(e) }}>
<option value="#FFFFFF">White</option>
<option value="#000000">Black</option>
<option value="#F7A711">Orange</option>
<option value="#DDDDDD">LightGrey</option>
<option value="#BBBBBB">Grey</option>
<option value="#999999">DarkGrey</option>
<option value="#82BC00">Green</option>
</select>
</div>
<div class="option-row">
<label for="color2">Rainfall - Temperature Graph Color</label>
</div>
<div class="option-row">
<select value={panelInfo.color2 + ""} select={panelInfo.color2} onChange={(e) => { color2Change(e) }}>
<option value="#FFFFFF">White</option>
<option value="#000000">Black</option>
<option value="#F7A711">Orange</option>
<option value="#DDDDDD">LightGrey</option>
<option value="#BBBBBB">Grey</option>
<option value="#999999">DarkGrey</option>
<option value="#82BC00">Green</option>
</select>
</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;
this.state = {
color1: "#BBBBBB",
color2: "#82BC00"
};
}
render() {
return (
<div class="sample-tutorial">
<div class="sample-spreadsheets">
<SpreadSheets workbookInitialized={spread => this.initSpread(spread)}>
<Worksheet>
</Worksheet>
</SpreadSheets>
</div>
<Panel panelInfo={this.state}
color1Change={(e) => { this.color1Change(e) }}
color2Change={(e) => { this.color2Change(e) }}
/>
</div>
)
}
color1Change(e) {
this.setState({
color1: e.target.value
}, () => {
this.applyChanges();
})
}
color2Change(e) {
this.setState({
color2: e.target.value
}, () => {
this.applyChanges();
})
}
initSpread(spread) {
this.spread = spread;
let spreadNS = GC.Spread.Sheets;
let sheet = spread.sheets[0];
sheet.suspendPaint();
sheet.addSpan(0, 0, 1, 5);
sheet.getCell(0, 0).value("Rainfall effect on Particulate Levels and Temperature").font("15px Arial")
.backColor("#BBBBBB")
.vAlign(spreadNS.VerticalAlign.center);
sheet.setArray(1, 0, [
["Daily Rainfall", "Particulate Level", "Daily Rainfall1", "Temperature", "Diagram"],
[2.0, 100, 2.0, 15],
[2.5, 130, 2.5, 12],
[3.0, 120, 3.0, 11],
[3.5, 140, 3.5, 9],
[4.0, 120, 4.0, 10],
[4.5, 110, 4.5, 10],
[5.0, 110, 5.0, 9],
[5.5, 105, 5.5, 9],
[6.0, 100, 6.0, 8]
]);
sheet.addSpan(2, 4, 9, 1);
sheet.setFormula(2, 4, '=SCATTERSPARKLINE(A3:B11,C3:D11,,,,,AVERAGE(B3:B11),AVERAGE(A3:A11),,,,,'
+ 'TRUE,TRUE,TRUE,"#000000","#82BC00",TRUE)');
for (var i = 0; i < 11; i++) {
sheet.setRowHeight(i, 25);
}
sheet.getRange(1, 0, 1, 5)
.font("bold 13px Arial")
.setBorder(new spreadNS.LineBorder("black", spreadNS.LineStyle.thin), { bottom: true });
sheet.getRange(2, 0, 9, 4).hAlign(spreadNS.HorizontalAlign.left);
sheet.setColumnWidth(0, 120);
sheet.setColumnWidth(1, 120);
sheet.setColumnWidth(3, 120);
sheet.setColumnWidth(4, 200);
//hide 2nd rainfall column data
sheet.setColumnVisible(2, false);
sheet.resumePaint();
}
applyChanges() {
let sheet = this.spread.getActiveSheet();
console.log("applyChanges: ", this.state.color1);
sheet.setFormula(2, 4, '=SCATTERSPARKLINE(A3:B11,C3:D11,,,,,AVERAGE(B3:B11),AVERAGE(A3:A11),,,,,'
+ 'TRUE,TRUE,TRUE,"' +
this.state.color1 + '","' +
this.state.color2 + '",TRUE)');
}
}
const Panel = (props) => {
const { panelInfo, color1Change, color2Change } = props;
return (
<div class="options-container">
<div class="option-row">
<label for="color1">Rainfall - Particulate Level Graph Color</label>
</div>
<div class="option-row">
<select value={panelInfo.color1 + ""} select={panelInfo.color1} onChange={(e) => { color1Change(e) }}>
<option value="#FFFFFF">White</option>
<option value="#000000">Black</option>
<option value="#F7A711">Orange</option>
<option value="#DDDDDD">LightGrey</option>
<option value="#BBBBBB">Grey</option>
<option value="#999999">DarkGrey</option>
<option value="#82BC00">Green</option>
</select>
</div>
<div class="option-row">
<label for="color2">Rainfall - Temperature Graph Color</label>
</div>
<div class="option-row">
<select value={panelInfo.color2 + ""} select={panelInfo.color2} onChange={(e) => { color2Change(e) }}>
<option value="#FFFFFF">White</option>
<option value="#000000">Black</option>
<option value="#F7A711">Orange</option>
<option value="#DDDDDD">LightGrey</option>
<option value="#BBBBBB">Grey</option>
<option value="#999999">DarkGrey</option>
<option value="#82BC00">Green</option>
</select>
</div>
</div>
);
}
<!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 {
position: relative;
height: 100%;
overflow: auto;
}
.sample::after {
display: block;
content: "";
clear: both;
}
.sample-tutorial {
position: relative;
height: 100%;
overflow: hidden;
}
.sample-spreadsheets {
width: calc(100% - 280px);
height: 100%;
overflow: hidden;
float: left;
}
.options-container {
float: right;
width: 280px;
padding: 12px;
height: 100%;
box-sizing: border-box;
background: #fbfbfb;
overflow: auto;
}
.option-row {
font-size: 14px;
padding: 5px;
margin-top: 10px;
}
.option-group {
margin-bottom: 6px;
}
label {
display: inline-block;
min-width: 90px;
margin-bottom: 6px;
}
select {
padding: 4px 6px;
box-sizing: border-box;
}
body {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
}
(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);