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
Export: default
Sparkline interactive configuration
Copy Code
Copy to Codepen
$("#sparkline").dxSparkline({
});

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

  • jQuery

    HTML
    <div id="daySparkline"></div>
    <div id="nightSparkline"></div>
    JavaScript
    var temperature = [
        { month: "January", day: 6, night: 2 },
        { month: "February", day: 7, night: 2 },
        { month: "March", day: 10, night: 3 },
        { month: "April", day: 14, night: 5 },
        { month: "May", day: 18, night: 8 },
        { month: "June", day: 21, night: 11 },
        { month: "July", day: 22, night: 13 },
        { month: "August", day: 22, night: 13 },
        { month: "September", day: 19, night: 11 },
        { month: "October", day: 15, night: 8 },
        { month: "November", day: 10, night: 5 },
        { month: "December", day: 7, night: 3 }
    ];
    $(function () {
        $("#daySparkline").dxSparkline({
            dataSource: temperature,
            argumentField: 'month',
            valueField: 'day',
            type: 'bar'
        });
        $("#nightSparkline").dxSparkline({
            dataSource: temperature,
            argumentField: 'month',
            valueField: 'night',
            type: 'bar'
        });
    });
  • AngularJS

    HTML
    <div dx-sparkline="{
        dataSource: temperature,
        argumentField: 'month',
        valueField: 'day',
        type: 'bar'
    }"></div>
    <div dx-sparkline="{
        dataSource: temperature,
        argumentField: 'month',
        valueField: 'night',
        type: 'bar'
    }"></div>
    JavaScript
    angular.module('DemoApp', ['dx'])
        .controller("DemoController", function ($scope) {
            $scope.temperature = [
                // ...   
            ];
        });
  • Knockout

    HTML
    <div data-bind="dxSparkline: {
        dataSource: temperature,
        argumentField: 'month',
        valueField: 'day',
        type: 'bar'
    }"></div>
    <div data-bind="dxSparkline: {
        dataSource: temperature,
        argumentField: 'month',
        valueField: 'night',
        type: 'bar'
    }"></div>
    JavaScript
    var viewModel = {
        temperature: [
            // ...
        ]
    };
    ko.applyBindings(viewModel);
  • ASP.NET MVC Wrappers

    @(Html.DevExtreme().Sparkline()
        .ID("daySpakline")
        .DataSource(Temperature)
        .ArgumentField("month")
        .ValueField("day")
        .Type(SparklineType.Bar)
    )
    @(Html.DevExtreme().Sparkline()
        .ID("nightSpakline")
        .DataSource(Temperature)
        .ArgumentField("month")
        .ValueField("night")
        .Type(SparklineType.Bar)
    )

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 topics in the Installation section.

View Demo Watch Video

See Also

Configuration

An object that specifies configuration options for the Sparkline widget.

Methods

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

Events

This section describes events fired by this widget.