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)
<template> <div class="sample-tutorial"> <gc-spread-sheets class="sample-spreadsheets" @workbookInitialized="initSpread" :newTabVisible=false> <gc-worksheet></gc-worksheet> <gc-worksheet></gc-worksheet> </gc-spread-sheets> <div class="options-container"> <div> <label><b>Settings:</b></label> </div> <hr> <div class="option-row"> <label for="scheme">Color Scheme:</label> <select id="scheme" v-model="colorScheme" v-on:change="applyChanges" 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="measure">Measure Color:</label> <select id="measure" v-model="measureColor" v-on:change="applyChanges" 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="target">Target Color:</label> <select id="target" v-model="targetColor" v-on:change="applyChanges" 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="maxi">Maximum Color:</label> <select id="maxi" v-model="maxiColor" v-on:change="applyChanges" 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="optimist">Optimist Color:</label> <select id="optimist" v-model="goodColor" v-on:change="applyChanges" 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="pessimist">Pessimist Color:</label> <select id="pessimist" v-model="badColor" v-on:change="applyChanges" 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="forecast">Forecast Color:</label> <select id="forecast" v-model="forecastColor" v-on:change="applyChanges" 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="allowMeasure" v-model="allowMeasureOverMaxi" v-on:change="applyChanges" checked="checked" /> <label for="allowMeasure">Allow Measure Over Max</label> </div> <div class="option-row"> <label for="size">Bar Size:</label> <input type="text" style="margin: 0 20px 0 6px;width:120px;" id="size" v-model="barSize" v-on:change="applyChanges" /> </div> </div> </div> </template> <script setup> import { ref } from "vue"; import GC from "@mescius/spread-sheets"; import '@mescius/spread-sheets-vue' const spreadRef = ref(null); let colorScheme = '#FFFFFF'; let measureColor = '#000000'; let targetColor = '#F7A711'; let maxiColor = '#DDDDDD'; let goodColor = '#BBBBBB'; let badColor = '#999999'; let forecastColor = '#FFFFFF'; let allowMeasureOverMaxi = true; let barSize = '0.7'; let initHorizontalSparkline = function (sheet, name) { sheet.suspendPaint(); sheet.name(name); let spreadNS = GC.Spread.Sheets; 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(); } let initVerticalSparkline = function (sheet, name) { sheet.suspendPaint(); sheet.name(name); let spreadNS = GC.Spread.Sheets; 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(); } let applyChanges = function () { var spread = spreadRef.value; let sheet = spread.getActiveSheet(); sheet.suspendPaint(); 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,"' + colorScheme + '",false,"' + measureColor + '","' + targetColor + '","' + maxiColor + '","' + goodColor + '","' + badColor + '","' + forecastColor + '",' + allowMeasureOverMaxi + ',' + barSize); } } else { 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,"' + colorScheme + '",true,"' + measureColor + '","' + targetColor + '","' + maxiColor + '","' + goodColor + '","' + badColor + '","' + forecastColor + '",' + allowMeasureOverMaxi + ',' + barSize); } } sheet.resumePaint(); } let initSpread = function (spread) { spreadRef.value = spread; initHorizontalSparkline(spread.sheets[0], "Horizontal"); initVerticalSparkline(spread.sheets[1], "Vertical"); } </script> <style scoped> #app { height: 100%; } .sample { position: relative; height: 100%; overflow: auto; } .sample::after { display: block; content: ""; clear: both; } .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; } .option-group { margin-bottom: 6px; } label { display: inline-block; min-width: 90px; margin-bottom: 6px; } select { padding: 4px 6px; box-sizing: border-box; } body { position: absolute; top: 0; bottom: 0; left: 0; right: 0; } </style>
<!DOCTYPE html> <html style="height:100%;font-size:14px;"> <head> <meta charset="utf-8" /> <meta http-equiv="X-UA-Compatible" content="IE=edge" /> <title>SpreadJS VUE</title> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <link rel="stylesheet" type="text/css" href="$DEMOROOT$/en/vue3/node_modules/@mescius/spread-sheets/styles/gc.spread.sheets.excel2013white.css"> <script src="$DEMOROOT$/en/vue3/node_modules/systemjs/dist/system.src.js"></script> <script src="./systemjs.config.js"></script> <script src="./compiler.js" type="module"></script> <script> var System = SystemJS; System.import("./src/app.js"); System.import('$DEMOROOT$/en/lib/vue3/license.js'); </script> </head> <body> <div id="app"></div> </body> </html>
(function (global) { SystemJS.config({ transpiler: 'plugin-babel', babelOptions: { es2015: true }, paths: { // paths serve as alias 'npm:': 'node_modules/' }, packageConfigPaths: [ './node_modules/*/package.json', "./node_modules/@mescius/*/package.json", "./node_modules/@babel/*/package.json", "./node_modules/@vue/*/package.json" ], map: { 'vue': "npm:vue/dist/vue.esm-browser.js", 'tiny-emitter': 'npm:tiny-emitter/index.js', 'plugin-babel': 'npm:systemjs-plugin-babel/plugin-babel.js', "systemjs-babel-build": "npm:systemjs-plugin-babel/systemjs-babel-browser.js", '@mescius/spread-sheets': 'npm:@mescius/spread-sheets/index.js', '@mescius/spread-sheets-vue': 'npm:@mescius/spread-sheets-vue/index.js' }, meta: { '*.css': { loader: 'systemjs-plugin-css' }, '*.vue': { loader: "../plugin-vue/index.js" } } }); })(this);