数式にHBarSparklineまたはVBarSparkline関数を使用することで、水平バー/垂直バースパークラインを作成できます。構文は次のとおりです。=HBARSPARKLINE(value, colorScheme?, axisVisible?, barHeight?) もしくは =VBARSPARKLINE(value, colorScheme?, axisVisible?, barWidth?)
有効なパラメータは次のとおりです。
value: バーの長さを表す数値または参照。「0.3」、「A1」など。値が100%を超える場合、または-100%を下回る場合は、矢印が表示されます。
colorScheme: (オプション)バーの色を表す文字列。デフォルト値は「gray」です。
axisVisible: (オプション)軸を表示するかどうかを表すブール値。デフォルト値はtrueです。
barHeight: (オプション)セルの高さに応じてバーの高さをパーセンテージで表す数値。0から1までの範囲内である必要があります。
barWidth: (オプション)セルの幅に応じてバーの幅をパーセンテージで表す数値。0から1までの範囲内である必要があります。
HBarSparkline: 正の値を表すバーはセルの左端から、負の値を表すバーはセルの右端から開始します。
VBarSparkline: 正の値を表すバーはセルの下端から、負の値を表すバーはセルの上端から開始します。
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.setArray(1,0,[["Channel","Satisfaction %", "Diagram"],
["Email",0.92],
["Social Networks",0.79],
["Forums/Message Boards",0.65],
["Phone",0.58],
["Text Message",0.55],
["Online Chat",0.39],
["Self-Serve Knowledge Base",0.28],
["On-Page Support Widget",0.19]]);
for (var i = 2; i < 10; i++) {
sheet.setRowHeight(i, 30);
sheet.setFormula(i, 2, this.getFormula("B"+(i+1)));
}
sheet.addSpan(0, 0, 1, 3);
sheet.getCell(0, 0).value("Customer Service Satisfaction, by Channel").font("17px Arial").backColor("#E8E8E8").vAlign(GC.Spread.Sheets.VerticalAlign.center);
sheet.getRange(1, 0, 1, 3).font("bold 13px Arial").vAlign(GC.Spread.Sheets.VerticalAlign.center)
.setBorder(new GC.Spread.Sheets.LineBorder("black", GC.Spread.Sheets.LineStyle.thin), { bottom: true });
sheet.getRange(2,1,8,1).formatter("0%").hAlign(GC.Spread.Sheets.HorizontalAlign.left);
sheet.setRowHeight(0, 35);
sheet.setRowHeight(1, 35);
sheet.setColumnWidth(0, 250);
sheet.setColumnWidth(1, 120);
sheet.setColumnWidth(2, 250);
sheet.resumePaint();
}
function getFormula(range) {
return "=LET(ref, "+range+", color, IF(ref >= 0.8, \"#092834\", IF(ref>=0.6, \"#347B98\", IF(ref >0.4, \"#66B032\", IF(ref >= 0.2, \"#B2D732\", IF(ref >= 0, \"#F0F7D4\", \"red\"))))), HBARSPARKLINE(ref, color))";
}
function getVBarFormula(range) {
return "=LET(ref, "+range+", color, IF(ref >= 0.8, \"#092834\", IF(ref>=0.6, \"#347B98\", IF(ref >0.4, \"#66B032\", IF(ref >= 0.2, \"#B2D732\", IF(ref >= 0, \"#F0F7D4\", \"red\"))))), VBARSPARKLINE(ref, color, true, 0.4))";
}
function initVerticalSparkline(sheet, name) {
sheet.suspendPaint();
sheet.name(name);
sheet.setArray(1,0,[
["Name","Employee 1","Employee 2","Employee 3","Employee 4","Employee 5","Employee 6","Employee 7","Employee 8"],
["Progress",1.1,0.79,0.59,0.55,0.37,0.19,0.35,0.60]
]);
for (var i = 0; i < 8; i++) {
var columnChar = String.fromCharCode(66 + i);
sheet.setColumnWidth(i+1, 80);
sheet.setFormula(3, i+1, this.getVBarFormula(columnChar + "3"));
}
sheet.addSpan(0, 0, 1, 9);
sheet.getCell(0, 0).value("Sprint 3 Progress").font("17px Arial").backColor("#E8E8E8").vAlign(GC.Spread.Sheets.VerticalAlign.center);
sheet.getRange(1, 0, 2, 1).font("bold 13px Arial").vAlign(GC.Spread.Sheets.VerticalAlign.center)
.setBorder(new GC.Spread.Sheets.LineBorder("black", GC.Spread.Sheets.LineStyle.thin), { right: true });
sheet.getRange(2,1,1,8).formatter("0%").hAlign(GC.Spread.Sheets.HorizontalAlign.left);
sheet.setRowHeight(0, 35);
sheet.setRowHeight(1, 35);
sheet.setRowHeight(3, 220);
sheet.setColumnWidth(0, 120);
sheet.resumePaint();
}
<!doctype html>
<html style="height:100%;font-size:14px;">
<head>
<meta name="spreadjs culture" content="ja-jp" />
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" type="text/css" href="$DEMOROOT$/ja/purejs/node_modules/@mescius/spread-sheets/styles/gc.spread.sheets.excel2013white.css">
<script src="$DEMOROOT$/ja/purejs/node_modules/@mescius/spread-sheets/dist/gc.spread.sheets.all.min.js" type="text/javascript"></script>
<script src="$DEMOROOT$/ja/purejs/node_modules/@mescius/spread-sheets-resources-ja/dist/gc.spread.sheets.resources.ja.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;
}