[]
        
(Showing Draft Content)

GC.Spread.Sheets.ConditionalFormatting.SparklineRule

Class: SparklineRule

Sheets.ConditionalFormatting.SparklineRule

Hierarchy

Table of contents

Constructors

Methods

Constructors

constructor

new SparklineRule(type, sparklineOptions?, ranges?)

Represents a sparkline rule that renders sparkline charts in cells based on conditional formatting.

example

// Example 1: Create an HBar sparkline rule using options object
activeSheet.setArray(0, 0, [[0.2], [0.5], [0.75], [1.0], [0.6]]);
var rule = new GC.Spread.Sheets.ConditionalFormatting.SparklineRule('HBARSPARKLINE', {
    value: '@',
    colorScheme: 'green'
}, [new GC.Spread.Sheets.Range(0, 0, 5, 1)]);
activeSheet.conditionalFormats.addRule(rule);

// Example 2: Create a YEARSPARKLINE rule using positional array arguments
// This generates: =YEARSPARKLINE(2026, A2:B13, , , "#979797", "#f3f3f3")
// Simulate activity peaks across the year with busier summer and fall periods.
activeSheet.setArray(1, 0, [
    [new Date(2026, 0, 5), 2],
    [new Date(2026, 1, 14), 3],
    [new Date(2026, 2, 27), 4],
    [new Date(2026, 3, 10), 6],
    [new Date(2026, 4, 22), 5],
    [new Date(2026, 5, 18), 8],
    [new Date(2026, 6, 9), 7],
    [new Date(2026, 7, 25), 6],
    [new Date(2026, 8, 16), 9],
    [new Date(2026, 9, 28), 10],
    [new Date(2026, 10, 11), 7],
    [new Date(2026, 11, 20), 4]
]);
var rule2 = new GC.Spread.Sheets.ConditionalFormatting.SparklineRule('YEARSPARKLINE',
    [2026, 'A2:B13', undefined, undefined, '#979797', '#f3f3f3'],
    [new GC.Spread.Sheets.Range(0, 0, 1, 1)]);
activeSheet.conditionalFormats.addRule(rule2);

Parameters

Name Type Description
type SparklineExType The sparkline function name (e.g., 'PIESPARKLINE', 'BULLETSPARKLINE', 'HBARSPARKLINE', or a custom sparkline function name).
sparklineOptions? ISparklineOptions | SparklineParameterType[] -
ranges? Range[] -

Overrides

ConditionRuleBase.constructor

Methods

condition

condition(value?): any

Gets or sets the base condition of the rule.

Parameters

Name Type Description
value? Condition The base condition of the rule.

Returns

any

If no value is set, returns the base condition of the rule; otherwise, returns the condition rule.

Inherited from

ConditionRuleBase.condition


contains

contains(row, column): boolean

Determines whether the range of cells contains the cell at the specified row and column.

Parameters

Name Type Description
row number The row index.
column number The column index.

Returns

boolean

true if the range of cells contains the cell at the specified row and column; otherwise, false.

Inherited from

ConditionRuleBase.contains


createCondition

createCondition(): Condition

Creates condition for the rule.

example

var rule = new GC.Spread.Sheets.ConditionalFormatting.NormalConditionRule();
rule.ruleType(GC.Spread.Sheets.ConditionalFormatting.RuleType.formulaRule);
rule.formula("=A1=B1+C1");
var condition = rule.createCondition();
console.log(condition.evaluate(activeSheet));

Returns

Condition

The condition.

Inherited from

ConditionRuleBase.createCondition


evaluate

evaluate(evaluator, baseRow, baseColumn, actual): any

Returns the sparkline value of the rule if the cell is within the rule's ranges.

example

var rule = new GC.Spread.Sheets.ConditionalFormatting.SparklineRule('HBARSPARKLINE', {value: '@'}, [new GC.Spread.Sheets.Range(0, 0, 5, 1)]);
activeSheet.setArray(0, 0, [[0.2], [0.5], [0.75], [1.0], [0.6]]);
activeSheet.conditionalFormats.addRule(rule);
var result = rule.evaluate(activeSheet, 0, 0, 0.5);
console.log(result);

Parameters

Name Type Description
evaluator Object The evaluator (worksheet).
baseRow number The row index.
baseColumn number The column index.
actual Object The actual cell value.

Returns

any

The value object if the cell is in range; otherwise, null.

Overrides

ConditionRuleBase.evaluate


getExpected

getExpected(): Style

Gets the style of the base rule.

example

 //This example uses the getExpected method.
 activeSheet.suspendPaint();
 var style = new GC.Spread.Sheets.Style();
 style.backColor = "green";
 var ranges = [new GC.Spread.Sheets.Range(0, 0, 10, 1)];
 activeSheet.conditionalFormats.addUniqueRule(style, ranges);
 var data = [50, 50, 11, 5, 3, 6, 7, 8, 7, 11];
 var condition = activeSheet.conditionalFormats.getRules()[0];
 for (var i = 0; i < 10;i++){
     activeSheet.setValue(i, 0, data[i]);
 }
 activeSheet.resumePaint();
 console.log(condition.getExpected());

Returns

Style

Inherited from

ConditionRuleBase.getExpected


intersects

intersects(row, column, rowCount, columnCount): boolean

Specifies whether the range for this rule intersects another range.

example

 //This example uses the intersects method.
 activeSheet.suspendPaint();
 var style = new GC.Spread.Sheets.Style();
 style.backColor = "green";
 var ranges = [new GC.Spread.Sheets.Range(0, 0, 10, 1)];
 activeSheet.conditionalFormats.addUniqueRule(style, ranges);
 var data = [50, 50, 11, 5, 3, 6, 7, 8, 7, 11];
 var condition = activeSheet.conditionalFormats.getRules()[0];
 for (var i = 0; i < 10; i++) {
     activeSheet.setValue(i, 0, data[i]);
 }
 activeSheet.resumePaint();
 activeSheet.bind(GC.Spread.Sheets.Events.SelectionChanged, function(e, info) {
     var selection = info.newSelections[0];
     var result = condition.intersects(selection.row, selection.col, selection.rowCount, selection.colCount);
     if (result) {
         alert("current selection is intersects with condition formatting range");
     } else {
         alert("current selection is not intersects with condition formatting range");
     }
 });

Parameters

Name Type Description
row number The row index.
column number The column index.
rowCount number The number of rows.
columnCount number The number of columns.

Returns

boolean

true if the range for this rule intersects another range; otherwise, false.

Inherited from

ConditionRuleBase.intersects


isScaleRule

isScaleRule(): boolean

Specifies whether this rule is a scale rule.

Returns

boolean

true if this rule is a scale rule; otherwise, false.

Inherited from

ConditionRuleBase.isScaleRule


priority

priority(value?): any

Gets or sets the priority of the rule.

example

// Example: Create multiple rules with different priorities
var style = new GC.Spread.Sheets.Style();
style.backColor = "red";
var rule = new GC.Spread.Sheets.ConditionalFormatting.NormalConditionRule();
rule.ruleType(GC.Spread.Sheets.ConditionalFormatting.RuleType.cellValueRule);
rule.operator(GC.Spread.Sheets.ConditionalFormatting.ComparisonOperators.greaterThan);
rule.value1(10);
rule.ranges([new GC.Spread.Sheets.Range(0, 0, 10, 1)]);
rule.style(style);
rule.priority(1); // Set priority to 1 (highest priority)
activeSheet.conditionalFormats.addRule(rule);
var style2 = new GC.Spread.Sheets.Style();
style2.backColor = "blue";
var rule2 = new GC.Spread.Sheets.ConditionalFormatting.NormalConditionRule();
rule2.ruleType(GC.Spread.Sheets.ConditionalFormatting.RuleType.cellValueRule);
rule2.operator(GC.Spread.Sheets.ConditionalFormatting.ComparisonOperators.greaterThan);
rule2.value1(100);
rule2.ranges([new GC.Spread.Sheets.Range(5, 0, 10, 1)]);
rule2.style(style2);
rule2.priority(2); // Set priority to 1 (highest priority)
activeSheet.conditionalFormats.addRule(rule2);

Parameters

Name Type Description
value? number The priority of the rule.

Returns

any

If no value is set, returns the priority of the rule; otherwise, returns the condition rule.

Inherited from

ConditionRuleBase.priority


ranges

ranges(value?): any

Gets or sets the condition rule ranges.

example

var style = new GC.Spread.Sheets.Style();
style.backColor = "green";
var ranges = [new GC.Spread.Sheets.Range(0, 0, 10, 1)];
activeSheet.conditionalFormats.addUniqueRule(style, ranges);
activeSheet.setValue(0, 0, 50);
activeSheet.setValue(1, 0, 50);
activeSheet.setValue(2, 0, 11);
activeSheet.setValue(3, 0, 5);

Parameters

Name Type Description
value? Range[] The condition rule ranges.

Returns

any

If no value is set, returns a copy of the condition rule ranges; otherwise, returns the condition rule.

Inherited from

ConditionRuleBase.ranges


reset

reset(): void

Resets the rule to its default state.

example

activeSheet.setArray(0, 0, [[0.2], [0.5], [0.75], [1.0], [0.6], [0.25], [0.35], [0.15], [0.45], [0.3]]);
var rule = new GC.Spread.Sheets.ConditionalFormatting.SparklineRule('HBARSPARKLINE', {value: '@'}, [new GC.Spread.Sheets.Range(0, 0, 5, 1)]);
activeSheet.conditionalFormats.addRule(rule);
rule.reset();
rule.sparklineOptions({
   value: '@',
   colorScheme: 'blue'
});
rule.ranges([new GC.Spread.Sheets.Range(0, 0, 10, 1)]);
activeSheet.refresh();

Returns

void

Overrides

ConditionRuleBase.reset


ruleType

ruleType(value?): any

Gets or sets the condition rule type.

example

//This example uses the ruleType method.
activeSheet.setArray(0,0,[1,2,3,4,5,6,7,8,9,10]);
var style = new GC.Spread.Sheets.Style();
style.backColor = "red";
style.foreColor = "black";
var cell = new GC.Spread.Sheets.ConditionalFormatting.NormalConditionRule();
cell.ruleType(GC.Spread.Sheets.ConditionalFormatting.RuleType.cellValueRule);
cell.operator(GC.Spread.Sheets.ConditionalFormatting.ComparisonOperators.greaterThan);
cell.value1(5);
cell.ranges([new GC.Spread.Sheets.Range(0, 0, 10, 1)]);
cell.style(style);
activeSheet.conditionalFormats.addRule(cell);
var style1 = new GC.Spread.Sheets.Style();
style1.foreColor = "red";
var topRule = new GC.Spread.Sheets.ConditionalFormatting.NormalConditionRule();
topRule.ruleType(GC.Spread.Sheets.ConditionalFormatting.RuleType.top10Rule);
topRule.type(GC.Spread.Sheets.ConditionalFormatting.Top10ConditionType.top);
topRule.rank(3);
topRule.style(style1);
topRule.ranges([new GC.Spread.Sheets.Range(0, 0, 10, 1)]);
topRule.stopIfTrue(true);
activeSheet.conditionalFormats.addRule(topRule);

Parameters

Name Type Description
value? RuleType The condition rule type.

Returns

any

If no value is set, returns the condition rule type; otherwise, returns the condition rule.

Inherited from

ConditionRuleBase.ruleType


showSparklineOnly

showSparklineOnly(value?): any

Gets or sets whether to display the sparkline without cell text.

example

//This example uses the showSparklineOnly method.
activeSheet.setValue(0, 0, 50);
activeSheet.setValue(1, 0, 75);
activeSheet.setValue(2, 0, 25);
var sparklineRule = new GC.Spread.Sheets.ConditionalFormatting.SparklineRule('HBARSPARKLINE', {
    value: '@',
    colorScheme: 'green'
}, [new GC.Spread.Sheets.Range(0, 0, 3, 1)]);
sparklineRule.showSparklineOnly(true);
activeSheet.conditionalFormats.addRule(sparklineRule);

Parameters

Name Type Description
value? boolean Whether to display the sparkline without cell text.

Returns

any

If no value is set, returns whether the widget displays the sparkline without cell text; otherwise, returns the sparkline rule.


sparklineOptions

sparklineOptions(value?): any

Gets or sets the sparkline options.

example

// Example 1: Using options object
activeSheet.setArray(0, 0, [[0.2], [0.3], [0.5], [0.1], [0.4], [0.25], [0.35], [0.15], [0.45], [0.3]]);
var rule = new GC.Spread.Sheets.ConditionalFormatting.SparklineRule('PIESPARKLINE', {
    value: '@',
    colors: ['red', 'green', 'blue']
}, [new GC.Spread.Sheets.Range(0, 0, 10, 1)]);
activeSheet.conditionalFormats.addRule(rule);
console.log(rule.sparklineOptions()); // { value: '@', colors: ['red', 'green', 'blue'] }

// Example 2: Using positional array arguments
rule.sparklineOptions(['@', 'skyblue', 'orange', 'lightgray']);
activeSheet.refresh();

Parameters

Name Type
value? ISparklineOptions | SparklineParameterType[]

Returns

any

If no value is set, returns the sparkline options; otherwise, returns the sparkline rule.


sparklineType

sparklineType(): SparklineExType

Gets the sparkline function type name.

example

activeSheet.setArray(0, 0, [[0.2], [0.5], [0.75], [1.0], [0.6]]);
var rule = new GC.Spread.Sheets.ConditionalFormatting.SparklineRule('HBARSPARKLINE', {value: '@'}, [new GC.Spread.Sheets.Range(0, 0, 5, 1)]);
activeSheet.conditionalFormats.addRule(rule);
console.log(rule.sparklineType()); // 'HBARSPARKLINE'

Returns

SparklineExType

The sparkline type name (e.g., 'PIESPARKLINE').


stopIfTrue

stopIfTrue(value?): any

Gets or sets whether rules with lower priority are applied before this rule.

example

//This example applies multiple rules.
activeSheet.setArray(0,0,[1,2,3,4,5,6,7,8,9,10]);
var style = new GC.Spread.Sheets.Style();
style.backColor = "red";
style.foreColor = "black";
var cell = new GC.Spread.Sheets.ConditionalFormatting.NormalConditionRule();
cell.ruleType(GC.Spread.Sheets.ConditionalFormatting.RuleType.cellValueRule);
cell.operator(GC.Spread.Sheets.ConditionalFormatting.ComparisonOperators.greaterThan);
cell.value1(5);
cell.ranges([new GC.Spread.Sheets.Range(0, 0, 10, 1)]);
cell.style(style);
activeSheet.conditionalFormats.addRule(cell);
var style1 = new GC.Spread.Sheets.Style();
style1.foreColor = "red";
var topRule = new GC.Spread.Sheets.ConditionalFormatting.NormalConditionRule();
topRule.ruleType(GC.Spread.Sheets.ConditionalFormatting.RuleType.top10Rule);
topRule.type(GC.Spread.Sheets.ConditionalFormatting.Top10ConditionType.top);
topRule.rank(3);
topRule.style(style1);
topRule.ranges([new GC.Spread.Sheets.Range(0, 0, 10, 1)]);
topRule.stopIfTrue(true);
activeSheet.conditionalFormats.addRule(topRule);

Parameters

Name Type Description
value? boolean Whether rules with lower priority are applied before this rule.

Returns

any

If no value is set, returns whether the rules with lower priority are not applied before this rule; otherwise, returns the condition rule.

Inherited from

ConditionRuleBase.stopIfTrue


style

style(value?): any

Gets or sets the style for the rule.

example

//This example applies multiple rules.
activeSheet.setArray(0,0,[1,2,3,4,5,6,7,8,9,10]);
var style = new GC.Spread.Sheets.Style();
style.backColor = "red";
style.foreColor = "black";
var cell = new GC.Spread.Sheets.ConditionalFormatting.NormalConditionRule();
cell.ruleType(GC.Spread.Sheets.ConditionalFormatting.RuleType.cellValueRule);
cell.operator(GC.Spread.Sheets.ConditionalFormatting.ComparisonOperators.greaterThan);
cell.value1(5);
cell.ranges([new GC.Spread.Sheets.Range(0, 0, 10, 1)]);
cell.style(style);
activeSheet.conditionalFormats.addRule(cell);
var style1 = new GC.Spread.Sheets.Style();
style1.foreColor = "red";
var topRule = new GC.Spread.Sheets.ConditionalFormatting.NormalConditionRule();
topRule.ruleType(GC.Spread.Sheets.ConditionalFormatting.RuleType.top10Rule);
topRule.type(GC.Spread.Sheets.ConditionalFormatting.Top10ConditionType.top);
topRule.rank(3);
topRule.style(style1);
topRule.ranges([new GC.Spread.Sheets.Range(0, 0, 10, 1)]);
topRule.stopIfTrue(true);
activeSheet.conditionalFormats.addRule(topRule);

Parameters

Name Type Description
value? Style The style for the rule.

Returns

any

If no value is set, returns the style for the rule; otherwise, returns the condition rule.

Inherited from

ConditionRuleBase.style