Bullet

A bullet sparkline can show a lot of data in a small amount of space, typically used when displaying performance data.

You can create a bullet sparkline using the BulletSparkline function in a formula: =BULLETSPARKLINE(measure, target, maxi, good?, bad?, forecast?, tickunit?, colorScheme?, vertical?, measureColor?, targetColor?, maxiColor?, goodColor?, badColor?, forecastColor?, allowMeasureOverMaxi?, barSize?). The function has the following parameters: measure: Number or reference that represents the length of the measure bar, such as 5 or "A1". target: Number or reference that represents the location of the target line, such as 7 or "A2". maxi: Number or reference that represents the maximum value of the sparkline, such as 10 or "A3". good: (optional) Number or reference that represents the length of the good bar, such as 3 or "A4"; default value is 0. bad: (optional) Number or reference that represents the length of the bad bar, such as 1 or "A5"; default value is 0. forecast: (optional) Number or reference that represents the length of the forecast line, such as 8 or "A6"; default value is 0. tickunit: (optional) Number or reference that represents the tick unit, such as 1 or "A7"; default value is 0. colorScheme: (optional) String that represents the color scheme for generating a group of colors to display the sparkline; default value is "#A0A0A0". vertical: (optional) Boolean that represents whether to display the sparkline vertically; default value is false. measureColor: (optional) String that represents the color of measure bar. targetColor: (optional) String that represents the color of target line. maxiColor: (optional) String that represents the maxi area color. goodColor: (optional) String that represents the good area color. badColor: (optional) String that represents the bad area color. forecastColor: (optional) String that represents the forecast line color. allowMeasureOverMaxi: (optional) Boolean that represents if the measure could exceed maxi area; default value is false. barSize: (optional) Number that represents that the percentage of bar width/height according to the cell height/ width. (value > 0 && value <= 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, 8, '=BULLETSPARKLINE($D' + (index + 1) + ','+ '$E' + (index + 1) +','+ '$F' + (index + 1) +','+ '$G' + (index + 1) + ','+ '$H' + (index + 1) + ','+ '$C' + (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, 1, [ ['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, 8, '=BULLETSPARKLINE($D' + (index + 1) + ','+ '$E' + (index + 1) +','+ '$F' + (index + 1) +','+ '$G' + (index + 1) + ','+ '$H' + (index + 1) + ','+ '$C' + (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 = 1; j < 8; j++) { sheet.setColumnWidth(j, 100); } sheet.setColumnWidth(8, 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 charset="utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <link rel="stylesheet" type="text/css" href="$DEMOROOT$/en/purejs/node_modules/@grapecity/spread-sheets/styles/gc.spread.sheets.excel2013white.css"> <script src="$DEMOROOT$/en/purejs/node_modules/@grapecity/spread-sheets/dist/gc.spread.sheets.all.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>Settings:</b></label> </div> <hr> <div class="option-row"> <label for="colorScheme">Color Scheme:</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">Measure Color:</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">Target Color:</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">Maximum Color:</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">Optimist Color:</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">Pessimist Color:</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">Forecast Color:</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">Allow Measure Over Max</label> </div> <div class="option-row"> <label for="barSize">Bar Size:</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; }