Your search did not match any results.

Server-Side Data Processing

In many cases, you need to process data on the server before a chart displays it. The Chart component supports this scenario.

In this demo, the data source of the Chart loads weather data for a selected month from an OData service. Each time you select a different month in the drop-down menu, the data source sends a new query to the service. To implement this functionality, assign a DataSource object to the Chart's dataSource property.

In the DataSource, implement the ODataStore. An OData service can include multiple entity collections related to each other, but the ODataStore specifies only one collection. To load multiple collections at once, set the expand property to an array with the additional collection titles. Then, call the postProcess function to process additional data.

Set the paginate property to false to prevent data from partitioning. You can also apply a filter to the received values.

Once you load the data, specify the series type and its nested options (argumentField and valueField), so the component can determine the objects that indicate Chart arguments and values in the data source.
Backend API
Copy to CodeSandBox
<div id="chart-demo"> <dx-chart [dataSource]="chartDataSource" title="Temperature in Seattle , 2017" [valueAxis]="{ valueType: 'numeric', grid: { opacity: 0.2 }, label: { customizeText: customizeText } }" > <dxo-size [height]="420"></dxo-size> <dxi-series argumentField="Number" valueField="Temperature" type="spline" ></dxi-series> <dxo-legend [visible]="false"></dxo-legend> <dxo-common-pane-settings> <dxo-border [visible]="true" [width]="2" [top]="false" [right]="false" ></dxo-border> </dxo-common-pane-settings> <dxo-export [enabled]="true"></dxo-export> <dxo-tooltip [enabled]="true" [customizeTooltip]="customizeTooltip" ></dxo-tooltip> <dxo-argument-axis type="discrete"> <dxo-grid [visible]="true" [opacity]="0.5"></dxo-grid> </dxo-argument-axis> <dxo-loading-indicator [enabled]="true"></dxo-loading-indicator> </dx-chart> <div class="action"> <div class="label">Choose a month:</div> <dx-select-box id="selectbox" [items]="months" [width]="150" [value]="1" valueExpr="id" displayExpr="name" (onValueChanged)="onValueChanged($event)" ></dx-select-box> </div> </div>
import { NgModule, Component, enableProdMode } from '@angular/core'; import { BrowserModule } from '@angular/platform-browser'; import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; import { DxChartModule, DxSelectBoxModule } from 'devextreme-angular'; import DataSource from 'devextreme/data/data_source'; import 'devextreme/data/odata/store'; import { Month, Service } from './app.service'; if (!/localhost/.test( { enableProdMode(); } @Component({ selector: 'demo-app', templateUrl: 'app/app.component.html', styleUrls: ['app/app.component.css'], providers: [Service], }) export class AppComponent { months: Month[]; chartDataSource: any; constructor(service: Service) { this.months = service.getMonths(); this.chartDataSource = new DataSource({ store: { type: 'odata', url: '', }, postProcess: (results) => results[0].DayItems, expand: 'DayItems', filter: ['Id', '=', 1], paginate: false, }); } customizeTooltip(arg) { return { text: `${arg.valueText}&#176C`, }; } customizeText(arg) { return `${arg.valueText}&#176C`; } onValueChanged(data) { this.chartDataSource.filter(['Id', '=', data.value]); this.chartDataSource.load(); } } @NgModule({ imports: [ BrowserModule, DxChartModule, DxSelectBoxModule, ], declarations: [AppComponent], bootstrap: [AppComponent], }) export class AppModule { } platformBrowserDynamic().bootstrapModule(AppModule);
::ng-deep .action { width: 270px; margin-top: 20px; display: flex; justify-content: space-between; align-items: center; }
import { Injectable } from '@angular/core'; export class Month { id: number; name: string; } const months: Month[] = [{ id: 1, name: 'January', }, { id: 2, name: 'February', }, { id: 3, name: 'March', }, { id: 4, name: 'April', }, { id: 5, name: 'May', }, { id: 6, name: 'June', }, { id: 7, name: 'July', }, { id: 8, name: 'August', }, { id: 9, name: 'September', }, { id: 10, name: 'October', }, { id: 11, name: 'November', }, { id: 12, name: 'December', }]; @Injectable() export class Service { getMonths(): Month[] { return months; } }
// In real applications, you should not transpile code in the browser. // You can see how to create your own application with Angular and DevExtreme here: // window.config = { transpiler: 'ts', typescriptOptions: { module: 'system', emitDecoratorMetadata: true, experimentalDecorators: true, }, meta: { 'typescript': { 'exports': 'ts', }, 'devextreme/localization.js': { 'esModule': true, }, }, paths: { 'npm:': '', }, map: { 'ts': 'npm:plugin-typescript@4.2.4/lib/plugin.js', 'typescript': 'npm:typescript@4.2.4/lib/typescript.js', '@angular/core': 'npm:@angular/core@12.2.17', '@angular/platform-browser': 'npm:@angular/platform-browser@12.2.17', '@angular/platform-browser-dynamic': 'npm:@angular/platform-browser-dynamic@12.2.17', '@angular/forms': 'npm:@angular/forms@12.2.17', '@angular/common': 'npm:@angular/common@12.2.17', '@angular/compiler': 'npm:@angular/compiler@12.2.17', 'tslib': 'npm:tslib@2.3.1/tslib.js', 'rxjs': 'npm:rxjs@7.5.3/dist/bundles/rxjs.umd.js', 'rxjs/operators': 'npm:rxjs@7.5.3/dist/cjs/operators/index.js', 'rrule': 'npm:rrule@2.6.4/dist/es5/rrule.js', 'luxon': 'npm:luxon@1.28.0/build/global/luxon.min.js', 'es6-object-assign': 'npm:es6-object-assign@1.1.0', 'devextreme': 'npm:devextreme@22.2.5/cjs', 'devextreme/bundles/dx.all': 'npm:devextreme@22.2.5/bundles/dx.all.js', 'jszip': 'npm:jszip@3.7.1/dist/jszip.min.js', 'devextreme-quill': 'npm:devextreme-quill@1.5.20/dist/dx-quill.min.js', 'devexpress-diagram': 'npm:devexpress-diagram@2.1.72', 'devexpress-gantt': 'npm:devexpress-gantt@4.1.42', 'devextreme-angular': 'npm:devextreme-angular@22.2.5', '@devextreme/runtime': 'npm:@devextreme/runtime@3.0.11', 'inferno': 'npm:inferno@7.4.11/dist/inferno.min.js', 'inferno-compat': 'npm:inferno-compat/dist/inferno-compat.min.js', 'inferno-create-element': 'npm:inferno-create-element@7.4.11/dist/inferno-create-element.min.js', 'inferno-dom': 'npm:inferno-dom/dist/inferno-dom.min.js', 'inferno-hydrate': 'npm:inferno-hydrate@7.4.11/dist/inferno-hydrate.min.js', 'inferno-clone-vnode': 'npm:inferno-clone-vnode/dist/inferno-clone-vnode.min.js', 'inferno-create-class': 'npm:inferno-create-class/dist/inferno-create-class.min.js', 'inferno-extras': 'npm:inferno-extras/dist/inferno-extras.min.js', // Prettier 'prettier/standalone': 'npm:prettier@2.8.4/standalone.js', 'prettier/parser-html': 'npm:prettier@2.8.4/parser-html.js', }, packages: { 'app': { main: './app.component.ts', defaultExtension: 'ts', }, 'devextreme': { defaultExtension: 'js', }, 'devextreme/events/utils': { main: 'index', }, 'devextreme/events': { main: 'index', }, 'es6-object-assign': { main: './index.js', defaultExtension: 'js', }, 'rxjs': { defaultExtension: 'js', }, 'rxjs/operators': { defaultExtension: 'js', }, }, packageConfigPaths: [ 'npm:@devextreme/*/package.json', 'npm:@devextreme/runtime@3.0.11/inferno/package.json', 'npm:@angular/*/package.json', 'npm:@angular/common@12.2.17/*/package.json', 'npm:rxjs@7.5.3/package.json', 'npm:rxjs@7.5.3/operators/package.json', 'npm:devextreme-angular@22.2.5/*/package.json', 'npm:devextreme-angular@22.2.5/ui/*/package.json', 'npm:devextreme-angular@22.2.5/package.json', 'npm:devexpress-diagram@2.1.72/package.json', 'npm:devexpress-gantt@4.1.42/package.json', ], }; System.config(window.config);
<!DOCTYPE html> <html xmlns=""> <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=1.0" /> <link rel="stylesheet" type="text/css" href="" /> <script src=""></script> <script src=""></script> <script src=""></script> <script src=""></script> <script src="config.js"></script> <script> System.import("app").catch(console.error.bind(console)); </script> </head> <body class="dx-viewport"> <div class="demo-container"> <demo-app>Loading...</demo-app> </div> </body> </html>