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.
DevExtreme widgets are integrated with many popular libraries and frameworks. See the Installation section (for JavaScript libraries) or the Prerequisites and Installation section (for ASP.NET MVC framework) to find details on setting up DevExtreme with a particular library or framework.
The following code shows how to create the Sparkline widget using every supported library and framework. For more details on working with widgets in these libraries and frameworks, see the Widget Basics topic for jQuery, Angular, AngularJS, Knockout or ASP.NET MVC.
jQuery
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' }); });
<div id="daySparkline"></div> <div id="nightSparkline"></div>
Angular
<dx-sparkline [dataSource]="temperature" argumentField="month" valueField="day" type="bar"> </dx-sparkline> <dx-sparkline [dataSource]="temperature" argumentField="month" valueField="night" type="bar"> </dx-sparkline>
import { DxSparklineModule } from 'devextreme-angular'; // ... export class AppComponent { temperature = [ { month: "January", day: 6, night: 2 }, { month: "February", day: 7, night: 2 }, { month: "March", day: 10, night: 3 } ]; } @NgModule({ imports: [ // ... DxSparklineModule ], // ... })
AngularJS
<div dx-sparkline="{ dataSource: temperature, argumentField: 'month', valueField: 'day', type: 'bar' }"></div> <div dx-sparkline="{ dataSource: temperature, argumentField: 'month', valueField: 'night', type: 'bar' }"></div>
angular.module('DemoApp', ['dx']) .controller("DemoController", function ($scope) { $scope.temperature = [ { month: "January", day: 6, night: 2 }, { month: "February", day: 7, night: 2 }, { month: "March", day: 10, night: 3 } ]; });
Knockout
<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>
var viewModel = { temperature: [ { month: "January", day: 6, night: 2 }, { month: "February", day: 7, night: 2 }, { month: "March", day: 10, night: 3 } ] }; ko.applyBindings(viewModel);
ASP.NET MVC Controls
@(Html.DevExtreme().Sparkline() .ID("daySpakline") .DataSource(new JS ("temperature")) .ArgumentField("month") .ValueField("day") .Type(SparklineType.Bar) ) @(Html.DevExtreme().Sparkline() .ID("nightSpakline") .DataSource(new JS("temperature")) .ArgumentField("month") .ValueField("night") .Type(SparklineType.Bar) ) <script> var temperature = [ { month: "January", day: 6, night: 2 }, { month: "February", day: 7, night: 2 }, { month: "March", day: 10, night: 3 } ]; </script>
@(Html.DevExtreme().Sparkline() _ .ID("daySpakline") _ .DataSource(New JS("temperature")) _ .ArgumentField("month") _ .ValueField("day") _ .Type(SparklineType.Bar) ) @(Html.DevExtreme().Sparkline() _ .ID("nightSpakline") _ .DataSource(New JS("temperature")) _ .ArgumentField("month") _ .ValueField("night") _ .Type(SparklineType.Bar) ) <script> var temperature = [ { month: "January", day: 6, night: 2 }, { month: "February", day: 7, night: 2 }, { month: "March", day: 10, night: 3 } ]; </script>
See Also
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.
See Also
- Handle Events: jQuery | Angular | AngularJS | Knockout | ASP.NET MVC