你可以通过面积函数创建一个面积函数迷你图,例如: =AREASPARKLINE(points, min?, max?, line1?, line2?, colorPositive?, colorNegative?).
这个函数有以下这些参数:
points: 表示一片数据区域,例如 "D1:D6"。如果这片区域中哪个单元格的值不是一个合法的数字,那么会它的值被视为0。
min:(可选的参数)迷你图的值域下限。 这片区域的最小值和你设置的值域下限中更小的起作用。 默认值是这片数据区域的最小值。
max:(可选参数)迷你图的值域上限。这片区域中的最大值和你设置的值域上限中更大的起作用。默认值是这篇数据区域的最大值。
line1:(可选参数)表示一个水平线在垂直方向的位置的值;默认情况下是不存在的这根线的。
line2:(可选参数)表示另外一个水平线在垂直方向的位置的值;默认情况下也是不存在这根线的。
colorPositive:(可选参数)表示值是正数的区域填充颜色;默认值是"#787878"。
colorNegative:(可选参数)表示值是负数的区域填充颜色;默认值是"#CB0000"。
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.sheets[0];
sheet.suspendPaint();
sheet.addSpan(0, 0, 1, 5);
sheet.getCell(0, 0).value("Revenue by State").font("17px Arial").vAlign(spreadNS.VerticalAlign.center);
var table1 = sheet.tables.add("table1", 1, 0, 6, 5, spreadNS.Tables.TableThemes.light1);
table1.rowFilter().filterButtonVisible(false);
sheet.setArray(1, 0, [
["State",2018, 2019, 2020,"Diagram"],
["Idaho",10000, -9000, 15000],
["Montana",1000, 9000, ],
["Oregon",10000, 7000, 0],
["Washington",1000, 10000, 5000],
["Utah",-5000, 5000, 12000]]);
sheet.getRange(2, 1,5,3).formatter("$#,##0");
sheet.setFormula(2, 4, '=AREASPARKLINE(B3:D3,,,0,10000,"#82bc00","#f7a711")');
sheet.setFormula(3, 4, '=AREASPARKLINE(B4:D4,,,0,10000,"#82bc00","#f7a711")');
sheet.setFormula(4, 4, '=AREASPARKLINE(B5:D5,,,0,10000,"#82bc00","#f7a711")');
sheet.setFormula(5, 4, '=AREASPARKLINE(B6:D6,,,0,10000,"#82bc00","#f7a711")');
sheet.setFormula(6, 4, '=AREASPARKLINE(B7:D7,,,0,10000,"#82bc00","#f7a711")');
sheet.setRowHeight(0, 50);
sheet.setRowHeight(1, 25);
for (var i = 2; i < 7; i++) {
sheet.setRowHeight(i, 35);
}
sheet.setColumnWidth(0, 100);
sheet.setColumnWidth(1, 70);
sheet.setColumnWidth(2, 70);
sheet.setColumnWidth(3, 70);
sheet.setColumnWidth(4, 200);
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;
}