パレートスパークライン

パレートスパークラインを使用すると、一式の値の中から最も重要な項目を強調表示できます。

数式にParetoSparkline関数を使用することで、パレートスパークラインを作成できます。構文は次のとおりです。=PARETOSPARKLINE(points, pointIndex, colorRange?, target?, target2?, highlightPosition?, label?, vertical?, targetColor?, target2Color?, labelColor?, barSize?) 有効なパラメータは次のとおりです。 points: 表示するすべての値を保持するセル範囲を表す参照。「B2:B7」など。 pointIndex: データ点に対応するインデックスを表す数値または参照。1以上の値となります。「1」、「D2」など。 colorRange: (オプション)セグメントボックスの色を保持するセル範囲を表す参照。「D2:D7」など。デフォルト値はnullです。 target: (オプション)目標線の位置を表す数値または参照。「0.5」など。デフォルト値はnullです。 target2: (オプション)第2目標線の位置を表す数値または参照。「0.5」など。デフォルト値はnullです。 highlightPosition: (オプション)赤色で表示するセグメントの順位を表す数値または参照。「3」など。デフォルト値はnullです。 label: (オプション)セグメントのラベルを累積パーセンテージとして表示するのか(label = 1)、単一のパーセンテージとして表示するのか(label = 2)、または表示しないか(label = 0)を表す数値。デフォルト値は「なし(0)」です。 vertical: (オプション)ボックスの向きを垂直方向にするかどうかを表すブール値。デフォルト値はfalseです。 targetColor: (オプション) 目標線の色を表す文字列。 target2Color: (オプション) 第2目標線の色を表す文字列。 labelColor: (オプション) ラベルの前景色を表す文字列。 barSize: (オプション) セルの幅または高さに応じてバーの幅または高さをパーセンテージで表す数値。0から1までの範囲内である必要があります。
import * as React from 'react'; import * as ReactDOM from 'react-dom'; import GC from '@mescius/spread-sheets'; import '@mescius/spread-sheets-resources-ja'; GC.Spread.Common.CultureManager.culture("ja-jp"); 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 [paretoOption, setParetoOption] = React.useState({ type: 2, highlight: 0, target1: 0.5, target2: 0.8, color1: "#BBBBBB", color2: "#F7A711" }); React.useEffect(() => { applyChanges(); }, [paretoOption]); const highlightChange = (e) => { let value = parseInt(e.target.value); setParetoOption({ ...paretoOption, highlight: value }); } const typeChanges = (e) => { let value = parseInt(e.target.value); setParetoOption({ ...paretoOption, type: value }); } const target1Change = (e) => { let value = e.target.value; setParetoOption({ ...paretoOption, target1: value }); } const target2Change = (e) => { let value = e.target.value; setParetoOption({ ...paretoOption, target2: value }); } const color1Change = (e) => { let value = e.target.value; setParetoOption({ ...paretoOption, color1: value }); } const color2Change = (e) => { let value = e.target.value; setParetoOption({ ...paretoOption, color2: value }); } const initHorizontalSparkline = (sheet, name) => { sheet.suspendPaint(); sheet.name(name); let spreadNS = GC.Spread.Sheets; sheet.setArray(1, 0, [ ["Reason", "Cases", "Color", "Bar Size", "Diagram"], ["Traffic", 20, "#CCCCCC", 0.1], ["Child care", 15, "#82BC00", 0.3], ["Public transportation", 13, "#F7A711", 0.5], ["Weather", 6, "#00C2D6", 0.7], ["Overslept", 4, "#FFE7BA", 0.8], ["Emergency", 1, "#000000", 1] ]); sheet.setValue(10, 0, '*結果:上記のスパークラインより、従業員の遅刻の80%は"traffic"、"child care"、"public transportation"が原因であるという結論になります。'); for (var index = 2; index < 8; index++) { sheet.setFormula(index, 4, '=PARETOSPARKLINE($B$3:$B$8,ROW()-2,$C$3:$C$8,' + paretoOption.target1 + ',' + paretoOption.target2 + ',0,2,false,"' + paretoOption.color1 + '","' + paretoOption.color2 + '",$C$3:$C$8,$D$3:$D$8)'); } //styling for (var i = 1; i < 4; i++) { sheet.setColumnWidth(i, 80); } sheet.setColumnWidth(4, 340); sheet.setColumnWidth(0, 140); sheet.setRowHeight(0, 35); sheet.addSpan(0, 0, 1, 5); sheet.getCell(0, 0).value("Late Arrivals by Reported Cause") .font("17px Arial") .vAlign(spreadNS.VerticalAlign.center) .backColor("gray") .foreColor("white"); sheet.getRange(2, 0, 6, 4).hAlign(spreadNS.HorizontalAlign.left); sheet.getRange(1, 0, 1, 5) .font("bold 13px Arial") .setBorder(new spreadNS.LineBorder("black", spreadNS.LineStyle.thin), { bottom: true }); sheet.resumePaint(); } const initVerticalSparkline = (sheet, name) => { let spreadNS = GC.Spread.Sheets; sheet.suspendPaint(); sheet.name(name); sheet.setArray(1, 0, [ ["Reason", "Traffic", "Child care", "Public transportation", "Weather", "Overslept", "Emergency"], ["Cases", 20, 15, 13, 5, 4, 1], ["Color", "#CCCCCC", "#82BC00", "#F7A711", "#00C2D6", "#FFE7BA", "#000000"], ["Bar Size", 0.1, 0.3, 0.5, 0.7, 0.8, 1], ["Diagram"] ]); sheet.setValue(8, 0, '*結果:上記のスパークラインより、従業員の遅刻の80%は"traffic"、"child care"、"public transportation"が原因であるという結論になります。'); for (var index = 1; index < 7; index++) { sheet.setFormula(5, index, '=PARETOSPARKLINE($B$3:$G$3,COLUMN()-1,$B$4:$G$4,' + paretoOption.target1 + ',' + paretoOption.target2 + ',0,2,true,"' + paretoOption.color1 + '","' + paretoOption.color2 + '",$B$4:$G$4,$B$5:$G$5)'); } //styling for (var i = 0; i < 7; i++) { sheet.setColumnWidth(i, 120); } sheet.setColumnWidth(3, 150); sheet.setRowHeight(5, 160); sheet.setRowHeight(0, 35); sheet.addSpan(0, 0, 1, 7); sheet.getCell(0, 0).value("Late Arrivals by Reported Cause") .font("17px Arial") .vAlign(spreadNS.VerticalAlign.center) .backColor("gray") .foreColor("white"); sheet.getRange(1, 0, 5, 1) .font("bold 13px Arial") .setBorder(new spreadNS.LineBorder("black", spreadNS.LineStyle.thin), { right: true }); sheet.getRange(1, 0, 4, 7).hAlign(spreadNS.HorizontalAlign.left); sheet.resumePaint(); } const applyChanges = () => { let sheet = spread.getActiveSheet(); let labelType = parseInt(paretoOption.type, 10), highlightPosition = parseInt(paretoOption.highlight, 10); if (spread.getActiveSheetIndex() == 0) { var formula = '=PARETOSPARKLINE($B$3:$B$8,ROW()-2,$C$3:$C$8,' + paretoOption.target1 + ',' + paretoOption.target2 + ',' + highlightPosition + ',' + labelType + ',false,"' + paretoOption.color1 + '","' + paretoOption.color2 + '",$C$3:$C$8,$D$3:$D$8)'; for (var i = 2; i <= 7; i++) { sheet.setFormula(i, 4, formula); } } else { var formulaVertical = '=PARETOSPARKLINE($B$3:$G$3,COLUMN()-1,$B$4:$G$4,' + paretoOption.target1 + ',' + paretoOption.target2 + ',' + highlightPosition + ',' + labelType + ',true,"' + paretoOption.color1 + '","' + paretoOption.color2 + '",$B$4:$G$4,$B$5:$G$5)'; for (var index = 1; index < 7; index++) { sheet.setFormula(5, index, formulaVertical); } } } 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> <Panel panelInfo={paretoOption} typeChanges={(e) => { typeChanges(e) }} highlightChange={(e) => { highlightChange(e) }} target1Change={(e) => { target1Change(e) }} target2Change={(e) => { target2Change(e) }} color1Change={(e) => { color1Change(e) }} color2Change={(e) => { color2Change(e) }} /> </div> ); } const Panel = (props) => { const { panelInfo, highlightChange, typeChanges, target1Change, target2Change, color1Change, color2Change } = props; return ( <div class="options-container"> <div class="option-row"> <label><b>スパークラインの設定</b></label> </div> <hr /> <div class="option-row"> <label for="labelType">ラベルの種類:</label> <select id="labelType" value={panelInfo.type + ""} onChange={(e) => { typeChanges(e) }}> <option value="0">None</option> <option value="1">Cumulated percentage</option> <option value="2" selected>Single percentage</option> </select> </div> <div class="option-row"> <label for="highlightPosition" >強調表示する項目:</label> <select id="highlightPosition" value={panelInfo.highlight + ""} onChange={(e) => { highlightChange(e) }}> <option value="0" selected>None</option> <option value="1">1st</option> <option value="2">2nd</option> <option value="3">3rd</option> <option value="4">4th</option> <option value="5">5th</option> <option value="6">6th</option> </select> </div> <div class="option-row"> <label for="target1">目標線:</label> <input type="text" value={panelInfo.target1 + ""} onChange={(e) => { target1Change(e) }} /> </div> <div class="option-row"> <label for="target2">第2目標線:</label> <input type="text" value={panelInfo.target2 + ""} onChange={(e) => { target2Change(e) }} /> </div> <div class="option-row"> <label for="color1">目標線の色:</label> <select value={panelInfo.color1 + ""} onChange={(e) => { color1Change(e) }}> <option value="#BBBBBB" selected>Grey</option> <option value="#82BC00">Green</option> <option value="#000000">Black</option> <option value="#F7A711">Orange</option> </select> </div> <div class="option-row"> <label for="color2">第2目標線の色:</label> <select value={panelInfo.color2 + ""} onChange={(e) => { color2Change(e) }}> <option value="#BBBBBB">Grey</option> <option value="#82BC00">Green</option> <option value="#000000">Black</option> <option value="#F7A711" selected>Orange</option> </select> </div> </div> ); }
import * as React from 'react'; import GC from '@mescius/spread-sheets'; import { SpreadSheets, Worksheet } from '@mescius/spread-sheets-react'; const PureComponent = React.PureComponent; export class App extends PureComponent { constructor(props) { super(props); this.spread = null; this.state = { type: 2, highlight: 0, target1: 0.5, target2: 0.8, color1: "#BBBBBB", color2: "#F7A711" }; } render() { return ( <div class="sample-tutorial"> <div class="sample-spreadsheets"> <SpreadSheets workbookInitialized={spread => this.initSpread(spread)} newTabVisible={false}> <Worksheet> </Worksheet> <Worksheet> </Worksheet> </SpreadSheets> </div> <Panel panelInfo={this.state} typeChanges={(e) => { this.typeChanges(e) }} highlightChange={(e) => { this.highlightChange(e) }} target1Change={(e) => { this.target1Change(e) }} target2Change={(e) => { this.target2Change(e) }} color1Change={(e) => { this.color1Change(e) }} color2Change={(e) => { this.color2Change(e) }} /> </div> ) } highlightChange(e) { let value = parseInt(e.target.value); this.setState(() => ({ highlight: value }), () => { this.applyChanges(); }) } typeChanges(e) { let value = parseInt(e.target.value); this.setState(() => ({ type: value }), () => { this.applyChanges(); }) } target1Change(e) { let value = e.target.value; this.setState(() => ({ target1: value }), () => { this.applyChanges(); }) } target2Change(e) { let value = e.target.value; this.setState(() => ({ target2: value }), () => { this.applyChanges(); }) } color1Change(e) { let value = e.target.value; this.setState(() => ({ color1: value }), () => { this.applyChanges(); }) } color2Change(e) { let value = e.target.value; this.setState(() => ({ color2: value }), () => { this.applyChanges(); }) } initHorizontalSparkline(sheet, name) { sheet.suspendPaint(); sheet.name(name); let spreadNS = GC.Spread.Sheets; sheet.setArray(1, 0, [ ["Reason", "Cases", "Color", "Bar Size", "Diagram"], ["Traffic", 20, "#CCCCCC", 0.1], ["Child care", 15, "#82BC00", 0.3], ["Public transportation", 13, "#F7A711", 0.5], ["Weather", 6, "#00C2D6", 0.7], ["Overslept", 4, "#FFE7BA", 0.8], ["Emergency", 1, "#000000", 1] ]); sheet.setValue(10, 0, '*結果:上記のスパークラインより、従業員の遅刻の80%は"traffic"、"child care"、"public transportation"が原因であるという結論になります。'); for (var index = 2; index < 8; index++) { sheet.setFormula(index, 4, '=PARETOSPARKLINE($B$3:$B$8,ROW()-2,$C$3:$C$8,' + this.state.target1 + ',' + this.state.target2 + ',0,2,false,"' + this.state.color1 + '","' + this.state.color2 + '",$C$3:$C$8,$D$3:$D$8)'); } //styling for (var i = 1; i < 4; i++) { sheet.setColumnWidth(i, 80); } sheet.setColumnWidth(4, 340); sheet.setColumnWidth(0, 140); sheet.setRowHeight(0, 35); sheet.addSpan(0, 0, 1, 5); sheet.getCell(0, 0).value("Late Arrivals by Reported Cause") .font("17px Arial") .vAlign(spreadNS.VerticalAlign.center) .backColor("gray") .foreColor("white"); sheet.getRange(2, 0, 6, 4).hAlign(spreadNS.HorizontalAlign.left); sheet.getRange(1, 0, 1, 5) .font("bold 13px Arial") .setBorder(new spreadNS.LineBorder("black", spreadNS.LineStyle.thin), { bottom: true }); sheet.resumePaint(); } initVerticalSparkline(sheet, name) { let spreadNS = GC.Spread.Sheets; sheet.suspendPaint(); sheet.name(name); sheet.setArray(1, 0, [ ["Reason", "Traffic", "Child care", "Public transportation", "Weather", "Overslept", "Emergency"], ["Cases", 20, 15, 13, 5, 4, 1], ["Color", "#CCCCCC", "#82BC00", "#F7A711", "#00C2D6", "#FFE7BA", "#000000"], ["Bar Size", 0.1, 0.3, 0.5, 0.7, 0.8, 1], ["Diagram"] ]); sheet.setValue(8, 0, '*結果:上記のスパークラインより、従業員の遅刻の80%は"traffic"、"child care"、"public transportation"が原因であるという結論になります。'); for (var index = 1; index < 7; index++) { sheet.setFormula(5, index, '=PARETOSPARKLINE($B$3:$G$3,COLUMN()-1,$B$4:$G$4,' + this.state.target1 + ',' + this.state.target2 + ',0,2,true,"' + this.state.color1 + '","' + this.state.color2 + '",$B$4:$G$4,$B$5:$G$5)'); } //styling for (var i = 0; i < 7; i++) { sheet.setColumnWidth(i, 120); } sheet.setColumnWidth(3, 150); sheet.setRowHeight(5, 160); sheet.setRowHeight(0, 35); sheet.addSpan(0, 0, 1, 7); sheet.getCell(0, 0).value("Late Arrivals by Reported Cause") .font("17px Arial") .vAlign(spreadNS.VerticalAlign.center) .backColor("gray") .foreColor("white"); sheet.getRange(1, 0, 5, 1) .font("bold 13px Arial") .setBorder(new spreadNS.LineBorder("black", spreadNS.LineStyle.thin), { right: true }); sheet.getRange(1, 0, 4, 7).hAlign(spreadNS.HorizontalAlign.left); sheet.resumePaint(); } applyChanges() { let sheet = this.spread.getActiveSheet(); let labelType = parseInt(this.state.type, 10), highlightPosition = parseInt(this.state.highlight, 10); if (this.spread.getActiveSheetIndex() == 0) { var formula = '=PARETOSPARKLINE($B$3:$B$8,ROW()-2,$C$3:$C$8,' + this.state.target1 + ',' + this.state.target2 + ',' + highlightPosition + ',' + labelType + ',false,"' + this.state.color1 + '","' + this.state.color2 + '",$C$3:$C$8,$D$3:$D$8)'; for (var i = 2; i <= 7; i++) { sheet.setFormula(i, 4, formula); } } else { var formulaVertical = '=PARETOSPARKLINE($B$3:$G$3,COLUMN()-1,$B$4:$G$4,' + this.state.target1 + ',' + this.state.target2 + ',' + highlightPosition + ',' + labelType + ',true,"' + this.state.color1 + '","' + this.state.color2 + '",$B$4:$G$4,$B$5:$G$5)'; for (var index = 1; index < 7; index++) { sheet.setFormula(5, index, formulaVertical); } } } initSpread(spread) { this.spread = spread; this.initHorizontalSparkline(spread.sheets[0], "Horizontal"); this.initVerticalSparkline(spread.sheets[1], "Vertical"); } } const Panel = (props) => { const { panelInfo, highlightChange, typeChanges, target1Change, target2Change, color1Change, color2Change } = props; return ( <div class="options-container"> <div class="option-row"> <label><b>スパークラインの設定:</b></label> </div> <hr /> <div class="option-row"> <label for="labelType">ラベルの種類:</label> <select id="labelType" value={panelInfo.type + ""} onChange={(e) => { typeChanges(e) }}> <option value="0">None</option> <option value="1">Cumulated percentage</option> <option value="2" selected>Single percentage</option> </select> </div> <div class="option-row"> <label for="highlightPosition" >強調表示する項目:</label> <select id="highlightPosition" value={panelInfo.highlight + ""} onChange={(e) => { highlightChange(e) }}> <option value="0" selected>None</option> <option value="1">1st</option> <option value="2">2nd</option> <option value="3">3rd</option> <option value="4">4th</option> <option value="5">5th</option> <option value="6">6th</option> </select> </div> <div class="option-row"> <label for="target1">目標線:</label> <input type="text" value={panelInfo.target1 + ""} onChange={(e) => { target1Change(e) }} /> </div> <div class="option-row"> <label for="target2">第2目標線:</label> <input type="text" value={panelInfo.target2 + ""} onChange={(e) => { target2Change(e) }} /> </div> <div class="option-row"> <label for="color1">目標線の色:</label> <select value={panelInfo.color1 + ""} onChange={(e) => { color1Change(e) }}> <option value="#BBBBBB" selected>Grey</option> <option value="#82BC00">Green</option> <option value="#000000">Black</option> <option value="#F7A711">Orange</option> </select> </div> <div class="option-row"> <label for="color2">第2目標線の色:</label> <select value={panelInfo.color2 + ""} onChange={(e) => { color2Change(e) }}> <option value="#BBBBBB">Grey</option> <option value="#82BC00">Green</option> <option value="#000000">Black</option> <option value="#F7A711" selected>Orange</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$/ja/react/node_modules/@mescius/spread-sheets/styles/gc.spread.sheets.excel2013white.css"> <!-- SystemJS --> <script src="$DEMOROOT$/ja/react/node_modules/systemjs/dist/system.src.js"></script> <script src="systemjs.config.js"></script> <script> System.import('$DEMOROOT$/ja/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-resources-ja': 'npm:@mescius/spread-sheets-resources-ja/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);