You can create a Histogram sparkline using the HistogramSparkline function in a formula: =HISTOGRAMSPARKLINE(dataRange,continuous?,paintLabel?,scale?,barWidth?,barColor?,labelColor?,edgeColor?).
The function has the following parameters:
dataRange: It's a range or calc array,such as "A1:C6" or "{1,2,2,3,3}". If a cell value isn't a valid number, it will be ignore.
continuous: (optional) If it's true, the histogram is continuous. If it's false, the histogram is discrete.
paintLabel: (optional) Boolean that represents whether to show the data label.
scale: (optional) Number that represents the data binning width when histogram is continuous. (value > 0)
barWidth: (optional) Number that represents the percent of bar width according to the average bar width. (value > 0 && value <= 1)
barColor: (optional) String that represents the bar color.
labelFontStyle: (optional) String that represents the data label font style. It supports custom font style, font weight, font family, font size.
labelColor: (optional) String that represents the data label font color. It support CSS color.
edgeColor: (optional) String that represents the color of bar edge.
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 { SpreadSheets, Worksheet } from '@mescius/spread-sheets-react';
export function AppFunc() {
const initSpread = (spread) => {
spread.fromJSON(data);
var sheet = spread.getSheet(0);
spread.suspendPaint();
for (var i = 0; i < 7; i++) {
var column = String.fromCharCode(65 + i);
sheet.setFormula(3, i, 'HISTOGRAMSPARKLINE(' + column + '4:' + column +
'50,TRUE,TRUE,10,1,"#DDDDDD","normal normal 8pt Calibri", "#000000", "#C0C0C0")');
i++;
}
spread.resumePaint();
}
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 { 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>
)
}
initSpread(spread){
spread.fromJSON(data);
var sheet = spread.getSheet(0);
spread.suspendPaint();
for(var i=0; i<7;i++){
var column = String.fromCharCode(65 + i);
sheet.setFormula(3, i, 'HISTOGRAMSPARKLINE('+column+'4:'+column+
'50,TRUE,TRUE,10,1,"#DDDDDD","normal normal 8pt Calibri", "#000000", "#C0C0C0")');
i++;
}
spread.resumePaint();
}
}
<!DOCTYPE html>
<html lang="en">
<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$/spread/source/data/histogramSparkline.js"></script>
<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);