DevExtreme v26.1 is now available.

Explore our newest features/capabilities and share your thoughts with us.

Your search did not match any results.

Angular Charts - Sparklines

In this demo, a set of line-like sparklines is placed into a table. Although these sparklines look similar, they have different series types. The first table column contains sparklines of the line series type. In the second table column, spline sparklines are placed. The third table column displays sparklines of the step line series type.

Backend API
<div class="long-title"><h3>Monthly Prices of Oil, Gold and Silver</h3></div> <div id="chart-demo"> <table class="demo-table"> <tr> <th><div class="dx-screen-reader-only">Year</div></th> <th>Oil (USD/barrel)</th> <th>Gold (USD/troy ounce)</th> <th>Silver (USD/troy ounce)</th> </tr> @for(year of years; track year) { <tr> <th>{{ year }}</th> <td> <dx-sparkline class="sparkline" [dataSource]="oilCosts" argumentField="month" valueField="{{ year }}" type="line" [showMinMax]="true" > <dxo-sparkline-tooltip [format]="{ type: 'currency', precision: 2 }" ></dxo-sparkline-tooltip> </dx-sparkline> </td> <td> <dx-sparkline class="sparkline" [dataSource]="goldCosts" argumentField="month" valueField="{{ year }}" type="spline" [lineWidth]="3" lineColor="#9ab57e" minColor="#6babac" maxColor="#ebdd8f" [showMinMax]="true" [showFirstLast]="false" > <dxo-sparkline-tooltip [format]="{ type: 'currency', precision: 2 }" ></dxo-sparkline-tooltip> </dx-sparkline> </td> <td> <dx-sparkline class="sparkline" [dataSource]="silverCosts" argumentField="month" valueField="{{ year }}" type="stepline" lineColor="#e8c267" firstLastColor="#e55253" [pointSize]="6" pointSymbol="square" pointColor="#ebdd8f" > <dxo-sparkline-tooltip [format]="{ type: 'currency', precision: 2 }" ></dxo-sparkline-tooltip> </dx-sparkline> </td> </tr> } </table> </div>
import { bootstrapApplication } from '@angular/platform-browser'; import { Component, enableProdMode, provideZoneChangeDetection } from '@angular/core'; import { DxSparklineModule } from 'devextreme-angular'; import { CostInfo, Service } from './app.service'; if (!/localhost/.test(document.location.host)) { enableProdMode(); } @Component({ selector: 'demo-app', templateUrl: './app.component.html', styleUrls: ['./app.component.css'], providers: [Service], imports: [ DxSparklineModule, ], }) export class AppComponent { oilCosts: CostInfo[]; goldCosts: CostInfo[]; silverCosts: CostInfo[]; years: number[]; constructor(service: Service) { this.oilCosts = service.getOilCosts(); this.goldCosts = service.getGoldCosts(); this.silverCosts = service.getSilverCosts(); this.years = [2021, 2022, 2023]; } } bootstrapApplication(AppComponent, { providers: [ provideZoneChangeDetection({ eventCoalescing: true, runCoalescing: true }), ], });
::ng-deep #chart-demo { height: 440px; } ::ng-deep .demo-table { width: 100%; border: 1px solid #c2c2c2; border-collapse: collapse; } ::ng-deep .demo-table th, ::ng-deep .demo-table td { font-weight: 400; width: 200px; padding: 25px 10px 5px; border: 1px solid #c2c2c2; } ::ng-deep .demo-table th { padding: 25px 15px 20px; border: 1px solid #c2c2c2; } ::ng-deep .demo-table tr:nth-child(2) td { border-top: 1px solid #c2c2c2; } ::ng-deep .demo-table td:first-of-type { border-left: 1px solid #c2c2c2; } ::ng-deep .demo-table .sparkline { width: 200px; height: 30px; } ::ng-deep .long-title h3 { font-weight: 200; font-size: 28px; text-align: center; margin-bottom: 20px; margin-top: 0; }
import { Injectable } from '@angular/core'; export class CostInfo { month: number; 2021: number; 2022: number; 2023: number; } const oilCosts: CostInfo[] = [{ month: 1, 2021: 52.16, 2022: 89.16, 2023: 78.12, }, { month: 2, 2021: 61.55, 2022: 96.13, 2023: 76.83, }, { month: 3, 2021: 59.19, 2022: 100.53, 2023: 73.28, }, { month: 4, 2021: 63.50, 2022: 104.59, 2023: 79.45, }, { month: 5, 2021: 66.31, 2022: 114.38, 2023: 71.58, }, { month: 6, 2021: 73.52, 2022: 107.76, 2023: 70.25, }, { month: 7, 2021: 73.93, 2022: 101.31, 2023: 76.07, }, { month: 8, 2021: 68.43, 2022: 90.09, 2023: 81.39, }, { month: 9, 2021: 75.22, 2022: 79.91, 2023: 89.43, }, { month: 10, 2021: 83.50, 2022: 86.54, 2023: 85.64, }, { month: 11, 2021: 66.14, 2022: 80.48, 2023: 77.69, }, { month: 12, 2021: 75.33, 2022: 80.16, 2023: 71.90, }]; const goldCosts: CostInfo[] = [{ month: 1, 2021: 1866.98, 2022: 1816.51, 2023: 1894.75, }, { month: 2, 2021: 1808.17, 2022: 1856.30, 2023: 1858.74, }, { month: 3, 2021: 1718.23, 2022: 1947.83, 2023: 1912.12, }, { month: 4, 2021: 1760.27, 2022: 1933.88, 2023: 2000.13, }, { month: 5, 2021: 1850.26, 2022: 1848.33, 2023: 1992.05, }, { month: 6, 2021: 1834.57, 2022: 1836.57, 2023: 1942.92, }, { month: 7, 2021: 1807.84, 2022: 1738.41, 2023: 1951.01, }, { month: 8, 2021: 1784.28, 2022: 1764.56, 2023: 1918.41, }, { month: 9, 2021: 1777.27, 2022: 1680.78, 2023: 1915.65, }, { month: 10, 2021: 1776.85, 2022: 1664.15, 2023: 1916.14, }, { month: 11, 2021: 1820.23, 2022: 1725.06, 2023: 1984.45, }, { month: 12, 2021: 1790.43, 2022: 1796.87, 2023: 2027.01, }]; const silverCosts: CostInfo[] = [{ month: 1, 2021: 25.91, 2022: 23.13, 2023: 23.76, }, { month: 2, 2021: 27.35, 2022: 23.51, 2023: 21.90, }, { month: 3, 2021: 25.60, 2022: 25.17, 2023: 21.92, }, { month: 4, 2021: 25.63, 2022: 24.51, 2023: 24.98, }, { month: 5, 2021: 27.48, 2022: 21.90, 2023: 24.21, }, { month: 6, 2021: 26.98, 2022: 21.46, 2023: 23.34, }, { month: 7, 2021: 25.66, 2022: 19.07, 2023: 24.08, }, { month: 8, 2021: 24.01, 2022: 19.74, 2023: 23.55, }, { month: 9, 2021: 23.19, 2022: 18.91, 2023: 23.15, }, { month: 10, 2021: 23.36, 2022: 19.34, 2023: 22.25, }, { month: 11, 2021: 24.16, 2022: 21.03, 2023: 23.47, }, { month: 12, 2021: 22.47, 2022: 23.29, 2023: 24.03, }]; @Injectable() export class Service { getOilCosts(): CostInfo[] { return oilCosts; } getGoldCosts(): CostInfo[] { return goldCosts; } getSilverCosts(): CostInfo[] { return silverCosts; } }
<!DOCTYPE html> <html lang="en"> <head> <title>DevExtreme Demo</title> <meta http-equiv="X-UA-Compatible" content="IE=edge" /> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=5.0" /> <link rel="stylesheet" type="text/css" href="https://cdn3.devexpress.com/jslib/26.1.5/css/dx.light.css" /> </head> <body class="dx-viewport"> <div class="demo-container"> <demo-app>Loading...</demo-app> </div> <script src="https://cdn.jsdelivr.net/npm/zone.js@0.16.2/bundles/zone.umd.js"></script> <script src="./bundle.js" type="module"></script> </body> </html>