你可以通过堆积函数创建一个堆积函数迷你图,比如: =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, 7);
sheet.getCell(0, 0).value("Quarterly Sales by Regions 2020").font("20px Arial").vAlign(spreadNS.VerticalAlign.center);
for (var i = 0; i < 7; i++) {
sheet.getCell(1,i).backColor("#E3E3E3");
sheet.setColumnWidth(i, 90);
sheet.setFormatter(-1, i, "$#,##0");
}
sheet.setArray(1, 0, [
["Quarter", "Color Range","East", "West", "North","South","Diagram"],
["Q1","#82BC00", 42000,45000,26000,38000],
["Q2","#AED069", 52000,35000,45000,20000],
["Q3","#D4E3AF", 25000,34000,55000,19000],
["Q4","#F4F8EB", 50000,25000,60000,20000]]);
sheet.setFormula(2, 6, '=STACKEDSPARKLINE(C3:F3,$B$3:$B$6,$C$2:$F$2,170000)');
sheet.setFormula(3, 6, '=STACKEDSPARKLINE(C4:F4,$B$3:$B$6,$C$2:$F$2,170000)');
sheet.setFormula(4, 6, '=STACKEDSPARKLINE(C5:F5,$B$3:$B$6,$C$2:$F$2,170000)');
sheet.setFormula(5, 6, '=STACKEDSPARKLINE(C6:F6,$B$3:$B$6,$C$2:$F$2,170000)');
sheet.setFormula(6, 6, '=STACKEDSPARKLINE(C7:F7,$B$3:$B$6,$C$2:$F$2,170000)');
sheet.setRowHeight(0, 30);
sheet.setRowHeight(1, 25);
for (var i = 2; i < 6; i++) {
sheet.setRowHeight(i, 30);
}
sheet.setColumnWidth(6, 250);
//hide Color Range column
sheet.setColumnWidth(1, 0);
sheet.resumePaint();
}
function initVerticalSparkline(sheet, name) {
sheet.suspendPaint();
sheet.name(name);
sheet.addSpan(0, 0, 1, 5);
sheet.getCell(0, 0).value("Quarterly Sales by Regions 2020").font("20px Arial").vAlign(spreadNS.VerticalAlign.center);
for (var i = 0; i < 5; i++) {
sheet.getCell(1,i).backColor("#E3E3E3");
sheet.setColumnWidth(i, 90);
sheet.setFormatter(-1, i, "$#,##0");
}
sheet.setArray(1, 0, [
["Quarter", "Q1", "Q2", "Q3","Q4"],
["Color Range", "#82BC00","#AED069","#D4E3AF","#F4F8EB"],
["East",42000,52000,25000,50000],
["West",45000,35000,34000,25000],
["North",26000,45000,55000,60000],
["South",38000,20000,19000,20000]]);
sheet.setFormula(7, 1, '=STACKEDSPARKLINE(B$4:B$7,$B$3:$E$3,$A$4:$A$7,170000,,,,,,,TRUE)');
sheet.setFormula(7, 2, '=STACKEDSPARKLINE(C$4:C$7,$B$3:$E$3,$A$4:$A$7,170000,,,,,,,TRUE)');
sheet.setFormula(7, 3, '=STACKEDSPARKLINE(D$4:D$7,$B$3:$E$3,$A$4:$A$7,170000,,,,,,,TRUE)');
sheet.setFormula(7, 4, '=STACKEDSPARKLINE(E$4:E$7,$B$3:$E$3,$A$4:$A$7,170000,,,,,,,TRUE)');
sheet.setFormula(7, 5, '=STACKEDSPARKLINE(F$4:F$7,$B$3:$E$3,$A$4:$A$7,170000,,,,,,,TRUE)');
for (var i = 0; i < 7; i++) {
sheet.setRowHeight(i, 30);
}
sheet.setRowHeight(2, 0);
sheet.setRowHeight(7, 180);
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-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" 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;
}