数式にBulletSparkline関数を使用することで、ブレットスパークラインを作成できます。構文は次のとおりです。=BULLETSPARKLINE(measure, target, maxi, good?, bad?, forecast?, tickunit?, colorScheme?, vertical?, measureColor?, targetColor?, maxiColor?, goodColor?, badColor?, forecastColor?, allowMeasureOverMaxi?, barSize?)
有効なパラメータは次のとおりです。
measure: 計測バーの長さを表す数値または参照。「5」、「A1」など。
target: 目標線の位置を表す数値または参照。「7」、「A2」など。
maxi: スパークラインの最大値を表す数値または参照。「10」、「A3」など。
good: (オプション)「良好」領域の長さを表す数値または参照。「3」、「A4」など。デフォルト値は0です。
bad: (オプション)「不十分」領域の長さを表す数値または参照。「1」、「A5」など。デフォルト値は0です。
forecast: (オプション)予測線の長さを表す数値または参照。「8」、「A6」など。デフォルト値は0です。
tickunit: (オプション)目盛単位を表す数値または参照。「1」、「A7」など。デフォルト値は0です。
colorScheme: (オプション)スパークラインを表示するための一群の色を生成する配色パターンを表す文字列。デフォルト値は「#A0A0A0」です。
vertical: (オプション)スパークラインを垂直に表示するかどうかを表すブール値。デフォルト値はfalseです。
measureColor:(オプション)計測バーの色を表す文字列。
targetColor:(オプション)目標線の色を表す文字列。
maxiColor:(オプション)最大領域の色を表す文字列。
goodColor:(オプション)「良好」領域の色を表す文字列。
badColor:(オプション)「不十分」領域の色を表す文字列。
forecastColor:(オプション)予測線の色を表す文字列。
allowMeasureOverMaxi:(オプション)計測バーが最大を超える可能性があるかどうかを表すブール。 デフォルト値はfalseです。
barSize:(オプション)セルの幅または高さに応じてバーの幅または高さをパーセンテージで表す数値。0から1までの範囲内である必要があります。
var spreadNS = GC.Spread.Sheets, spread;
window.onload = function () {
spread = new GC.Spread.Sheets.Workbook(document.getElementById("ss"), { sheetCount: 2 });
initSpread(spread);
document.getElementById('colorScheme').addEventListener('change',applyChanges);
document.getElementById('measureColor').addEventListener('change',applyChanges);
document.getElementById('targetColor').addEventListener('change',applyChanges);
document.getElementById('maxiColor').addEventListener('change',applyChanges);
document.getElementById('goodColor').addEventListener('change',applyChanges);
document.getElementById('badColor').addEventListener('change',applyChanges);
document.getElementById('forecastColor').addEventListener('change',applyChanges);
document.getElementById('allowMeasureOverMaxi').addEventListener('change',applyChanges);
document.getElementById('barSize').addEventListener('change',applyChanges);
};
function applyChanges() {
var sheet = spread.getActiveSheet();
if (spread.getActiveSheetIndex() == 0) {
for (var index = 3; index < 9; index++) {
sheet.setFormula(index, 1, '=BULLETSPARKLINE($E' + (index + 1) + ','+
'$F' + (index + 1) +','+
'$G' + (index + 1) +','+
'$H' + (index + 1) + ','+
'$I' + (index + 1) + ','+
'$D' + (index + 1) + ',1,"' +
document.getElementById('colorScheme').value + '",false,"'+
document.getElementById('measureColor').value + '","'+
document.getElementById('targetColor').value + '","'+
document.getElementById('maxiColor').value + '","'+
document.getElementById('goodColor').value + '","'+
document.getElementById('badColor').value + '","'+
document.getElementById('forecastColor').value +'",'+
document.getElementById('allowMeasureOverMaxi').checked +','+
document.getElementById('barSize').value );
}
} else if (spread.getActiveSheetIndex() == 1) {
for (var index = 2; index < 8; index++) {
var columnChar = String.fromCharCode(65 + index);
sheet.setFormula(9, index, '=BULLETSPARKLINE($' + columnChar + '5,'+
'$' + columnChar +'6,'+
'$' + columnChar +'7,'+
'$' + columnChar + '8,'+
'$' + columnChar + '9,'+
'$' + columnChar + '4,1,"' +
document.getElementById('colorScheme').value + '",true,"'+
document.getElementById('measureColor').value + '","'+
document.getElementById('targetColor').value + '","'+
document.getElementById('maxiColor').value + '","'+
document.getElementById('goodColor').value + '","'+
document.getElementById('badColor').value + '","'+
document.getElementById('forecastColor').value +'",'+
document.getElementById('allowMeasureOverMaxi').checked +','+
document.getElementById('barSize').value );
}
}
}
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(1, 1, 1, 8);
sheet.getCell(1, 1).value("Revenue By Region (million $)")
.font("20px Calibri").hAlign(spreadNS.HorizontalAlign.center).vAlign(spreadNS.VerticalAlign.center)
.foreColor("white").backColor("#82bc00");
sheet.getRange(2, 1, 1, 8).vAlign(spreadNS.VerticalAlign.center)
.font("bold 16px Calibri")
.backColor("#F4F8EB");
sheet.getRange(3, 1, 6, 7).font("20px").vAlign(spreadNS.VerticalAlign.center);
sheet.getRange(2, 1, 7, 8).setBorder(new GC.Spread.Sheets.LineBorder("Black", GC.Spread.Sheets.LineStyle.thin), {
all: true
});
sheet.getRange(3, 1, 6, 8).setBorder(new GC.Spread.Sheets.LineBorder("Black", GC.Spread.Sheets.LineStyle.dotted), {
inside: true
});
sheet.setArray(2, 2, [
['Region', 'Forecast', 'Actual', 'Target', 'Max', 'Optimist F.','Pessimist F.',' '],
['North America', 80, 75, 70, 95, 65, 50],
['South America', 79, 62, 80, 95, 75, 50],
['Europe', 95, 100, 100, 120, 90, 80],
['Azia', 80, 95, 80, 90, 70, 55],
['Australia', 35, 20, 40,50, 35, 15],
['Africa', 34, 40, 30,50, 20, 15]
]);
for (var index = 3; index < 9; index++) {
sheet.setFormula(index, 1, '=BULLETSPARKLINE($E' + (index + 1) + ','+
'$F' + (index + 1) +','+
'$G' + (index + 1) +','+
'$H' + (index + 1) + ','+
'$I' + (index + 1) + ','+
'$D' + (index + 1) + ',1,"#FFFFFF",false,"#000000","#F7A711","#DDDDDD","#BBBBBB","#999999","#FFFFFF",TRUE,0.7');
}
sheet.setRowHeight(1, 30);
for (var i = 3; i < 9; i++) {
sheet.setRowHeight(i, 40);
}
for (var j = 2; j < 9; j++) {
sheet.setColumnWidth(j, 100);
}
sheet.setColumnWidth(1, 250);
sheet.resumePaint();
}
function initVerticalSparkline(sheet, name) {
sheet.suspendPaint();
sheet.name(name);
sheet.addSpan(1, 1, 1, 7);
sheet.getCell(1, 1).value("Revenue By Region (million $)")
.font("20px Calibri").hAlign(spreadNS.HorizontalAlign.center).vAlign(spreadNS.VerticalAlign.center)
.foreColor("white").backColor("#82bc00");
sheet.getRange(2, 1, 7, 1).vAlign(spreadNS.VerticalAlign.center)
.font("bold 16px Calibri")
.backColor("#F4F8EB");
sheet.getRange(2, 2, 7, 6).font("20px").vAlign(spreadNS.VerticalAlign.center);
sheet.getRange(2, 1, 7, 7).setBorder(new GC.Spread.Sheets.LineBorder("Black", GC.Spread.Sheets.LineStyle.thin), {
all: true
});
sheet.getRange(2, 2, 7, 6).setBorder(new GC.Spread.Sheets.LineBorder("Black", GC.Spread.Sheets.LineStyle.dotted), {
inside: true
});
sheet.setArray(2, 1, [
['Region', 'North America', 'South America', 'Europe', 'Azia', 'Australia','Africa'],
['Forecast', 80, 79, 95, 80, 35, 34],
['Actual', 75, 62, 100, 95, 20, 40],
['Target',70, 80, 100, 80, 40, 30],
['Max',95, 95, 120, 90, 50, 50],
['Optimist F.', 65, 75, 90,70, 35, 20],
['Pessimist F.', 50, 50, 80,55, 15, 15]
]);
for (var index = 2; index < 8; index++) {
var columnChar = String.fromCharCode(65 + index);
sheet.setFormula(9, index, '=BULLETSPARKLINE($' + columnChar + '5,'+
'$' + columnChar +'6,'+
'$' + columnChar +'7,'+
'$' + columnChar + '8,'+
'$' + columnChar + '9,'+
'$' + columnChar + '4,1,"#FFFFFF",TRUE,"#000000","#F7A711","#DDDDDD","#BBBBBB","#999999","#FFFFFF",TRUE,0.7');
}
sheet.setRowHeight(1, 30);
sheet.setRowHeight(9, 200);
for (var j = 1; j < 8; j++) {
sheet.setColumnWidth(j, 100);
}
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" class="sample-spreadsheets"> </div>
<div class="options-container">
<div>
<label><b>設定:</b></label>
</div>
<hr>
<div class="option-row">
<label for="colorScheme">カラースキーム:</label>
<select id="colorScheme" style="margin: 0 20px 0 6px">
<option value="#FFFFFF" selected>White</option>
<option value="#000000">Black</option>
<option value="#F7A711">Orange</option>
<option value="#DDDDDD">LightGrey</option>
<option value="#BBBBBB">Grey</option>
<option value="#999999">DarkGrey</option>
<option value="#82BC00">Green</option>
</select>
</div>
<div class="option-row">
<label for="measureColor">計測バーの色:</label>
<select id="measureColor" style="margin: 0 20px 0 6px">
<option value="#FFFFFF">White</option>
<option value="#000000" selected>Black</option>
<option value="#F7A711">Orange</option>
<option value="#DDDDDD">LightGrey</option>
<option value="#BBBBBB">Grey</option>
<option value="#999999">DarkGrey</option>
<option value="#82BC00">Green</option>
</select>
</div>
<div class="option-row">
<label for="targetColor">目標線の色:</label>
<select id="targetColor" style="margin: 0 20px 0 6px">
<option value="#FFFFFF">White</option>
<option value="#000000">Black</option>
<option value="#F7A711" selected>Orange</option>
<option value="#DDDDDD">LightGrey</option>
<option value="#BBBBBB">Grey</option>
<option value="#999999">DarkGrey</option>
<option value="#82BC00">Green</option>
</select>
</div>
<div class="option-row">
<label for="maxiColor">最大領域の色:</label>
<select id="maxiColor" style="margin: 0 20px 0 6px">
<option value="#FFFFFF">White</option>
<option value="#000000">Black</option>
<option value="#F7A711">Orange</option>
<option value="#DDDDDD" selected>LightGrey</option>
<option value="#BBBBBB">Grey</option>
<option value="#999999">DarkGrey</option>
<option value="#82BC00">Green</option>
</select>
</div>
<div class="option-row">
<label for="goodColor">「良好」領域の色:</label>
<select id="goodColor" style="margin: 0 20px 0 6px">
<option value="#FFFFFF">White</option>
<option value="#000000">Black</option>
<option value="#F7A711">Orange</option>
<option value="#DDDDDD">LightGrey</option>
<option value="#BBBBBB" selected>Grey</option>
<option value="#999999">DarkGrey</option>
<option value="#82BC00">Green</option>
</select>
</div>
<div class="option-row">
<label for="badColor">「不充分」領域の色:</label>
<select id="badColor" style="margin: 0 20px 0 6px">
<option value="#FFFFFF">White</option>
<option value="#000000">Black</option>
<option value="#F7A711">Orange</option>
<option value="#DDDDDD">LightGrey</option>
<option value="#BBBBBB">Grey</option>
<option value="#999999" selected>DarkGrey</option>
<option value="#82BC00">Green</option>
</select>
</div>
<div class="option-row">
<label for="forecastColor"> 予測線の色:</label>
<select id="forecastColor" style="margin: 0 20px 0 6px">
<option value="#FFFFFF" selected>White</option>
<option value="#000000">Black</option>
<option value="#F7A711">Orange</option>
<option value="#DDDDDD">LightGrey</option>
<option value="#BBBBBB">Grey</option>
<option value="#999999">DarkGrey</option>
<option value="#82BC00">Green</option>
</select>
</div>
<div style="padding-top: 16px">
<input type="checkbox" id="allowMeasureOverMaxi" checked="checked"/>
<label for="allowMeasureOverMaxi">計測バーに最大値以上を許可する</label>
</div>
<div class="option-row">
<label for="barSize">バーの大きさ:</label>
<input type="text" style="margin: 0 20px 0 6px;width:120px;" id="barSize" value="0.7"/>
</div>
</div>
</div>
</body>
</html>
.sample-tutorial {
position: relative;
height: 100%;
overflow: hidden;
}
.sample-spreadsheets {
width: calc(100% - 280px);
height: 100%;
overflow: hidden;
float: left;
}
.options-container {
float: right;
width: 280px;
padding: 12px;
height: 100%;
box-sizing: border-box;
background: #fbfbfb;
overflow: auto;
}
.option-row {
font-size: 14px;
padding: 5px;
margin-top: 10px;
}
label {
margin-bottom: 6px;
}
input {
padding: 4px 6px;
}
input[type=button] {
margin-top: 6px;
display: block;
}
input[type=text] {
margin-top: 6px;
margin-bottom: 6px;
}
body {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
}