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.component.ts
index.html
app.component.html
styles.css
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:
import { Component, NgModule, enableProdMode } from '@angular/core'; import { BrowserModule } from '@angular/platform-browser'; import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; import { SpreadSheetsModule } from '@mescius/spread-sheets-angular'; import GC from '@mescius/spread-sheets'; import './styles.css'; @Component({ selector: 'app-component', templateUrl: 'src/app.component.html' }) export class AppComponent { spread: GC.Spread.Sheets.Workbook; firstMarkerColor = '(none)'; buttonDisable = true; type = 0; highMarkerColor = 'Blue'; lastMarkerColor = '(none)'; lowMarkerColor = 'Blue'; negativeMarkerColor = 'Brown'; markersColor = '(none)'; axisColor = 'black'; seriesColor = '(none)'; showFirst = false; showHigh = false; showLast = false; showLow = false; showNegative = true; showMarkers = false; displayXAxis = true; hostStyle = { width: 'calc(100% - 280px)', height: '100%', overflow: 'hidden', float: 'left' }; buttonClick() { let sheet = this.spread.getActiveSheet(); sheet.suspendPaint(); let sels = sheet.getSelections(); let setting = new GC.Spread.Sheets.Sparklines.SparklineSetting(); let sparklineType = this.type; if (sels && sels.length > 0) { let sel = this.getActualRange(sels[0], sheet.getRowCount(), sheet.getColumnCount()); let sparkline = this.findSparkLine(sheet, sel); if (sparkline != null) { sparkline.setting(this.buildSparklineSettings(setting)); sparkline.sparklineType(sparklineType); } } sheet.resumePaint(); } showFirstChange(e: any) { this.showFirst = e.target.checked; } showHighChange(e: any) { this.showHigh = e.target.checked; } showLastChange(e: any) { this.showLast = e.target.checked; } showLowChange(e: any) { this.showLow = e.target.checked; } showNegativeChange(e: any) { this.showNegative = e.target.checked; } showMarkersChange(e: any) { this.showMarkers = e.target.checked; } displayXAxisChange(e: any) { this.displayXAxis = e.target.checked; } firstMarkerColorChange(e: any) { this.firstMarkerColor = e.target.value; } typeChange(e: any) { this.type = parseInt(e.target.value); } highMarkerColorChange(e: any) { this.highMarkerColor = e.target.value; } lastMarkerColorChange(e: any) { this.lastMarkerColor = e.target.value; } lowMarkerColorChange(e: any) { this.lowMarkerColor = e.target.value; } negativeMarkerColorChange(e: any) { this.negativeMarkerColor = e.target.value; } markersColorChange(e: any) { this.markersColor = e.target.value; } axisColorChange(e: any) { this.axisColor = e.target.value; } seriesColorChange(e: any) { this.seriesColor = e.target.value; } getActualRange(range: any, maxRowCount: number, maxColCount: number) { 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); } findSparkLine(sheet: GC.Spread.Sheets.Worksheet, range: any) { 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; } buildSparklineSettings(setting: any) { if (setting == null) setting = new GC.Spread.Sheets.Sparklines.SparklineSetting(); let firstMarkerColor = this.firstMarkerColor; if (firstMarkerColor != '(none)') setting.options.firstMarkerColor = firstMarkerColor; let highMarkerColor = this.highMarkerColor; if (highMarkerColor != '(none)') setting.options.highMarkerColor = highMarkerColor; let lastMarkerColor = this.lastMarkerColor; if (lastMarkerColor != '(none)') setting.options.lastMarkerColor = lastMarkerColor; let lowMarkerColor = this.lowMarkerColor; if (lowMarkerColor != '(none)') setting.options.lowMarkerColor = lowMarkerColor; let negativeMarkerColor = this.negativeMarkerColor; if (negativeMarkerColor != '(none)') setting.options.negativeColor = negativeMarkerColor; let markersColor = this.markersColor; if (markersColor != '(none)') setting.options.markersColor = markersColor; let AxisColor = this.axisColor; if (AxisColor != '(none)') setting.options.axisColor = AxisColor; let SeriesColor = this.seriesColor; if (SeriesColor != '(none)') setting.options.seriesColor = SeriesColor; setting.options.showFirst = this.showFirst; setting.options.showHigh = this.showHigh; setting.options.showLast = this.showLast; setting.options.showLow = this.showLow; setting.options.showNegative = this.showNegative; setting.options.showMarkers = this.showMarkers; setting.options.displayXAxis = this.displayXAxis; return setting; } initSpread($event: any) { this.spread = $event.spread; let self = this; let sheet = this.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 = self.spread.getActiveSheet(); let sparkline = sheet.getSparkline(sheet.getActiveRowIndex(), sheet.getActiveColumnIndex()); if (sparkline) { getSparklineSettings(sparkline); self.buttonDisable = false; } else { initSparklineSettings(); self.buttonDisable = true; } } function initSparklineSettings() { self.type = 0; self.firstMarkerColor = '(none)'; self.highMarkerColor = 'Blue'; self.lastMarkerColor = '(none)'; self.lowMarkerColor = 'Blue'; self.negativeMarkerColor = 'Brown'; self.markersColor = '(none)'; self.axisColor = 'Black'; self.seriesColor = '(none)'; self.showFirst = false; self.showHigh = false; self.showLow = false; self.showLast = false; self.showNegative = false; self.showMarkers = false; self.displayXAxis = true; } function getSparklineSettings(sparkline: any) { let setting = sparkline.setting(); self.type = sparkline.sparklineType(); self.firstMarkerColor = setting.options.firstMarkerColor; self.highMarkerColor = setting.options.highMarkerColor; self.lastMarkerColor = setting.options.lastMarkerColor; self.lowMarkerColor = setting.options.lowMarkerColor; self.negativeMarkerColor = setting.options.negativeColor; self.markersColor = setting.options.markersColor; self.axisColor = setting.options.axisColor; self.seriesColor = setting.options.seriesColor; self.showFirst = setting.options.showFirst; self.showHigh = setting.options.showHigh; self.showLow = setting.options.showLow; self.showLast = setting.options.showLast; self.showNegative = setting.options.showNegative; self.showMarkers = setting.options.showMarkers; self.displayXAxis = setting.options.displayXAxis; } } } @NgModule({ imports: [BrowserModule, SpreadSheetsModule], declarations: [AppComponent], exports: [AppComponent], bootstrap: [AppComponent] }) export class AppModule { } enableProdMode(); // Bootstrap application with hash style navigation and global services. platformBrowserDynamic().bootstrapModule(AppModule);
<!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/angular/node_modules/@mescius/spread-sheets/styles/gc.spread.sheets.excel2013white.css"> <!-- Polyfills --> <script src="$DEMOROOT$/en/angular/node_modules/core-js/client/shim.min.js"></script> <script src="$DEMOROOT$/en/angular/node_modules/zone.js/fesm2015/zone.min.js"></script> <!-- SystemJS --> <script src="$DEMOROOT$/en/angular/node_modules/systemjs/dist/system.js"></script> <script src="systemjs.config.js"></script> <script> // workaround to load 'rxjs/operators' from the rxjs bundle System.import('rxjs').then(function (m) { System.import('@angular/compiler'); System.set(SystemJS.resolveSync('rxjs/operators'), System.newModule(m.operators)); System.import('$DEMOROOT$/en/lib/angular/license.ts'); System.import('./src/app.component'); }); </script> </head> <body> <app-component></app-component> </body> </html>
<div class="sample-tutorial"> <gc-spread-sheets [hostStyle]="hostStyle" (workbookInitialized)="initSpread($event)"> <gc-worksheet> </gc-worksheet> </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] = "buttonDisable" value='Change Settings' (click) = "buttonClick($event)"/> </div> </div> <div class="option-row"> <div class="option"> <input [checked]="showFirst" id='showFirst' type='checkbox' (change) = "showFirstChange($event)"/> <label for="showFirst">showFirst</label> </div> <div class="option"> <input [checked]="showHigh" id='showHigh' type='checkbox' (change) = "showHighChange($event)"/> <label for="showHigh">showHigh</label> </div> <div class="option"> <input id='showLast' type='checkbox' [checked]="showLast" (change) = "showLastChange($event)"/> <label for="showLast">showLast</label> </div> <div class="option"> <input id='showLow' type='checkbox' [checked]="showLow" (change) = "showLowChange($event)"/> <label for="showLow">showLow</label> </div> <div class="option"> <input id='showNegative' type='checkbox' [checked]="showNegative" (change) = "showNegativeChange($event)"/> <label for="showNegative">showNegative</label> </div> <div class="option"> <input id='showMarkers' type='checkbox' [checked]="showMarkers" (change) = "showMarkersChange($event)"/> <label for="showMarkers">showMarkers</label> </div> <div class="option"> <input id="displayXAxis" type="checkbox" [checked]="displayXAxis" (change) = "displayXAxisChange($event)"/> <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" [value]="firstMarkerColor" (change) = "firstMarkerColorChange($event)"/> </div> <div class="option"> <label for="sparklinetype" class="block">Type:</label> <select id="sparklinetype" class="control" [value] = "type" (change) = "typeChange($event)"> <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" [value]="highMarkerColor" (change) = "highMarkerColorChange($event)"/> </div> <div class="option"> <label for="lastMarkerColor" class="block">Last Marker Color</label> <input id='lastMarkerColor' class="control" [value]="lastMarkerColor" (change) = "lastMarkerColorChange($event)"/> </div> <div class="option"> <label for="lowMarkerColor" class="block">Low Marker Color</label> <input id='lowMarkerColor' class="control" [value]="lowMarkerColor" (change) = "lowMarkerColorChange($event)"/> </div> <div class="option"> <label for="negativeMarkerColor" class="block">Negative Marker Color</label> <input id='negativeMarkerColor' class="control" [value]="negativeMarkerColor" (change) = "negativeMarkerColorChange($event)"/> </div> <div class="option"> <label for="markersColor" class="block">Markers Color</label> <input id='markersColor' class="control" [value]="markersColor" (change) = "markersColorChange($event)"/> </div> <div class="option"> <label for="AxisColor" class="block">Axis Color</label> <input id='AxisColor' class="control" [value]="axisColor" (change) = "axisColorChange($event)"/> </div> <div class="option"> <label for="SeriesColor" class="block">SeriesColor</label> <input id='SeriesColor' class="control" [value]="seriesColor" (change) = "seriesColorChange($event)"/> </div> </div> </div> </div>
.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; }
(function (global) { System.config({ transpiler: 'ts', typescriptOptions: { tsconfig: true }, meta: { 'typescript': { "exports": "ts" }, '*.css': { loader: 'css' } }, paths: { // paths serve as alias 'npm:': 'node_modules/' }, // map tells the System loader where to look for things map: { 'core-js': 'npm:core-js/client/shim.min.js', 'zone': 'npm:zone.js/fesm2015/zone.min.js', 'rxjs': 'npm:rxjs/dist/bundles/rxjs.umd.min.js', '@angular/core': 'npm:@angular/core/fesm2022', '@angular/common': 'npm:@angular/common/fesm2022/common.mjs', '@angular/compiler': 'npm:@angular/compiler/fesm2022/compiler.mjs', '@angular/platform-browser': 'npm:@angular/platform-browser/fesm2022/platform-browser.mjs', '@angular/platform-browser-dynamic': 'npm:@angular/platform-browser-dynamic/fesm2022/platform-browser-dynamic.mjs', '@angular/common/http': 'npm:@angular/common/fesm2022/http.mjs', '@angular/router': 'npm:@angular/router/fesm2022/router.mjs', '@angular/forms': 'npm:@angular/forms/fesm2022/forms.mjs', 'jszip': 'npm:jszip/dist/jszip.min.js', 'typescript': 'npm:typescript/lib/typescript.js', 'ts': './plugin.js', 'tslib':'npm:tslib/tslib.js', 'css': 'npm:systemjs-plugin-css/css.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-angular': 'npm:@mescius/spread-sheets-angular/fesm2020/mescius-spread-sheets-angular.mjs', '@grapecity/jsob-test-dependency-package/react-components': 'npm:@grapecity/jsob-test-dependency-package/react-components/index.js' }, // packages tells the System loader how to load when no filename and/or no extension packages: { src: { defaultExtension: 'ts' }, rxjs: { defaultExtension: 'js' }, "node_modules": { defaultExtension: 'js' }, "node_modules/@angular": { defaultExtension: 'mjs' }, "@mescius/spread-sheets-angular": { defaultExtension: 'mjs' }, '@angular/core': { defaultExtension: 'mjs', main: 'core.mjs' } } }); })(this);