通过YearSparkline函数可以创建年份迷你图
YearSparkline函数有以下这些参数:
Option | Description |
year | 类型为数字,表示年份,比如 2017。 |
dataRange | 类型为引用,所引用的单元格第一列为日期,第二列为数字,比如 "A1:B400"。 |
emptyColor | 类型为颜色字符串,用这种颜色填充没有值或者值为0的日期,比如 "lightgray"。 |
startColor | 类型为颜色字符串,用这种颜色填充值最小的日期,比如 "lightgreen"。 |
middleColor | 类型为颜色字符串,用这种颜色填充值为最大值和最小值平均值的日期,比如 "green"。 |
endColor | 类型为颜色字符串,用这种颜色填充值最大的日期,比如 "darkgreen"。 |
colorRange | 类型为引用,所引用的单元格数据为颜色字符串。 |
你可以通过 年份迷你图函数创建一个年份迷你图,例如:
=YEARSPARKLINE(year, dataRange, emptyColor, startColor, middleColor, endColor)
=YEARSPARKLINE(year, dataRange, colorRange)
下面代码展示了如何创建年份迷你图
JavaScript
activeSheet.name("ColorRange"); activeSheet.setFormatter(-1, 0, "MM/DD/YYYY"); activeSheet.setRowHeight(0, 100); activeSheet.setColumnWidth(0, 75); activeSheet.setColumnWidth(1, 25); activeSheet.setColumnWidth(2, 25); activeSheet.setColumnWidth(3, 600); activeSheet.setRowCount(500); var rowCount = activeSheet.getRowCount(); activeSheet.setValue(0, 1, "sales"); activeSheet.setValue(0, 2, "color"); for (var rowIndex = 1; rowIndex < rowCount; rowIndex++) { activeSheet.setValue(rowIndex, 0, new Date(2017, 4, rowIndex)); var sale = Math.round(Math.random() * 50000); activeSheet.setValue(rowIndex, 1, sale); activeSheet.setValue(rowIndex, 2, sale > 25000 ? "Green" : "YellowGreen"); } activeSheet.setFormula(0, 3, '=YearSparkline(2017, A2:B' + rowCount + ', C2:C' + rowCount +')');