JavaScript/jQuery Sparkline Options
See Also
- Configure a Widget: Angular | Vue | React | jQuery | AngularJS | Knockout | ASP.NET MVC 5 | ASP.NET Core
barNegativeColor
Sets a color for the bars indicating negative values. Available for a sparkline of the bar type only.
This property supports the following colors:
- Hexadecimal colors
- RGB colors
- RGBA colors
- Predefined/cross-browser color names
- Predefined SVG colors
- Paint server address
To set a color for the bars indicating positive values, specify the barPositiveColor property.
barPositiveColor
Sets a color for the bars indicating positive values. Available for a sparkline of the bar type only.
This property supports the following colors:
- Hexadecimal colors
- RGB colors
- RGBA colors
- Predefined/cross-browser color names
- Predefined SVG colors
- Paint server address
To set a color for the bars indicating negative values, specify the barNegativeColor property.
dataSource
If you use DevExtreme ASP.NET MVC Controls, refer to the Bind Controls to Data article.
The Sparkline works with collections of objects.
Depending on your data source, bind the Sparkline to data as follows. In each case, also specify the argumentField and valueField properties.
Data Array
Assign the array to the dataSource property. View DemoRead-Only Data in JSON Format
Set the dataSource property to the URL of a JSON file or service that returns JSON data.OData
Implement an ODataStore.Web API, PHP, MongoDB
Use one of the following extensions to enable the server to process data according to the protocol DevExtreme UI components use:Then, use the createStore method to configure access to the server on the client as shown below. This method is part of DevExtreme.AspNet.Data.
jQuery
JavaScript$(function() { let serviceUrl = "https://url/to/my/service"; $("#sparklineContainer").dxSparkline({ // ... dataSource: DevExpress.data.AspNet.createStore({ key: "ID", loadUrl: serviceUrl + "/GetAction", insertUrl: serviceUrl + "/InsertAction", updateUrl: serviceUrl + "/UpdateAction", deleteUrl: serviceUrl + "/DeleteAction" }) }) });
Angular
app.component.tsapp.component.htmlapp.module.tsimport { Component } from '@angular/core'; import CustomStore from 'devextreme/data/custom_store'; import { createStore } from 'devextreme-aspnet-data-nojquery'; @Component({ selector: 'app-root', templateUrl: './app.component.html', styleUrls: ['./app.component.css'] }) export class AppComponent { store: CustomStore; constructor() { let serviceUrl = "https://url/to/my/service"; this.store = createStore({ key: "ID", loadUrl: serviceUrl + "/GetAction", insertUrl: serviceUrl + "/InsertAction", updateUrl: serviceUrl + "/UpdateAction", deleteUrl: serviceUrl + "/DeleteAction" }) } }
<dx-sparkline ... [dataSource]="store"> </dx-sparkline>
import { BrowserModule } from '@angular/platform-browser'; import { NgModule } from '@angular/core'; import { AppComponent } from './app.component'; import { DxSparklineModule } from 'devextreme-angular'; @NgModule({ declarations: [ AppComponent ], imports: [ BrowserModule, DxSparklineModule ], providers: [], bootstrap: [AppComponent] }) export class AppModule { }
Vue
App.vue<template> <DxSparkline ... :data-source="store" /> </template> <script> import 'devextreme/dist/css/dx.common.css'; import 'devextreme/dist/css/dx.light.css'; import CustomStore from 'devextreme/data/custom_store'; import { createStore } from 'devextreme-aspnet-data-nojquery'; import { DxSparkline } from 'devextreme-vue/sparkline'; export default { components: { DxSparkline }, data() { const serviceUrl = "https://url/to/my/service"; const store = createStore({ key: "ID", loadUrl: serviceUrl + "/GetAction", insertUrl: serviceUrl + "/InsertAction", updateUrl: serviceUrl + "/UpdateAction", deleteUrl: serviceUrl + "/DeleteAction" }); return { store } } } </script>
React
App.jsimport React from 'react'; import 'devextreme/dist/css/dx.common.css'; import 'devextreme/dist/css/dx.light.css'; import CustomStore from 'devextreme/data/custom_store'; import { createStore } from 'devextreme-aspnet-data-nojquery'; import Sparkline from 'devextreme-react/sparkline'; const serviceUrl = "https://url/to/my/service"; const store = createStore({ key: "ID", loadUrl: serviceUrl + "/GetAction", insertUrl: serviceUrl + "/InsertAction", updateUrl: serviceUrl + "/UpdateAction", deleteUrl: serviceUrl + "/DeleteAction" }); class App extends React.Component { render() { return ( <Sparkline ... dataSource={store} /> ); } } export default App;
Any other data source
Implement a CustomStore.
Regardless of the data source on the input, the Sparkline always wraps it in the DataSource object. This object allows you to sort, filter, group, and perform other data shaping operations. To get its instance, call the getDataSource() method.
Review the following notes about data binding:
Data field names cannot be equal to
this
and should not contain the following characters:.
,:
,[
, and]
.The stores and DataSource have methods to process and update data. However, the methods do not allow you to perform particular tasks (for example, replace the entire dataset, reconfigure data access at runtime). For such tasks, create a new array, store, or DataSource and assign it to the dataSource property as shown in the articles about changing properties in jQuery, Angular, React, and Vue.
elementAttr
Specifies the global attributes to be attached to the UI component's container element.
jQuery
$(function(){ $("#sparklineContainer").dxSparkline({ // ... elementAttr: { id: "elementId", class: "class-name" } }); });
Angular
<dx-sparkline ... [elementAttr]="{ id: 'elementId', class: 'class-name' }"> </dx-sparkline>
import { DxSparklineModule } from "devextreme-angular"; // ... export class AppComponent { // ... } @NgModule({ imports: [ // ... DxSparklineModule ], // ... })
Vue
<template> <DxSparkline ... :element-attr="sparklineAttributes"> </DxSparkline> </template> <script> import DxSparkline from 'devextreme-vue/sparkline'; export default { components: { DxSparkline }, data() { return { sparklineAttributes: { id: 'elementId', class: 'class-name' } } } } </script>
React
import React from 'react'; import Sparkline from 'devextreme-react/sparkline'; class App extends React.Component { sparklineAttributes = { id: 'elementId', class: 'class-name' } render() { return ( <Sparkline ... elementAttr={this.sparklineAttributes}> </Sparkline> ); } } export default App;
firstLastColor
This property supports the following colors:
- Hexadecimal colors
- RGB colors
- RGBA colors
- Predefined/cross-browser color names
- Predefined SVG colors
- Paint server address
Make sure that the showFirstLast property is set to true, so that this property takes effect.
To specify a color for the area inside of the point boundary, use the pointColor property.
lineColor
Sets a color for a line on a sparkline. Available for the sparklines of the line- and area-like types.
This property supports the following colors:
- Hexadecimal colors
- RGB colors
- RGBA colors
- Predefined/cross-browser color names
- Predefined SVG colors
- Paint server address
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.
This property supports the following colors:
- Hexadecimal colors
- RGB colors
- RGBA colors
- Predefined/cross-browser color names
- Predefined SVG colors
- Paint server address
To set a color for the bars indicating the values greater than a winloss threshold, specify the winColor property.
margin
jQuery
$(function() { $("#sparklineContainer").dxSparkline({ // ... margin: { top: 20, bottom: 20, left: 30, right: 30 } }); });
Angular
<dx-sparkline ... > <dxo-margin [top]="20" [bottom]="20" [left]="30" [right]="30"> </dxo-margin> </dx-sparkline>
import { Component } from '@angular/core'; @Component({ selector: 'app-root', templateUrl: './app.component.html', styleUrls: ['./app.component.css'] }) export class AppComponent { // ... }
import { BrowserModule } from '@angular/platform-browser'; import { NgModule } from '@angular/core'; import { AppComponent } from './app.component'; import { DxSparklineModule } from 'devextreme-angular'; @NgModule({ declarations: [ AppComponent ], imports: [ BrowserModule, DxSparklineModule ], providers: [ ], bootstrap: [AppComponent] }) export class AppModule { }
Vue
<template> <DxSparkline ... > <DxMargin :top="20" :bottom="20" :left="30" :right="30" /> </DxSparkline> </template> <script> import 'devextreme/dist/css/dx.common.css'; import 'devextreme/dist/css/dx.light.css'; import DxSparkline, { DxMargin } from 'devextreme-vue/sparkline'; export default { components: { DxSparkline, DxMargin }, // ... } </script>
React
import React from 'react'; import 'devextreme/dist/css/dx.common.css'; import 'devextreme/dist/css/dx.light.css'; import Sparkline, { Margin } from 'devextreme-react/sparkline'; class App extends React.Component { render() { return ( <Sparkline ... > <Margin top={20} bottom={20} left={30} right={30} /> </Sparkline> ); } } export default App;
maxColor
This property supports the following colors:
- Hexadecimal colors
- RGB colors
- RGBA colors
- Predefined/cross-browser color names
- Predefined SVG colors
- Paint server address
So that this property takes effect, make sure that the showMinMax property is set to true.
To set a color for the minimum point on a sparkline, specify the minColor property.
To specify a color for the area inside of the point boundary, use the pointColor property.
minColor
This property supports the following colors:
- Hexadecimal colors
- RGB colors
- RGBA colors
- Predefined/cross-browser color names
- Predefined SVG colors
- Paint server address
Make sure that the showMinMax property is set to true, so that this property takes effect.
To set a color for the maximum point on a sparkline, specify the maxColor property.
To specify a color for the area inside of the point boundary, use the pointColor property.
onDisposing
A function that is executed before the UI component is disposed of.
Name | Type | Description |
---|---|---|
component |
The UI component's instance. |
|
element |
The UI component's container. It is an HTML Element or a jQuery Element when you use jQuery. |
|
model |
Model data. Available only if you use Knockout. |
onDrawn
Name | Type | Description |
---|---|---|
component |
The UI component's instance. |
|
element |
The UI component's container. It is an HTML Element or a jQuery Element when you use jQuery. |
|
model |
The model data. Available only if you use Knockout. |
onExported
Name | Type | Description |
---|---|---|
component |
The UI component's instance. |
|
element |
The UI component's container. It is an HTML Element or a jQuery Element when you use jQuery. |
|
model |
The model data. Available only if you use Knockout. |
onExporting
Name | Type | Description |
---|---|---|
cancel |
Allows you to prevent exporting. |
|
component |
The UI component's instance. |
|
element |
The UI component's container. It is an HTML Element or a jQuery Element when you use jQuery. |
|
fileName |
The name of the file to which the UI component is about to be exported. |
|
format |
The resulting file format. One of PNG, PDF, JPEG, SVG and GIF. |
|
model |
The model data. Available only if you use Knockout. |
onFileSaving
A function that is executed before a file with exported UI component is saved to the user's local storage.
Name | Type | Description |
---|---|---|
cancel |
Allows you to prevent file saving. |
|
component |
The UI component's instance. |
|
data |
Exported data as a BLOB. |
|
element |
The UI component's container. It is an HTML Element or a jQuery Element when you use jQuery. |
|
fileName |
The name of the file to be saved. |
|
format |
The format of the file to be saved. |
onIncidentOccurred
Name | Type | Description |
---|---|---|
component |
The UI component's instance. |
|
element |
The UI component's container. It is an HTML Element or a jQuery Element when you use jQuery. |
|
model |
The model data. Available only if you use Knockout. |
|
target | any |
Information on the occurred incident. |
The UI component notifies you of errors and warnings by passing messages to the browser console. Each message contains the incident's ID, a brief description, and a link to the Errors and Warnings section where further information about this incident can be found.
The onIncidentOccurred function allows you to handle errors and warnings the way you require. The object passed to it contains the target field. This field provides information about the occurred incident and contains the following properties:
- id
The incident's ID. The full list of IDs can be found in the Errors and Warnings section. - type
The incident's type: "error" or "warning". - args
The argument of the incident's message. Depends on the incident. For example, it may be the name of the data source field that was specified incorrectly, or the name of the property that was not set properly. - text
The text passed to the browser's console. Includes the args content, if there is any. - widget
The name of the UI component that produced the error or warning. - version
The used DevExtreme version.
onInitialized
Name | Type | Description |
---|---|---|
component |
The UI component's instance. |
|
element |
The UI component's container. It is an HTML Element or a jQuery Element when you use jQuery. |
onOptionChanged
Name | Type | Description |
---|---|---|
model |
Model data. Available only if you use Knockout. |
|
fullName |
The path to the modified property that includes all parent properties. |
|
element |
The UI component's container. It is an HTML Element or a jQuery Element when you use jQuery. |
|
component |
The UI component's instance. |
|
name |
The modified property if it belongs to the first level. Otherwise, the first-level property it is nested into. |
|
value | any |
The modified property's new value. |
The following example shows how to subscribe to component property changes:
jQuery
$(function() { $("#sparklineContainer").dxSparkline({ // ... onOptionChanged: function(e) { if(e.name === "changedProperty") { // handle the property change here } } }); });
Angular
<dx-sparkline ... (onOptionChanged)="handlePropertyChange($event)"> </dx-sparkline>
import { Component } from '@angular/core'; @Component({ selector: 'app-root', templateUrl: './app.component.html', styleUrls: ['./app.component.css'] }) export class AppComponent { // ... handlePropertyChange(e) { if(e.name === "changedProperty") { // handle the property change here } } }
import { BrowserModule } from '@angular/platform-browser'; import { NgModule } from '@angular/core'; import { AppComponent } from './app.component'; import { DxSparklineModule } from 'devextreme-angular'; @NgModule({ declarations: [ AppComponent ], imports: [ BrowserModule, DxSparklineModule ], providers: [ ], bootstrap: [AppComponent] }) export class AppModule { }
Vue
<template> <DxSparkline ... @option-changed="handlePropertyChange" /> </template> <script> import 'devextreme/dist/css/dx.common.css'; import 'devextreme/dist/css/dx.light.css'; import DxSparkline from 'devextreme-vue/sparkline'; export default { components: { DxSparkline }, // ... methods: { handlePropertyChange: function(e) { if(e.name === "changedProperty") { // handle the property change here } } } } </script>
React
import React from 'react'; import 'devextreme/dist/css/dx.common.css'; import 'devextreme/dist/css/dx.light.css'; import Sparkline from 'devextreme-react/sparkline'; const handlePropertyChange = (e) => { if(e.name === "changedProperty") { // handle the property change here } } export default function App() { return ( <Sparkline ... onOptionChanged={handlePropertyChange} /> ); }
onTooltipHidden
Name | Type | Description |
---|---|---|
component |
The UI component's instance. |
|
element |
The UI component's container. It is an HTML Element or a jQuery Element when you use jQuery. |
|
model |
The model data. Available only if you use Knockout. |
onTooltipShown
Name | Type | Description |
---|---|---|
component |
The UI component's instance. |
|
element |
The UI component's container. It is an HTML Element or a jQuery Element when you use jQuery. |
|
model |
The model data. Available only if you use Knockout. |
pathModified
pointColor
Sets a color for points on a sparkline. Available for the sparklines of the line- and area-like types.
This property supports the following colors:
- Hexadecimal colors
- RGB colors
- RGBA colors
- Predefined/cross-browser color names
- Predefined SVG colors
- Paint server address
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.
Use the VizPointSymbol
enum to specify this property when the UI component is used as an ASP.NET MVC 5 Control or a DevExtreme-Based ASP.NET Core Control. This enum accepts the following values: Circle
, Square
, Polygon
, Triangle
, and Cross
.
rtlEnabled
When this property is set to true, the UI component text flows from right to left, and the layout of elements is reversed. To switch the entire application/site to the right-to-left representation, assign true to the rtlEnabled field of the object passed to the DevExpress.config(config) method.
DevExpress.config({ rtlEnabled: true });
showFirstLast
When this property is set to true, the first and last values are highlighted and painted in the color specified by the firstLastColor property.
size
By default, the UI component occupies the entire area of the container. If you need to set a particular size for the UI component, different from the container's size, assign a height and width in pixels to height and width properties of the size object.
Using the size object, you can hide the UI component. For this purpose, simply assign 0 to both the height and width of the UI component.
theme
A theme is a UI component configuration that gives the UI component a distinctive appearance. Use can use one of the predefined themes or create a custom one. Changing the property values in the UI component's configuration object overrides the theme's corresponding values.
Use the VizTheme
enum to specify this property when the UI component is used as an ASP.NET MVC 5 Control or a DevExtreme-Based ASP.NET Core Control. This enum accepts the following values: GenericLight
, GenericDark
, GenericContrast
, GenericCarmine
, GenericDarkMoon
, GenericSoftBlue
, GenericDarkViolet
, GenericGreenMist
, MaterialBlueLight
, MaterialLimeLight
, MaterialOrangeLight
, MaterialPurpleLight
, MaterialTealLight
.
tooltip
A tooltip is a miniature rectangle displaying UI component data. The tooltip appears when the end-user hovers the cursor over the UI component. You can enable/disable the tooltip, change its appearance and format its text using fields of the tooltip configuration object.
type
The sparkline type determines how data is visualized. The following list shows properties that are available for different types of Sparklines:
All types:
The line, spline, stepline, area, splinearea, and steparea types:
The bar type:
The winloss type:
Use the SparklineType
enum to specify this property when the UI component is used as an ASP.NET MVC 5 Control or a DevExtreme-Based ASP.NET Core Control. This enum accepts the following values: Line
, Spline
, StepLine
, Area
, SplineArea
, StepArea
, Bar
, and WinLoss
.
winColor
Sets a color for the bars indicating the values greater than a winloss threshold. Available for a sparkline of the winloss type only.
This property supports the following colors:
- Hexadecimal colors
- RGB colors
- RGBA colors
- Predefined/cross-browser color names
- Predefined SVG colors
- Paint server address
To set a color for the bars indicating the values that are less than the winloss threshold, specify the lossColor property.
winlossThreshold
In the winloss sparkline, values are represented by bars that either grow up or go down from an invisible line. This line is determined by a threshold value. If a data source value is greater than this threshold value, the bar grows up. Otherwise, it goes down.
You can paint the 'win' and 'loss' bars differently. For this purpose, specify the required colors using the winColor and lossColor properties respectively.