迷你图配置

创建迷你图后,可以控制显示哪些值点 (例如高、 低、 姓或任何负值)、 更改 (行、 列或盈亏) 迷你图的类型,应用样式,以及控制是否显示水平轴。

你可以通过使一些或所有标记可见来突出显示折线迷你图中的各个数据标记(值)。 showFirst: 迷你图组中的每一个迷你图的第一个数据点的的格式是否不同。 showHigh: 迷你图组中的每一个迷你图的最高点所对应的数据点的格式是否不同。 showLast: 迷你图组中的每一个迷你图的最末点所对应的数据点的格式是否不同。 showLow: 迷你图组中的每一个迷你图的最低点所对应的数据点的格式是否不同。 showNegative: 迷你图组中的每一个迷你图的负数数据点的格式是否不同。 showMarkers: 迷你图组中的每一个迷你图的数据标记是否显示。 你可以通过下面这些方法来设置迷你图的样式和格式: axisColor: 轴线的颜色。 firstMarkerColor: 迷你图组中的每一个迷你图的第一个数据点的颜色。 highMarkerColor: 迷你图组中的每一个迷你图的最高数据点的颜色。 lastMarkerColor: 迷你图组中的每一个迷你图的最末数据点的颜色。 lowMarkerColor: 迷你图组中的每一个迷你图的最低数据点的颜色。 markersColor:迷你图组中的每一个迷你图的数据标记的颜色。 negativeColor: 迷你图组中的每一个迷你图的负数数据点的颜色。 seriesColor: 迷你图组中的每一个迷你图的颜色。 迷你图还提供了一些额外的配置。比如,当数据系列中有空值的时候,你可以使用 displayEmptyCellsAs 方法来控制是否显示空值。例如: 这个示例演示了如何应用这些配置:
import * as React from 'react'; import * as ReactDOM from 'react-dom'; import '@grapecity-software/spread-sheets-resources-zh'; GC.Spread.Common.CultureManager.culture("zh-cn"); import GC from '@grapecity-software/spread-sheets'; import { SpreadSheets, Worksheet, Column } from '@grapecity-software/spread-sheets-react'; import './styles.css'; const Component = React.Component; class App extends Component { constructor(props) { super(props); this.spread = null; this.state = { firstMarkerColor: '(none)', buttonDisable: true, type: 0, highMarkerColor: 'Blue', lastMarkerColor: '(none)', lowMarkerColor: 'Blue', negativeMarkerColor: 'Brown', markersColor: '(none)', axisColor: 'black', seriesColor: '(none)', showFirst: false, showHigh: false, showLast: false, showLow: false, showNegative: true, showMarkers: false, displayXAxis: true } } render() { return ( <div class="sample-tutorial"> <div class="sample-spreadsheets"> <SpreadSheets workbookInitialized={spread => this.initSpread(spread)}> </SpreadSheets> </div> <Panel panelInfo={this.state} buttonClick={() => { this.buttonClick() }} showFirstChange={(e) => { this.showFirstChange(e) }} showHighChange={(e) => { this.showHighChange(e) }} showLastChange={(e) => { this.showLastChange(e) }} showLowChange={(e) => { this.showLowChange(e) }} showNegativeChange={(e) => { this.showNegativeChange(e) }} showMarkersChange={(e) => { this.showMarkersChange(e) }} displayXAxisChange={(e) => { this.displayXAxisChange(e) }} firstMarkerColorChange={(e) => { this.firstMarkerColorChange(e) }} typeChange={(e) => { this.typeChange(e) }} highMarkerColorChange={(e) => { this.highMarkerColorChange(e) }} lastMarkerColorChange={(e) => { this.lastMarkerColorChange(e) }} lowMarkerColorChange={(e) => { this.lowMarkerColorChange(e) }} negativeMarkerColorChange={(e) => { this.negativeMarkerColorChange(e) }} markersColorChange={(e) => { this.markersColorChange(e) }} axisColorChange={(e) => { this.axisColorChange(e) }} seriesColorChange={(e) => { this.seriesColorChange(e) }} ></Panel> </div> ) } buttonClick() { let sheet = this.spread.getActiveSheet(); sheet.suspendPaint(); let sels = sheet.getSelections(); let setting = new GC.Spread.Sheets.Sparklines.SparklineSetting(); let sparklineType = this.state.type; if (sels && sels.length > 0) { let sel = this.getActualRange(sels[0], sheet.getRowCount(), sheet.getColumnCount()); let sparkline = this.findSparkLine(sheet, sel); if (sparkline != null) { sparkline.setting(this.buildSparklineSettings(setting)); sparkline.sparklineType(sparklineType); } } sheet.resumePaint(); } showFirstChange(e) { let value = e.target.checked; this.setState(() => ({ showFirst: value })); } showHighChange(e) { let value = e.target.checked; this.setState(() => ({ showHigh: value })); } showLastChange(e) { let value = e.target.checked; this.setState(() => ({ showLast: value })); } showLowChange(e) { let value = e.target.checked; this.setState(() => ({ showLow: value })); } showNegativeChange(e) { let value = e.target.checked; this.setState(() => ({ showNegative: value })); } showMarkersChange(e) { let value = e.target.checked; this.setState(() => ({ showMarkers: value })); } displayXAxisChange(e) { let value = e.target.checked; this.setState(() => ({ displayXAxis: value })); } firstMarkerColorChange(e) { let value = e.target.value; this.setState(() => ({ firstMarkerColor: value })); } typeChange(e) { let value = parseInt(e.target.value); this.setState(() => ({ type: value })); } highMarkerColorChange(e) { let value = e.target.value; this.setState(() => ({ highMarkerColor: value })); } lastMarkerColorChange(e) { let value = e.target.value; this.setState(() => ({ lastMarkerColor: value })); } lowMarkerColorChange(e) { let value = e.target.value; this.setState(() => ({ lowMarkerColor: value })); } negativeMarkerColorChange(e) { let value = e.target.value; this.setState(() => ({ negativeMarkerColor: value })); } markersColorChange(e) { let value = e.target.value; this.setState(() => ({ markersColor: value })); } axisColorChange(e) { let value = e.target.value; this.setState(() => ({ axisColor: value })); } seriesColorChange(e) { let value = e.target.value; this.setState(() => ({ seriesColor: value })); } getActualRange(range, maxRowCount, maxColCount) { let row = range.row < 0 ? 0 : range.row; let col = range.col < 0 ? 0 : range.col; let rowCount = range.rowCount < 0 ? maxRowCount : range.rowCount; let colCount = range.colCount < 0 ? maxColCount : range.colCount; return new GC.Spread.Sheets.Range(row, col, rowCount, colCount); } findSparkLine(sheet, range) { let row = range.row, col = range.col, rowCount = range.rowCount, colCount = range.colCount; for (let i = 0; i < rowCount; i++) { for (let j = 0; j < colCount; j++) { let sparkline = sheet.getSparkline(row + i, col + j); if (sparkline != null) { return sparkline; } } } return null; } buildSparklineSettings(setting) { if (setting == null) setting = new GC.Spread.Sheets.Sparklines.SparklineSetting(); let firstMarkerColor = this.state.firstMarkerColor; if (firstMarkerColor != '(none)') setting.options.firstMarkerColor = firstMarkerColor; let highMarkerColor = this.state.highMarkerColor; if (highMarkerColor != '(none)') setting.options.highMarkerColor = highMarkerColor; let lastMarkerColor = this.state.lastMarkerColor; if (lastMarkerColor != '(none)') setting.options.lastMarkerColor = lastMarkerColor; let lowMarkerColor = this.state.lowMarkerColor; if (lowMarkerColor != '(none)') setting.options.lowMarkerColor = lowMarkerColor; let negativeMarkerColor = this.state.negativeMarkerColor; if (negativeMarkerColor != '(none)') setting.options.negativeColor = negativeMarkerColor; let markersColor = this.state.markersColor; if (markersColor != '(none)') setting.options.markersColor = markersColor; let AxisColor = this.state.axisColor; if (AxisColor != '(none)') setting.options.axisColor = AxisColor; let SeriesColor = this.state.seriesColor; if (SeriesColor != '(none)') setting.options.seriesColor = SeriesColor; setting.options.showFirst = this.state.showFirst; setting.options.showHigh = this.state.showHigh; setting.options.showLast = this.state.showLast; setting.options.showLow = this.state.showLow; setting.options.showNegative = this.state.showNegative; setting.options.showMarkers = this.state.showMarkers; setting.options.displayXAxis = this.state.displayXAxis; return setting; } initSpread(spread) { this.spread = spread; let spreadNS = GC.Spread.Sheets; let self = this; let sheet = this.spread.getSheet(0); sheet.suspendPaint(); sheet.options.allowCellOverflow = true; var data = [1,-2,-1,6,4,-4,3,8]; var dateAxis = [new Date(2011, 0, 5),new Date(2011, 0, 1),new Date(2011, 1, 11),new Date(2011, 2, 1), new Date(2011, 1, 1),new Date(2011, 1, 3),new Date(2011, 2, 6),new Date(2011, 1, 19)]; sheet.setValue(0, 0, "Series 1"); sheet.setValue(0, 1, "Series 2"); for(let i=0;i<8;i++) { sheet.setValue(i+1, 0,data[i]); sheet.getCell(i+1, 1).value(dateAxis[i]).formatter("yyyy-mm-dd"); } sheet.setColumnWidth(1,100); sheet.setValue(10, 0, "*Data Range is A2-A9"); sheet.setValue(11, 0, "*Date axis range is B2-B9"); var dataRange = new spreadNS.Range(1, 0, 8, 1); var dateAxisRange = new spreadNS.Range(1, 1, 8, 1); sheet.getCell(13, 0).text("Sparkline with dateAxis:"); sheet.getCell(14, 0).text("(1) Line"); sheet.getCell(14, 3).text("(2)Column"); sheet.getCell(14, 6).text("(3)Winloss"); //line sheet.addSpan(15, 0, 4, 3); var setting = new spreadNS.Sparklines.SparklineSetting(); setting.options.showMarkers = true; setting.options.displayXAxis = true; setting.options.showFirst = true; setting.options.showLast = true; setting.options.showLow = true; setting.options.showHigh = true; setting.options.showNegative = true; sheet.setSparkline(15, 0, dataRange , spreadNS.Sparklines.DataOrientation.vertical , spreadNS.Sparklines.SparklineType.line , setting , dateAxisRange , spreadNS.Sparklines.DataOrientation.vertical ); //column sheet.addSpan(15, 3, 4, 3); setting = new spreadNS.Sparklines.SparklineSetting(); setting.options.displayXAxis = true; setting.options.showFirst = true; setting.options.showLast = true; setting.options.showLow = true; setting.options.showHigh = true; setting.options.showNegative = true; sheet.setSparkline(15, 3, dataRange , spreadNS.Sparklines.DataOrientation.vertical , spreadNS.Sparklines.SparklineType.column , setting , dateAxisRange , spreadNS.Sparklines.DataOrientation.vertical ); //winloss sheet.addSpan(15, 6, 4, 3); setting = new spreadNS.Sparklines.SparklineSetting(); setting.options.displayXAxis = true; setting.options.showNegative = true; sheet.setSparkline(15, 6, dataRange , spreadNS.Sparklines.DataOrientation.vertical , spreadNS.Sparklines.SparklineType.winloss , setting , dateAxisRange , spreadNS.Sparklines.DataOrientation.vertical ); sheet.bind(GC.Spread.Sheets.Events.SelectionChanged, selectionChangedCallback); sheet.resumePaint(); function selectionChangedCallback() { let sheet = self.spread.getActiveSheet(); let sparkline = sheet.getSparkline(sheet.getActiveRowIndex(), sheet.getActiveColumnIndex()); if (sparkline) { getSparklineSettings(sparkline); self.setState(() => ({ buttonDisable: false })); } else { initSparklineSettings(); self.setState(() => ({ buttonDisable: true })); } } function initSparklineSettings() { self.setState(() => ({ type: 0, firstMarkerColor: '(none)', highMarkerColor: 'Blue', lastMarkerColor: '(none)', lowMarkerColor: 'Blue', negativeMarkerColor: 'Brown', markersColor: '(none)', axisColor: 'Black', seriesColor: '(none)', showFirst: false, showHigh: false, showLow: false, showLast: false, showNegative: false, showMarkers: false, displayXAxis: true })); } function getSparklineSettings(sparkline) { let setting = sparkline.setting(); self.setState({ type: sparkline.sparklineType(), firstMarkerColor: setting.options.firstMarkerColor, highMarkerColor: setting.options.highMarkerColor, lastMarkerColor: setting.options.lastMarkerColor, lowMarkerColor: setting.options.lowMarkerColor, negativeMarkerColor: setting.options.negativeColor, markersColor: setting.options.markersColor, axisColor: setting.options.axisColor, seriesColor: setting.options.seriesColor, showFirst: setting.options.showFirst, showHigh: setting.options.showHigh, showLow: setting.options.showLow, showLast: setting.options.showLast, showNegative: setting.options.showNegative, showMarkers: setting.options.showMarkers, displayXAxis: setting.options.displayXAxis }); } } } const Panel = (props) => { const { panelInfo, buttonClick, showFirstChange, showHighChange, showLastChange, showLowChange, showNegativeChange, showMarkersChange, displayXAxisChange, firstMarkerColorChange, typeChange, highMarkerColorChange, lastMarkerColorChange, lowMarkerColorChange, negativeMarkerColorChange, markersColorChange, axisColorChange, seriesColorChange } = props; return ( <div class="options-container"> <div class="option-row"> <label>*Select a sparkline in the spreadsheet then change its properties</label> </div> <div class="option-row"> <div class="option"> <input id='btnChangeSetting' type='button' disabled={panelInfo.buttonDisable} value='Change Setting' onClick={() => { buttonClick() }} /> </div> </div> <div class="option-row"> <div class="option"> <input checked={panelInfo.showFirst} id='showFirst' type='checkbox' onChange={(e) => { showFirstChange(e) }} /> <label for="showFirst">showFirst</label> </div> <div class="option"> <input checked={panelInfo.showHigh} id='showHigh' type='checkbox' onChange={(e) => { showHighChange(e) }} /> <label for="showHigh">showHigh</label> </div> <div class="option"> <input id='showLast' type='checkbox' checked={panelInfo.showLast} onChange={(e) => { showLastChange(e) }} /> <label for="showLast">showLast</label> </div> <div class="option"> <input id='showLow' type='checkbox' checked={panelInfo.showLow} onChange={(e) => { showLowChange(e) }} /> <label for="showLow">showLow</label> </div> <div class="option"> <input id='showNegative' type='checkbox' checked={panelInfo.showNegative} onChange={(e) => { showNegativeChange(e) }} /> <label for="showNegative">showNegative</label> </div> <div class="option"> <input id='showMarkers' type='checkbox' checked={panelInfo.showMarkers} onChange={(e) => { showMarkersChange(e) }} /> <label for="showMarkers">showMarkers</label> </div> <div class="option"> <input id="displayXAxis" type="checkbox" checked={panelInfo.displayXAxis} onChange={(e) => { displayXAxisChange(e) }} /> <label for="displayXAxis">displayXAxis</label> </div> </div> <div class="option-row"> <div class="option"> <label for="firstMarkerColor" class="block">First Marker Color</label> <input id='firstMarkerColor' class="control" value={panelInfo.firstMarkerColor} onChange={(e) => { firstMarkerColorChange(e) }} /> </div> <div class="option"> <label for="sparklinetype" class="block">Type:</label> <select id="sparklinetype" class="control" value={panelInfo.type} onChange={(e) => { typeChange(e) }}> <option value="0">line</option> <option value="1">column</option> <option value="2">winloss</option> </select> </div> <div class="option"> <label for="highMarkerColor" class="block">High Marker Color</label> <input id='highMarkerColor' class="control" value={panelInfo.highMarkerColor} onChange={(e) => { highMarkerColorChange(e) }} /> </div> <div class="option"> <label for="lastMarkerColor" class="block">Last Marker Color</label> <input id='lastMarkerColor' class="control" value={panelInfo.lastMarkerColor} onChange={(e) => { lastMarkerColorChange(e) }} /> </div> <div class="option"> <label for="lowMarkerColor" class="block">Low Marker Color</label> <input id='lowMarkerColor' class="control" value={panelInfo.lowMarkerColor} onChange={(e) => { lowMarkerColorChange(e) }} /> </div> <div class="option"> <label for="negativeMarkerColor" class="block">Negative Marker Color</label> <input id='negativeMarkerColor' class="control" value={panelInfo.negativeMarkerColor} onChange={(e) => { negativeMarkerColorChange(e) }} /> </div> <div class="option"> <label for="markersColor" class="block">Markers Color</label> <input id='markersColor' class="control" value={panelInfo.markersColor} onChange={(e) => { markersColorChange(e) }} /> </div> <div class="option"> <label for="AxisColor" class="block">Axis Color</label> <input id='AxisColor' class="control" value={panelInfo.axisColor} onChange={(e) => { axisColorChange(e) }} /> </div> <div class="option"> <label for="SeriesColor" class="block">SeriesColor</label> <input id='SeriesColor' class="control" value={panelInfo.seriesColor} onChange={(e) => { seriesColorChange(e) }} /> </div> </div> </div> ) } ReactDOM.render(<App />, document.getElementById('app'));
<!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$/zh/react/node_modules/@grapecity-software/spread-sheets/styles/gc.spread.sheets.excel2013white.css"> <!-- SystemJS --> <script src="$DEMOROOT$/zh/react/node_modules/systemjs/dist/system.src.js"></script> <script src="systemjs.config.js"></script> <script> System.import('$DEMOROOT$/zh/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 { padding-bottom: 6px; } .block { display: block; padding: 6px 0; } .control { padding: 4px 8px; box-sizing: border-box; width: 100%; } 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: { '@grapecity-software/spread-sheets': 'npm:@grapecity-software/spread-sheets/index.js', '@grapecity-software/spread-sheets-resources-zh': 'npm:@grapecity-software/spread-sheets-resources-zh/index.js', '@grapecity-software/spread-sheets-react': 'npm:@grapecity-software/spread-sheets-react/index.js', '@grapecity-software/jsob-test-dependency-package/react-components': 'npm:@grapecity-software/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);