Sparkline

The Sparkline widget is a compact chart that contains only one series. Owing to their size, sparklines occupy very little space and can be easily collected in a table or embedded straight in text.

Included in: dx.viz.js, dx.viz-web.js, dx.all.js
Module: viz/sparkline
Sparkline interactive configuration
Copy Code
Copy to Codepen
$("#sparkline").dxSparkline({
});

                    

You can create the widget using one of the following approaches.

  • jQuery
    Use the dxSparkline jQuery plug-in.

    HTML
    <div id="sparklineContainer"></div>
    JavaScript
    $("#sparklineContainer").dxSparkline({
        dataSource: dataSource,
        argumentField: 'month',
        valueField: '2010',
        type: 'spline'
    });
  • Knockout
    Add a div element and apply the dxSparkline binding to this element.

    HTML
    <div data-bind="dxSparkline: {
        dataSource: dataSource,
        argumentField: 'month',
        valueField: '2010',
        type: 'spline'
    }"></div>
  • AngularJS
    Add a div element and apply the dx-sparkline directive to this element.

    HTML
    <div dx-sparkline="{
        dataSource: dataSource,
        argumentField: 'month',
        valueField: '2010',
        type: 'spline'
    }"></div>

Note that DevExtreme widgets require you to link the jQuery library to your application. If you use the Knockout or AngularJS approach, the Knockout or AngularJS library is also required. For detailed information on linking these libraries to your project, refer to the Installation article.

View Demo Watch Video

Configuration

An object that specifies configuration options for the Sparkline widget.

Name Description
argumentField

Specifies the data source field that provides arguments for a sparkline.

barNegativeColor

Sets a color for the bars indicating negative values. Available for a sparkline of the bar type only.

barPositiveColor

Sets a color for the bars indicating positive values. Available for a sparkline of the bar type only.

dataSource

Specifies a data source for the sparkline.

firstLastColor

Sets a color for the boundary of both the first and last points on a sparkline.

ignoreEmptyPoints

Specifies whether a sparkline ignores null data points or not.

lineColor

Sets a color for a line on a sparkline. Available for the sparklines of the line- and area-like types.

lineWidth

Specifies a width for a line on a sparkline. Available for the sparklines of the line- and area-like types.

lossColor

Sets a color for the bars indicating the values that are less than the winloss threshold. Available for a sparkline of the winloss type only.

margin

Generates space around the widget.

maxColor

Sets a color for the boundary of the maximum point on a sparkline.

maxValue

Specifies the maximum value of the sparkline's value axis.

minColor

Sets a color for the boundary of the minimum point on a sparkline.

minValue

Specifies the minimum value of the sparkline value axis.

onDisposing

A handler for the disposing event.

onDrawn

A handler for the drawn event.

onExported

A handler for the exported event.

onExporting

A handler for the exporting event.

onFileSaving

A handler for the fileSaving event.

onIncidentOccurred

A handler for the incidentOccurred event.

onInitialized

A handler for the initialized event.

onOptionChanged

A handler for the optionChanged event.

onTooltipHidden

A handler for the tooltipHidden event.

onTooltipShown

A handler for the tooltipShown event.

pathModified

Notifies a widget that it is embedded into an HTML page that uses a path modifier.

pointColor

Sets a color for points on a sparkline. Available for the sparklines of the line- and area-like types.

pointSize

Specifies the diameter of sparkline points in pixels. Available for the sparklines of line- and area-like types.

pointSymbol

Specifies a symbol to use as a point marker on a sparkline. Available for the sparklines of the line- and area-like types.

rtlEnabled

Specifies whether or not the widget supports right-to-left representation.

showFirstLast

Specifies whether or not to indicate both the first and last values on a sparkline.

showMinMax

Specifies whether or not to indicate both the minimum and maximum values on a sparkline.

size

Specifies the size of the widget in pixels.

theme

Sets the name of the theme to be used in the widget.

tooltip

Configures the tooltip.

type

Determines the type of a sparkline.

valueField

Specifies the data source field that provides values for a sparkline.

winColor

Sets a color for the bars indicating the values greater than a winloss threshold. Available for a sparkline of the winloss type only.

winlossThreshold

Specifies a value that serves as a threshold for the sparkline of the winloss type.

Methods

This section describes the methods that can be used in code to manipulate objects related to the Sparkline widget.

Name Description
beginUpdate()

Prevents the component from refreshing until the endUpdate() method is called.

element()

Returns the root HTML element of the widget.

endUpdate()

Enables the component to refresh after the beginUpdate() method call.

exportTo(fileName, format)

Exports the widget into a document with a specified name and format.

instance()

Returns an instance of this component class.

off(eventName)

Detaches all event handlers from the specified event.

off(eventName, eventHandler)

Detaches a particular event handler from the specified event.

on(eventName, eventHandler)

Subscribes to a specified event.

on(events)

Subscribes to the specified events.

option()

Returns the configuration options of this component.

option(optionName)

Gets the value of the specified configuration option of this component.

option(optionName, optionValue)

Sets a value to the specified configuration option of this component.

option(options)

Sets one or more options of this component.

print()

Opens the browser's print window.

render()

Redraws the widget.

svg()

Returns the widget's SVG markup.

Events

This section describes events fired by this widget.

Name Description
disposing

Fires when the widget is being removed.

drawn

Fires when the widget has finished drawing itself.

exported

Fires after data from the widget is exported.

exporting

Fires before data from the widget is exported.

fileSaving

Fires before a file with exported data is saved on the user's local storage.

incidentOccurred

Fires when an error or warning appears in a widget.

initialized

Fires when the widget is initialized.

optionChanged

Fires after an option of the component is changed.

tooltipHidden

Fires when a sparkline's tooltip becomes hidden.

tooltipShown

Fires when a sparkline tooltip appears.