迷你图配置

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

你可以通过使一些或所有标记可见来突出显示折线迷你图中的各个数据标记(值)。 showFirst: 迷你图组中的每一个迷你图的第一个数据点的的格式是否不同。 showHigh: 迷你图组中的每一个迷你图的最高点所对应的数据点的格式是否不同。 showLast: 迷你图组中的每一个迷你图的最末点所对应的数据点的格式是否不同。 showLow: 迷你图组中的每一个迷你图的最低点所对应的数据点的格式是否不同。 showNegative: 迷你图组中的每一个迷你图的负数数据点的格式是否不同。 showMarkers: 迷你图组中的每一个迷你图的数据标记是否显示。 你可以通过下面这些方法来设置迷你图的样式和格式: axisColor: 轴线的颜色。 firstMarkerColor: 迷你图组中的每一个迷你图的第一个数据点的颜色。 highMarkerColor: 迷你图组中的每一个迷你图的最高数据点的颜色。 lastMarkerColor: 迷你图组中的每一个迷你图的最末数据点的颜色。 lowMarkerColor: 迷你图组中的每一个迷你图的最低数据点的颜色。 markersColor:迷你图组中的每一个迷你图的数据标记的颜色。 negativeColor: 迷你图组中的每一个迷你图的负数数据点的颜色。 seriesColor: 迷你图组中的每一个迷你图的颜色。 迷你图还提供了一些额外的配置。比如,当数据系列中有空值的时候,你可以使用 displayEmptyCellsAs 方法来控制是否显示空值。例如: 这个示例演示了如何应用这些配置:
window.onload = function () { var spread = new GC.Spread.Sheets.Workbook(document.getElementById('ss')); initSpread(spread); }; function initSpread(spread) { var spreadNS = GC.Spread.Sheets; var sheet = 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(spreadNS.Events.SelectionChanged, selectionChangedCallback); sheet.resumePaint(); function selectionChangedCallback() { var sheet = spread.getActiveSheet(); var sparkline = sheet.getSparkline(sheet.getActiveRowIndex(), sheet.getActiveColumnIndex()); if (sparkline) { getSparklineSettings(sparkline); _getElementById('btnChangeSetting').disabled = false; } else { initSparklineSettings(); _getElementById('btnChangeSetting').disabled = true; } } function getActualRange(range, maxRowCount, maxColCount) { var row = range.row < 0 ? 0 : range.row; var col = range.col < 0 ? 0 : range.col; var rowCount = range.rowCount < 0 ? maxRowCount : range.rowCount; var colCount = range.colCount < 0 ? maxColCount : range.colCount; return new spreadNS.Range(row, col, rowCount, colCount); } function findSparkLine(sheet, range) { var row = range.row, col = range.col, rowCount = range.rowCount, colCount = range.colCount; for (var i = 0; i < rowCount; i++) { for (var j = 0; j < colCount; j++) { var sparkline = sheet.getSparkline(row + i, col + j); if (sparkline != null) { return sparkline; } } } return null; } _getElementById('btnChangeSetting').addEventListener('click', function () { var sheet = spread.getActiveSheet(); sheet.suspendPaint(); var sels = sheet.getSelections(); var setting = new spreadNS.Sparklines.SparklineSetting(); var sparklinetype = _getElementById("sparklinetype"); var index = sparklinetype.selectedIndex; var sparklineType = parseInt(sparklinetype.options[index].value, 10); if (sels && sels.length > 0) { var sel = getActualRange(sels[0], sheet.getRowCount(), sheet.getColumnCount()); var sparkline = findSparkLine(sheet, sel); if (sparkline != null) { sparkline.setting(buildSparklineSettings(setting)); sparkline.sparklineType(sparklineType); } } sheet.resumePaint(); }); function initSparklineSettings() { var sparklinetype = _getElementById("sparklinetype"); _selectOption(sparklinetype, '0'); _getElementById('firstMarkerColor').setAttribute('value', '(none)'); _getElementById('highMarkerColor').setAttribute('value', 'Blue'); _getElementById('lastMarkerColor').setAttribute('value', '(none)'); _getElementById('lowMarkerColor').setAttribute('value', 'Blue'); _getElementById('negativeMarkerColor').setAttribute('value', 'Brown'); _getElementById('markersColor').setAttribute('value', '(none)'); _getElementById('AxisColor').setAttribute('value', 'Black'); _getElementById('SeriesColor').setAttribute('value', '(none)'); _getElementById('showFirst').checked = false; _getElementById('showHigh').checked = false; _getElementById('showLast').checked = false; _getElementById('showLow').checked = false; _getElementById('showNegative').checked = false; _getElementById('showMarkers').checked = false; _getElementById('displayXAxis').checked = true; } function getSparklineSettings(sparkline) { var setting = sparkline.setting(); var sparklinetype = _getElementById("sparklinetype"); _selectOption(sparklinetype, sparkline.sparklineType() + ""); _getElementById('firstMarkerColor').setAttribute('value', setting.options.firstMarkerColor); _getElementById('highMarkerColor').setAttribute('value', setting.options.highMarkerColor); _getElementById('lastMarkerColor').setAttribute('value', setting.options.lastMarkerColor); _getElementById('lowMarkerColor').setAttribute('value', setting.options.lowMarkerColor); _getElementById('negativeMarkerColor').setAttribute('value', setting.options.negativeColor); _getElementById('markersColor').setAttribute('value', setting.options.markersColor); _getElementById('AxisColor').setAttribute('value', setting.options.axisColor); _getElementById('SeriesColor').setAttribute('value', setting.options.seriesColor); _getElementById('showFirst').checked = setting.options.showFirst; _getElementById('showHigh').checked = setting.options.showHigh; _getElementById('showLast').checked = setting.options.showLast; _getElementById('showLow').checked = setting.options.showLow; _getElementById('showNegative').checked = setting.options.showNegative; _getElementById('showMarkers').checked = setting.options.showMarkers; _getElementById('displayXAxis').checked = setting.options.displayXAxis; } function buildSparklineSettings(setting) { if (setting == null) setting = new spreadNS.Sparklines.SparklineSetting(); var firstMarkerColor = _getElementById('firstMarkerColor'); if (firstMarkerColor.value != '(none)') setting.options.firstMarkerColor = firstMarkerColor.value; var highMarkerColor = _getElementById('highMarkerColor'); if (highMarkerColor.value != '(none)') setting.options.highMarkerColor = highMarkerColor.value; var lastMarkerColor = _getElementById('lastMarkerColor'); if (lastMarkerColor.value != '(none)') setting.options.lastMarkerColor = lastMarkerColor.value; var lowMarkerColor = _getElementById('lowMarkerColor'); if (lowMarkerColor.value != '(none)') setting.options.lowMarkerColor = lowMarkerColor.value; var negativeMarkerColor = _getElementById('negativeMarkerColor'); if (negativeMarkerColor.value != '(none)') setting.options.negativeColor = negativeMarkerColor.value; var markersColor = _getElementById('markersColor'); if (markersColor.value != '(none)') setting.options.markersColor = markersColor.value; var AxisColor = _getElementById('AxisColor'); if (AxisColor.value != '(none)') setting.options.axisColor = AxisColor.value; var SeriesColor = _getElementById('SeriesColor'); if (SeriesColor.value != '(none)') setting.options.seriesColor = SeriesColor.value; setting.options.showFirst = _getElementById('showFirst').checked; setting.options.showHigh = _getElementById('showHigh').checked; setting.options.showLast = _getElementById('showLast').checked; setting.options.showLow = _getElementById('showLow').checked; setting.options.showNegative = _getElementById('showNegative').checked; setting.options.showMarkers = _getElementById('showMarkers').checked; setting.options.displayXAxis = _getElementById('displayXAxis').checked; return setting; } } function _getElementById(id) { return document.getElementById(id); } function _selectOption(select, value) { for (var i = 0; i < select.length; i++) { var op = select.options[i]; if (op.value === value) { op.selected = true; } else { op.selected = false; } } }
<!doctype html> <html style="height:100%;font-size:14px;"> <head> <meta name="spreadjs culture" content="zh-cn" /> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <link rel="stylesheet" type="text/css" href="$DEMOROOT$/zh/purejs/node_modules/@grapecity-software/spread-sheets/styles/gc.spread.sheets.excel2013white.css"> <script src="$DEMOROOT$/zh/purejs/node_modules/@grapecity-software/spread-sheets/dist/gc.spread.sheets.all.min.js" type="text/javascript"></script> <script src="$DEMOROOT$/zh/purejs/node_modules/@grapecity-software/spread-sheets-resources-zh/dist/gc.spread.sheets.resources.zh.min.js" type="text/javascript"></script> <script src="$DEMOROOT$/spread/source/js/license.js" type="text/javascript"></script> <script src="app.js" type="text/javascript"></script> <link rel="stylesheet" type="text/css" href="styles.css"> </head> <body> <div class="sample-tutorial"> <div id="ss" class="sample-spreadsheets"></div> <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' value='Change Setting' /> </div> </div> <div class="option-row"> <div class="option"> <input id='showFirst' type='checkbox' /> <label for="showFirst">showFirst</label> </div> <div class="option"> <input id='showHigh' type='checkbox' /> <label for="showHigh">showHigh</label> </div> <div class="option"> <input id='showLast' type='checkbox' /> <label for="showLast">showLast</label> </div> <div class="option"> <input id='showLow' type='checkbox' /> <label for="showLow">showLow</label> </div> <div class="option"> <input id='showNegative' type='checkbox' /> <label for="showNegative">showNegative</label> </div> <div class="option"> <input id='showMarkers' type='checkbox' /> <label for="showMarkers">showMarkers</label> </div> <div class="option"> <input id="displayXAxis" type="checkbox" /> <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="(none)" /> </div> <div class="option"> <label for="sparklinetype" class="block">Type:</label> <select id="sparklinetype" class="control"> <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="Blue" /> </div> <div class="option"> <label for="lastMarkerColor" class="block">Last Marker Color</label> <input id='lastMarkerColor' class="control" value="(none)" /> </div> <div class="option"> <label for="lowMarkerColor" class="block">Low Marker Color</label> <input id='lowMarkerColor' class="control" value="Blue" /> </div> <div class="option"> <label for="negativeMarkerColor" class="block">Negative Marker Color</label> <input id='negativeMarkerColor' class="control" value="Brown" /> </div> <div class="option"> <label for="markersColor" class="block">Markers Color</label> <input id='markersColor' class="control" value="(none)" /> </div> <div class="option"> <label for="AxisColor" class="block">Axis Color</label> <input id='AxisColor' class="control" value="Black" /> </div> <div class="option"> <label for="SeriesColor" class="block">SeriesColor</label> <input id='SeriesColor' class="control" value="(none)" /> </div> </div> </div> </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; }