堆积函数迷你图

堆积函数迷你图对于比较不同的值和不同的类别是很有用的。

你可以通过堆积函数创建一个堆积函数迷你图,比如: =STACKEDSPARKLINE(points, colorRange?, labelRange?, maximum?, targetRed?, targetGreen?, targetBlue?, tragetYellow?, color?, highlightPosition?, vertical?, textOrientation?, textSize?). 这个函数有以下这些参数: points: 表示所描述的数据区域,比如"A1:A4"。 colorRange: (可选参数)类型为引用,所引用的单元格中包含了所有的颜色,比如"B1:B4";默认值是由下面的color参数所代表的颜色生成的。 labelRange: (可选参数)类型为引用,所引用的单元格中包含了所有的标注,比如"C1:C4";默认值是空字符串。 maximum: (可选参数)类型为数字,表示迷你图的最大值;默认值是所有值为正的总和。 targetRed: (可选参数)类型为数字,表示红线的位置;默认值是空字符串,也就是没有红线。 targetGreen: (可选参数)类型为数字,表示绿线的位置;默认值是空字符串,也就是没有绿线。 targetBlue: (可选参数)类型为数字,表示蓝线所在的位置;默认值是空字符串,也就是没有蓝线。 targetYellow: (可选参数)类型为数字,表示黄线所在的位置;默认值是空字符串,也就是没有黄线。 color: (可选参数)类型为颜色字符串,用来生成所有颜色的颜色字符串,如果colorRange省略的话,才会起作用;默认值是"#646464"。 highlightPosition: (可选参数)类型为数字,表示应该高亮的是哪个区域;默认值是空字符串,也就是没有高亮区域。 vertical: (可选参数)类型为布尔值,表示迷你图是垂直显示还是水平显示。默认值是false,也就是水平显示。 textOrientation: (可选参数)类型为数字,表示标注文本的显示方向。可以是以下一种: 0: (默认值)水平显示 1: 垂直显示 textSize: (可选参数)类型为数字,表示标注文本的大小(以像素为单位);默认值是10。
var spreadNS = GC.Spread.Sheets; window.onload = function () { var spread = new GC.Spread.Sheets.Workbook(document.getElementById("ss"), { sheetCount: 2 }); initSpread(spread); }; function initSpread(spread) { spread.options.newTabVisible = false; initHorizontalSparkline(spread.sheets[0], "Horizontal"); initVerticalSparkline(spread.sheets[1], "Vertical"); }; function initHorizontalSparkline(sheet, name) { sheet.suspendPaint(); sheet.name(name); sheet.addSpan(0, 0, 1, 5); sheet.getCell(0, 0).value("Sales by State").font("20px Arial").hAlign(spreadNS.HorizontalAlign.center).vAlign(spreadNS.VerticalAlign.center); sheet.getRange(1, 0, 1, 5).foreColor("white").backColor("Accent 4").hAlign(spreadNS.HorizontalAlign.center).vAlign(spreadNS.VerticalAlign.center); sheet.setValue(1, 0, "State"); sheet.setValue(1, 1, "Product 1"); sheet.setValue(1, 2, "Product 2"); sheet.setValue(1, 3, "Product 3"); sheet.setValue(1, 4, "Diagram"); sheet.setValue(2, 0, "Idaho"); sheet.setValue(2, 1, 10000); sheet.setValue(2, 2, 12000); sheet.setValue(2, 3, 15000); sheet.setValue(3, 0, "Montana"); sheet.setValue(3, 1, 11000); sheet.setValue(3, 2, 10000); sheet.setValue(3, 3, 15000); sheet.setValue(4, 0, "Oregon"); sheet.setValue(4, 1, 10000); sheet.setValue(4, 2, 17000); sheet.setValue(4, 3, 12000); sheet.setValue(5, 0, "Washington"); sheet.setValue(5, 1, 15000); sheet.setValue(5, 2, 10000); sheet.setValue(5, 3, 15000); sheet.setValue(6, 0, "Utah"); sheet.setValue(6, 1, 10000); sheet.setValue(6, 2, 15000); sheet.setValue(6, 3, 12000); sheet.setValue(7, 1, "orange"); sheet.setValue(7, 2, "purple"); sheet.setValue(7, 3, "yellowgreen"); sheet.setFormatter(-1, 1, "$#,##0"); sheet.setFormatter(-1, 2, "$#,##0"); sheet.setFormatter(-1, 3, "$#,##0"); sheet.setFormula(2, 4, '=STACKEDSPARKLINE(B3:D3,$B$8:$D$8,$B$2:$D$2,40000)'); sheet.setFormula(3, 4, '=STACKEDSPARKLINE(B4:D4,$B$8:$D$8,$B$2:$D$2,40000)'); sheet.setFormula(4, 4, '=STACKEDSPARKLINE(B5:D5,$B$8:$D$8,$B$2:$D$2,40000)'); sheet.setFormula(5, 4, '=STACKEDSPARKLINE(B6:D6,$B$8:$D$8,$B$2:$D$2,40000)'); sheet.setFormula(6, 4, '=STACKEDSPARKLINE(B7:D7,$B$8:$D$8,$B$2:$D$2,40000)'); sheet.setRowHeight(0, 50); sheet.setRowHeight(1, 25); for (var i = 2; i < 7; i++) { sheet.setRowHeight(i, 45); } sheet.setRowHeight(7, 0); sheet.setColumnWidth(0, 100); sheet.setColumnWidth(1, 120); sheet.setColumnWidth(2, 120); sheet.setColumnWidth(3, 120); sheet.setColumnWidth(4, 200); sheet.resumePaint(); } function initVerticalSparkline(sheet, name) { sheet.suspendPaint(); sheet.name(name); sheet.addSpan(0, 0, 1, 6); sheet.getCell(0, 0).value("Sales by State").font("20px Arial").hAlign(spreadNS.HorizontalAlign.center).vAlign(spreadNS.VerticalAlign.center); sheet.getRange(1, 0, 1, 6).foreColor("white").backColor("Accent 4").hAlign(spreadNS.HorizontalAlign.center).vAlign(spreadNS.VerticalAlign.center); sheet.getRange(2, 0, 4, 6).vAlign(spreadNS.VerticalAlign.center); sheet.setFormatter(-1, 1, "$#,##0"); sheet.setFormatter(-1, 2, "$#,##0"); sheet.setFormatter(-1, 3, "$#,##0"); sheet.setFormatter(-1, 4, "$#,##0"); sheet.setFormatter(-1, 5, "$#,##0"); sheet.setColumnWidth(0, 120); sheet.setColumnWidth(1, 120); sheet.setColumnWidth(2, 120); sheet.setColumnWidth(3, 120); sheet.setColumnWidth(4, 120); sheet.setColumnWidth(5, 120); for (var i = 1; i < 5; i++) { sheet.setRowHeight(i, 45); } sheet.setRowHeight(5, 200); sheet.setColumnWidth(6, 0); sheet.setValue(2, 6, "orange"); sheet.setValue(3, 6, "purple"); sheet.setValue(4, 6, "yellowgreen"); sheet.setValue(1, 0, "state"); sheet.setValue(2, 0, "Product 1"); sheet.setValue(3, 0, "Product 2"); sheet.setValue(4, 0, "Product 3"); sheet.setValue(5, 0, "Diagram"); sheet.setValue(1, 1, "Idaho"); sheet.setValue(2, 1, 10000); sheet.setValue(3, 1, 12000); sheet.setValue(4, 1, 15000); sheet.setFormula(5, 1, '=STACKEDSPARKLINE(B$3:B$5,$G$3:$G$5,$A$3:$A$5,40000,,,,,,,TRUE)'); sheet.setValue(1, 2, "Montana"); sheet.setValue(2, 2, 11000); sheet.setValue(3, 2, 10000); sheet.setValue(4, 2, 15000); sheet.setFormula(5, 2, '=STACKEDSPARKLINE(C$3:C$5,$G$3:$G$5,$A$3:$A$5,40000,,,,,,,TRUE)'); sheet.setValue(1, 3, "Oregon"); sheet.setValue(2, 3, 10000); sheet.setValue(3, 3, 17000); sheet.setValue(4, 3, 12000); sheet.setFormula(5, 3, '=STACKEDSPARKLINE(D$3:D$5,$G$3:$G$5,$A$3:$A$5,40000,,,,,,,TRUE)'); sheet.setValue(1, 4, "Washington"); sheet.setValue(2, 4, 15000); sheet.setValue(3, 4, 10000); sheet.setValue(4, 4, 15000); sheet.setFormula(5, 4, '=STACKEDSPARKLINE(E$3:E$5,$G$3:$G$5,$A$3:$A$5,40000,,,,,,,TRUE)'); sheet.setValue(1, 5, "Utah"); sheet.setValue(2, 5, 10000); sheet.setValue(3, 5, 15000); sheet.setValue(4, 5, 12000); sheet.setFormula(5, 5, '=STACKEDSPARKLINE(F$3:F$5,$G$3:$G$5,$A$3:$A$5,40000,,,,,,,TRUE)'); sheet.resumePaint(); }
<!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; }