A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.ag-grid.com/javascript-data-grid/sparklines-points-of-interest/ below:

JavaScript Grid: Sparklines - Points of Interest

This section covers customisation of Sparkline Points of Interest.

Some data points in the sparklines are special and can be emphasised to allow for quick identification and comparisons across the values of a single sparkline or across multiple sparklines of the same type. These include:

First and last

Minimum and Maximum

Negative and positive

These special points can be customised via the styler callback function to make them stand out from the rest of the data points which are using the global styles.

Below are some examples demonstrating the different formatters for the three sparkline types:

Line and Area Sparklines Points of Interest Copy Link

In the line and area sparklines, each data point is represented by a marker. To customise the points of interest, the styler function is added to the marker options:

sparklineOptions: {
    marker: {
        enabled: true,
        itemStyler: (params: AgSeriesMarkerStylerParams): AgSeriesMarkerStyle => ..., 
    },
}

The itemStyler callback function will receive an input parameter of type AgSeriesMarkerStylerParams.

The function return type should be AgSeriesMarkerStyle, allowing the following attributes to be customised:

The following sections outline how the attributes mentioned above can be customised for various special points of interest:

First and Last Copy Link

Let's say we have a line sparkline where the markers are all 'skyblue' but we want to make the first and last markers stand out with a purple fill and stroke style.

We can do this by adding the following styler to the marker options.

const itemStyler = (params: AgSeriesMarkerStylerParams): AgSeriesMarkerStyle => {
    const { first, last } = params;

    return {
        size: first || last ? 5 : 3,
        fill: first || last ? '#9a60b4' : 'skyblue',
        stroke: first || last ? '#9a60b4' : 'skyblue'
    }
}

See the result of adding this styler in the sparklines on the right below, compared with the ones on the left which are using global styles in marker options:

Global marker styles

Formatted first and last points

Global marker styles

Formatted first and last points

Min and Max Copy Link

Similar to first and last, to emphasise the min and max data points, the min and max booleans from the styler params can be used to conditionally style the markers.

const itemStyler = (params: AgSeriesMarkerStylerParams): AgSeriesMarkerStyle => {
    const { min, max } = params;

    return {
        size: min || max ? 5 : 3,
        fill: min ? '#ee6666' : max ? '#3ba272' : 'skyBlue',
        stroke: min ? '#ee6666' : max ? '#3ba272' : 'skyBlue',
    }
}

See the result of adding this styler in the sparklines on the right below, compared with the ones on the left which are using global styles in marker options:

Global marker styles

Formatted min and max points

Global marker styles

Formatted min and max points

Positive and Negative Copy Link

The positive and negative values can be distinguished by adding a styler which returns styles based on the yValue of the data point.

This is demonstrated in the snippet below.

const itemStyler = (params: AgSeriesMarkerStylerParams): AgSeriesMarkerStyle => {
    const { yValue } = params;

    return {
        
        fill: yValue < 0 ? 'red' : 'green',
        stroke: yValue < 0 ? 'red' : 'green'
    }
}

See the result of adding this styler in the sparklines on the right below, compared with the ones on the left which are using global styles in marker options:

Global marker styles

Formatted positive and negative points

Global marker styles

Formatted positive and negative points

Column And Bar Sparklines Points of Interest Copy Link

Bar sparklines are just transposed column sparklines and have the same configuration. This section only covers column sparkline examples but the same applies for bar sparklines.

In the column sparklines, each data point is represented by a rectangle/ column. The styler callback function applies to the individual columns and is added to sparklineOptions:

sparklineOptions: {
    type: 'bar',
    direction: 'vertical',
    itemStyler: columnFormatter, 
}

The itemStyler will receive an input parameter with values associated with the data point it represents. The input parameter type is columnFormatterParams.

The function return type should be ItemStylerFormat, allowing these attributes to be customised:

The following sections outline how the attributes mentioned above can be customised for various special points of interest:

First and Last Copy Link

Let's say we want to make the first and last columns in our column sparklines stand out by styling them differently to the rest of the columns.

We can do this by adding the following styler to the sparklineOptions.

const itemStyler = (params: AgSeriesMarkerStylerParams): AgSeriesMarkerStyle => {
    const { first, last } = params;

    return {
        fill: first || last ? '#ea7ccc' : 'skyblue',
        stroke: first || last ? '#ea7ccc' : 'skyblue'
    }
}

Here is the result of adding this styler compared with setting global styles in sparklineOptions:

Global column styles

Formatted first and last points

Min and Max Copy Link

Similar to first and last, to emphasise the min and max data points, the min and max booleans from the styler params can be used to conditionally style the markers.

const itemStyler = (params: AgSeriesMarkerStylerParams): AgSeriesMarkerStyle => {
    const { min, max } = params;

    return {
        fill: min ? '#ee6666' : max ? '#3ba272' : 'skyBlue',
        stroke: min ? '#ee6666' : max ? '#3ba272' : 'skyBlue',
    }
}

Here is the result of adding this styler compared with setting global styles in sparklineOptions:

Global column styles

Formatted minimum and maximum points

Positive and Negative Copy Link

The positive and negative values can be distinguished by adding a styler which returns styles based on the yValue of the data point.

This is demonstrated in the snippet below.

const columnFormatter = (params: AgSeriesMarkerStylerParams): AgSeriesMarkerStyle => {
    const { yValue } = params;

    return {
        
        fill: yValue < 0 ? '#a90000' : '#5470c6',
        stroke: yValue < 0 ? '#a90000' : '#5470c6'
    }
}

Here is the result of adding this styler compared with setting global styles in sparklineOptions:

Global column styles

Formatted positive and negative points

Example: Points of Interest Copy Link

The example below shows formatting of special points for line, area and column sparklines.

It should be noted that

Next Up Copy Link

Continue to the next section to learn about Sparkline API.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4