Settings

SpreadJS allows you to have flexible sparkline settings. You can control which value points are shown (such as high, low, first, last, or any negative values), change the type of the sparkline (Line, Column, or WinLoss), apply styles, and control whether to show the horizontal axis.

Description
app.vue
index.html
Copy to CodeMine

You can highlight individual data markers (values) in a line sparkline by making some or all of the markers visible.

  • showFirst: whether the first data point is formatted differently for each sparkline in this sparkline group
  • showHigh: whether the data points with the highest value are formatted differently for each sparkline in this sparkline group
  • showLast: whether the last data point is formatted differently for each sparkline in this sparkline group
  • showLow: whether the data points with the lowest value are formatted differently for each sparkline in this sparkline group
  • showNegative: whether the negative data points are formatted differently for each sparkline in this sparkline group
  • showMarkers: whether data markers are displayed for each sparkline in this sparkline group

You can change the style and format of sparklines using the following methods:

  • axisColor: the color of the axis*
  • firstMarkerColor: the color of the first data point for each sparkline in this sparkline group
  • highMarkerColor: the color of the highest data point for each sparkline in this sparkline group
  • lastMarkerColor: the color of the last data point for each sparkline in this sparkline group
  • lowMarkerColor: the color of the lowest data point for each sparkline in this sparkline group
  • markersColor: the color of the data markers for each sparkline in this sparkline group
  • negativeColor: the color of the negative data points for each sparkline in this sparkline group
  • seriesColor: the color for each sparkline in this sparkline group

Sparklines offer additional settings. For example, sometimes there are empty values in the data series in the chart. You can use the displayEmptyCellsAs option to control how to display the empty cells, as shown in the following example:

    var setting = new GC.Spread.Sheets.Sparklines.SparklineSetting();
    setting.options.displayEmptyCellsAs = GC.Spread.Sheets.Sparklines.EmptyValueStyle.gaps;
    setting.options.rightToLeft = true;
    setting.options.displayHidden = false;
    setting.options.displayXAxis = false
    setting.options.lineWeight = 2;
    setting.options.manualMax = 3;
    setting.options.manualMin = 1;
    setting.options.markersColor = 'Magenta';
    setting.options.maxAxisType = GC.Spread.Sheets.Sparklines.SparklineAxisMinMax.custom;
    setting.options.minAxisType = GC.Spread.Sheets.Sparklines.SparklineAxisMinMax.individual;

The following example illustrates how to apply these settings:

    var setting = new GC.Spread.Sheets.Sparklines.SparklineSetting();
    setting.options.showFirst = true;
    setting.options.showHigh = true;
    setting.options.displayXAxis = true;
    setting.options.axisColor = 'Cyan';
    var sparkline = sheet.getSparkline(11, 0);
    sparkline.setting(setting);
You can highlight individual data markers (values) in a line sparkline by making some or all of the markers visible. showFirst: whether the first data point is formatted differently for each sparkline in this sparkline group showHigh: whether the data points with the highest value are formatted differently for each sparkline in this sparkline group showLast: whether the last data point is formatted differently for each sparkline in this sparkline group showLow: whether the data points with the lowest value are formatted differently for each sparkline in this sparkline group showNegative: whether the negative data points are formatted differently for each sparkline in this sparkline group showMarkers: whether data markers are displayed for each sparkline in this sparkline group You can change the style and format of sparklines using the following methods: axisColor: the color of the axis* firstMarkerColor: the color of the first data point for each sparkline in this sparkline group highMarkerColor: the color of the highest data point for each sparkline in this sparkline group lastMarkerColor: the color of the last data point for each sparkline in this sparkline group lowMarkerColor: the color of the lowest data point for each sparkline in this sparkline group markersColor: the color of the data markers for each sparkline in this sparkline group negativeColor: the color of the negative data points for each sparkline in this sparkline group seriesColor: the color for each sparkline in this sparkline group Sparklines offer additional settings. For example, sometimes there are empty values in the data series in the chart. You can use the displayEmptyCellsAs option to control how to display the empty cells, as shown in the following example: The following example illustrates how to apply these settings:
<template> <div class="sample-tutorial"> <gc-spread-sheets class="sample-spreadsheets" @workbookInitialized="initSpread"> </gc-spread-sheets> <div class="options-container"> <div class="option-row"> <label>*Select a sparkline in the spreadsheet then change its properties</label> </div> <div class="option-row"> <div class="option"> <input id='btnChangeSetting' type='button' :disabled="buttonDisableRef" value='Change Setting' v-on:click="buttonClick" /> </div> </div> <div class="option-row"> <div class="option"> <input v-model="showFirstRef" id='showFirst' type='checkbox' v-on:change="showFirstChange" /> <label for="showFirst">showFirst</label> </div> <div class="option"> <input v-model="showHighRef" id='showHigh' type='checkbox' v-on:change="showHighChange" /> <label for="showHigh">showHigh</label> </div> <div class="option"> <input id='showLast' type='checkbox' v-model="showLastRef" v-on:change="showLastChange" /> <label for="showLast">showLast</label> </div> <div class="option"> <input id='showLow' type='checkbox' v-model="showLowRef" v-on:change="showLowChange" /> <label for="showLow">showLow</label> </div> <div class="option"> <input id='showNegative' type='checkbox' v-model="showNegativeRef" v-on:change="showNegativeChange" /> <label for="showNegative">showNegative</label> </div> <div class="option"> <input id='showMarkers' type='checkbox' v-model="showMarkersRef" v-on:change="showMarkersChange" /> <label for="showMarkers">showMarkers</label> </div> <div class="option"> <input id="displayXAxis" type="checkbox" v-model="displayXAxisRef" v-on:change="displayXAxisChange" /> <label for="displayXAxis">displayXAxis</label> </div> </div> <div class="option-row"> <div class="option"> <label for="firstMarkerColor" class="block">First Marker Color</label> <input id='firstMarkerColor' class="control" v-model="firstMarkerColorRef" v-on:change="firstMarkerColorChange" /> </div> <div class="option"> <label for="sparklinetype" class="block">Type:</label> <select id="sparklinetype" class="control" v-model="typeRef" v-on:change="typeChange"> <option value="0">line</option> <option value="1">column</option> <option value="2">winloss</option> </select> </div> <div class="option"> <label for="highMarkerColor" class="block">High Marker Color</label> <input id='highMarkerColor' class="control" v-model="highMarkerColorRef" v-on:change="highMarkerColorChange" /> </div> <div class="option"> <label for="lastMarkerColor" class="block">Last Marker Color</label> <input id='lastMarkerColor' class="control" v-model="lastMarkerColorRef" v-on:change="lastMarkerColorChange" /> </div> <div class="option"> <label for="lowMarkerColor" class="block">Low Marker Color</label> <input id='lowMarkerColor' class="control" v-model="lowMarkerColorRef" v-on:change="lowMarkerColorChange" /> </div> <div class="option"> <label for="negativeMarkerColor" class="block">Negative Marker Color</label> <input id='negativeMarkerColor' class="control" v-model="negativeMarkerColorRef" v-on:change="negativeMarkerColorChange" /> </div> <div class="option"> <label for="markersColor" class="block">Markers Color</label> <input id='markersColor' class="control" v-model="markersColorRef" v-on:change="markersColorChange" /> </div> <div class="option"> <label for="AxisColor" class="block">Axis Color</label> <input id='AxisColor' class="control" v-model="axisColorRef" v-on:change="axisColorChange" /> </div> <div class="option"> <label for="SeriesColor" class="block">SeriesColor</label> <input id='SeriesColor' class="control" v-model="seriesColorRef" v-on:change="seriesColorChange" /> </div> </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); const firstMarkerColorRef = ref('(none)'); const buttonDisableRef = ref(true); const typeRef = ref(0); const highMarkerColorRef = ref('Blue'); const lastMarkerColorRef = ref('(none)'); const lowMarkerColorRef = ref('Blue'); const negativeMarkerColorRef = ref('Brown'); const markersColorRef = ref('(none)'); const axisColorRef = ref('black'); const seriesColorRef = ref('(none)'); const showFirstRef = ref(false); const showHighRef = ref(false); const showLastRef = ref(false); const showLowRef = ref(false); const showNegativeRef = ref(true); const showMarkersRef = ref(false); const displayXAxisRef = ref(true); let buttonClick = function () { let sheet = spreadRef.value.getActiveSheet(); sheet.suspendPaint(); let sels = sheet.getSelections(); let setting = new GC.Spread.Sheets.Sparklines.SparklineSetting(); let sparklineType = typeRef.value; if (sels && sels.length > 0) { let sel = getActualRange(sels[0], sheet.getRowCount(), sheet.getColumnCount()); let sparkline = findSparkLine(sheet, sel); if (sparkline != null) { sparkline.setting(buildSparklineSettings(setting)); sparkline.sparklineType(sparklineType); } } sheet.resumePaint(); } let showFirstChange = function (e) { showFirstRef.value = e.target.checked; } let showHighChange = function (e) { showHighRef.value = e.target.checked; } let showLastChange = function (e) { showLastRef.value = e.target.checked; } let showLowChange = function (e) { showLowRef.value = e.target.checked; } let showNegativeChange = function (e) { showNegativeRef.value = e.target.checked; } let showMarkersChange = function (e) { showMarkersRef.value = e.target.checked; } let displayXAxisChange = function (e) { displayXAxisRef.value = e.target.checked; } let firstMarkerColorChange = function (e) { firstMarkerColorRef.value = e.target.value; } let typeChange = function (e) { typeRef.value = parseInt(e.target.value); } let highMarkerColorChange = function (e) { highMarkerColorRef.value = e.target.value; } let lastMarkerColorChange = function (e) { lastMarkerColorRef.value = e.target.value; } let lowMarkerColorChange = function (e) { lowMarkerColorRef.value = e.target.value; } let negativeMarkerColorChange = function (e) { negativeMarkerColorRef.value = e.target.value; } let markersColorChange = function (e) { markersColorRef.value = e.target.value; } let axisColorChange = function (e) { axisColorRef.value = e.target.value; } let seriesColorChange = function (e) { seriesColorRef.value = e.target.value; } let getActualRange = function (range, maxRowCount, maxColCount) { let row = range.row < 0 ? 0 : range.row; let col = range.col < 0 ? 0 : range.col; let rowCount = range.rowCount < 0 ? maxRowCount : range.rowCount; let colCount = range.colCount < 0 ? maxColCount : range.colCount; return new GC.Spread.Sheets.Range(row, col, rowCount, colCount); } let findSparkLine = function (sheet, range) { let row = range.row, col = range.col, rowCount = range.rowCount, colCount = range.colCount; for (let i = 0; i < rowCount; i++) { for (let j = 0; j < colCount; j++) { let sparkline = sheet.getSparkline(row + i, col + j); if (sparkline != null) { return sparkline; } } } return null; } let buildSparklineSettings = function (setting) { if (setting == null) setting = new GC.Spread.Sheets.Sparklines.SparklineSetting(); let firstMarkerColor = firstMarkerColorRef.value; if (firstMarkerColor != '(none)') setting.options.firstMarkerColor = firstMarkerColor; let highMarkerColor = highMarkerColorRef.value; if (highMarkerColor != '(none)') setting.options.highMarkerColor = highMarkerColor; let lastMarkerColor = lastMarkerColorRef.value; if (lastMarkerColor != '(none)') setting.options.lastMarkerColor = lastMarkerColor; let lowMarkerColor = lowMarkerColorRef.value; if (lowMarkerColor != '(none)') setting.options.lowMarkerColor = lowMarkerColor; let negativeMarkerColor = negativeMarkerColorRef.value; if (negativeMarkerColor != '(none)') setting.options.negativeColor = negativeMarkerColor; let markersColor = markersColorRef.value; if (markersColor != '(none)') setting.options.markersColor = markersColor; let AxisColor = axisColorRef.value; if (AxisColor != '(none)') setting.options.axisColor = AxisColor; let SeriesColor = seriesColorRef.value; if (SeriesColor != '(none)') setting.options.seriesColor = SeriesColor; setting.options.showFirst = showFirstRef.value; setting.options.showHigh = showHighRef.value; setting.options.showLast = showLastRef.value; setting.options.showLow = showLowRef.value; setting.options.showNegative = showNegativeRef.value; setting.options.showMarkers = showMarkersRef.value; setting.options.displayXAxis = displayXAxisRef.value; return setting; } let initSpread = function (spread) { spreadRef.value = spread; let sheet = spread.getSheet(0); sheet.suspendPaint(); sheet.options.allowCellOverflow = true; let spreadNS = GC.Spread.Sheets; var data = [1, -2, -1, 6, 4, -4, 3, 8]; var dateAxis = [new Date(2011, 0, 5), new Date(2011, 0, 1), new Date(2011, 1, 11), new Date(2011, 2, 1), new Date(2011, 1, 1), new Date(2011, 1, 3), new Date(2011, 2, 6), new Date(2011, 1, 19)]; sheet.setValue(0, 0, "Series 1"); sheet.setValue(0, 1, "Series 2"); for (let i = 0; i < 8; i++) { sheet.setValue(i + 1, 0, data[i]); sheet.getCell(i + 1, 1).value(dateAxis[i]).formatter("yyyy-mm-dd"); } sheet.setColumnWidth(1, 100); sheet.setValue(10, 0, "*Data Range is A2-A9"); sheet.setValue(11, 0, "*Date axis range is B2-B9"); var dataRange = new spreadNS.Range(1, 0, 8, 1); var dateAxisRange = new spreadNS.Range(1, 1, 8, 1); sheet.getCell(13, 0).text("Sparkline with dateAxis:"); sheet.getCell(14, 0).text("(1) Line"); sheet.getCell(14, 3).text("(2)Column"); sheet.getCell(14, 6).text("(3)Winloss"); //line sheet.addSpan(15, 0, 4, 3); var setting = new spreadNS.Sparklines.SparklineSetting(); setting.options.showMarkers = true; setting.options.displayXAxis = true; setting.options.showFirst = true; setting.options.showLast = true; setting.options.showLow = true; setting.options.showHigh = true; setting.options.showNegative = true; sheet.setSparkline(15, 0, dataRange , spreadNS.Sparklines.DataOrientation.vertical , spreadNS.Sparklines.SparklineType.line , setting , dateAxisRange , spreadNS.Sparklines.DataOrientation.vertical ); //column sheet.addSpan(15, 3, 4, 3); setting = new spreadNS.Sparklines.SparklineSetting(); setting.options.displayXAxis = true; setting.options.showFirst = true; setting.options.showLast = true; setting.options.showLow = true; setting.options.showHigh = true; setting.options.showNegative = true; sheet.setSparkline(15, 3, dataRange , spreadNS.Sparklines.DataOrientation.vertical , spreadNS.Sparklines.SparklineType.column , setting , dateAxisRange , spreadNS.Sparklines.DataOrientation.vertical ); //winloss sheet.addSpan(15, 6, 4, 3); setting = new spreadNS.Sparklines.SparklineSetting(); setting.options.displayXAxis = true; setting.options.showNegative = true; sheet.setSparkline(15, 6, dataRange , spreadNS.Sparklines.DataOrientation.vertical , spreadNS.Sparklines.SparklineType.winloss , setting , dateAxisRange , spreadNS.Sparklines.DataOrientation.vertical ); sheet.bind(GC.Spread.Sheets.Events.SelectionChanged, selectionChangedCallback); sheet.resumePaint(); function selectionChangedCallback() { let sheet = spreadRef.value.getActiveSheet(); let sparkline = sheet.getSparkline(sheet.getActiveRowIndex(), sheet.getActiveColumnIndex()); if (sparkline) { getSparklineSettings(sparkline); buttonDisableRef.value = false; } else { initSparklineSettings(); buttonDisableRef.value = true; } } function initSparklineSettings() { typeRef.value = 0; firstMarkerColorRef.value = '(none)'; highMarkerColorRef.value = 'Blue'; lastMarkerColorRef.value = '(none)'; lowMarkerColorRef.value = 'Blue'; negativeMarkerColorRef.value = 'Brown'; markersColorRef.value = '(none)'; axisColorRef.value = 'Black'; seriesColorRef.value = '(none)'; showFirstRef.value = false; showHighRef.value = false; showLowRef.value = false; showLastRef.value = false; showNegativeRef.value = false; showMarkersRef.value = false; displayXAxisRef.value = true; } function getSparklineSettings(sparkline) { let setting = sparkline.setting(); typeRef.value = sparkline.sparklineType(); firstMarkerColorRef.value = setting.options.firstMarkerColor; highMarkerColorRef.value = setting.options.highMarkerColor; lastMarkerColorRef.value = setting.options.lastMarkerColor; lowMarkerColorRef.value = setting.options.lowMarkerColor; negativeMarkerColorRef.value = setting.options.negativeColor; markersColorRef.value = setting.options.markersColor; axisColorRef.value = setting.options.axisColor; seriesColorRef.value = setting.options.seriesColor; showFirstRef.value = setting.options.showFirst; showHighRef.value = setting.options.showHigh; showLowRef.value = setting.options.showLow; showLastRef.value = setting.options.showLast; showNegativeRef.value = setting.options.showNegative; showMarkersRef.value = setting.options.showMarkers; displayXAxisRef.value = setting.options.displayXAxis; } } </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 { padding-bottom: 6px; } .block { display: block; padding: 6px 0; } .control { padding: 4px 8px; box-sizing: border-box; width: 100%; } 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);