年份迷你图

年份迷你图对于展示你年度数据的趋势是很有用的。

你可以通过 YearSparkline 方法创建一个年份迷你图:=YEARSPARKLINE(year, dataRange, emptyColor, startColor, middleColor, endColor) 或者 =YEARSPARKLINE(year, dataRange, colorRange)。 此函数有以下参数: year : 类型为数字,表示年份,比如 2015。 dataRange : 类型为引用,所引用的单元格第一列为日期,第二列为数字,比如 "A1:B400"。 emptyColor : 类型为颜色字符串,用这种颜色填充没有值或者值为0的日期,比如 "lightgray"。 startColor : 类型为颜色字符串,用这种颜色填充值最小的日期,比如 "lightgreen"。 middleColor : 类型为颜色字符串,用这种颜色填充值为最大值和最小值平均值的日期,比如 "green"。 endColor : 类型为颜色字符串,用这种颜色填充值最大的日期,比如 "darkgreen"。 colorRange : 类型为引用,所引用的单元格数据为颜色字符串。
window.onload = function () { var spread = new GC.Spread.Sheets.Workbook(document.getElementById("ss"), { sheetCount: 2 }); var sheet1 = spread.sheets[0]; var sheet2 = spread.sheets[1]; sheet1.suspendPaint(); sheet2.suspendPaint(); initNormalSheet(sheet1); initColorRangeSheet(sheet2); sheet2.resumePaint(); sheet1.resumePaint(); }; function initNormalSheet(sheet) { sheet.setFormatter(-1, 0, "MM/DD/YYYY"); sheet.setColumnWidth(0, 75); sheet.setColumnWidth(1, 25); sheet.setColumnWidth(2, 25); sheet.setColumnWidth(3, 600); sheet.addSpan(4, 3, 4, 10); sheet.setRowCount(365); var rowCount = sheet.getRowCount(); for (var row = 0; row < rowCount; row++) { sheet.setValue(row, 0, new Date(2016, 0, row + 1)); sheet.setValue(row, 1, Math.round(Math.random() * 100)); } sheet.setFormula(4, 3, '=YearSparkline(2016, A1:B' + rowCount + ', "lightgray", "lightgreen", "green", "darkgreen")'); } function initColorRangeSheet(sheet) { sheet.name("Use colorRange"); sheet.setFormatter(-1, 0, "MM/DD/YYYY"); sheet.setColumnWidth(0, 75); sheet.setColumnWidth(1, 25); sheet.setColumnWidth(2, 100); sheet.setColumnWidth(3, 600); sheet.setValue(1, 3, "lightgray"); sheet.setValue(2, 3, "lightgreen"); sheet.setValue(3, 3, "green"); sheet.setValue(4, 3, "darkgreen"); sheet.addSpan(6, 3, 4, 10); sheet.setRowCount(365); var rowCount = sheet.getRowCount(); var colorList = ["lightgray", "red", "green", "darkgreen", "blue", "yellow", "orange", "pink", "gray", "black"]; for (var row = 0; row < rowCount; row++) { sheet.setValue(row, 0, new Date(2016, 0, row + 1)); sheet.setValue(row, 1, Math.round(Math.random() * 100)); sheet.setValue(row, 2, colorList[Math.round(Math.random() * 10)]) } sheet.setFormula(6, 3, '=YearSparkline(2016, A1:B' + rowCount + ', C1:C365)'); }
<!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/spread-sheets/styles/gc.spread.sheets.excel2013white.css"> <script src="$DEMOROOT$/zh/purejs/node_modules/@grapecity/spread-sheets/dist/gc.spread.sheets.all.min.js" type="text/javascript"></script> <script src="$DEMOROOT$/zh/purejs/node_modules/@grapecity/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" style="width:100%;height:100%"></div> </div> </body> </html>
.sample-tutorial { position: relative; height: 100%; overflow: hidden; } body { position: absolute; top: 0; bottom: 0; left: 0; right: 0; }