DevExtreme Angular - OData Service

To bind the Chart to data provided by an OData service, use the ODataStore.

TypeScript
HTML
  • import { DxChartModule } from "devextreme-angular";
  • import "devextreme/data/odata/store";
  • import DataSource from "devextreme/data/data_source";
  • // ...
  • export class AppComponent {
  • chartDataSource = new DataSource({
  • store: {
  • type: 'odata',
  • url: 'https://js.devexpress.com/Demos/WidgetsGallery/odata/WeatherItems',
  • key: 'Id'
  • },
  • paginate: false
  • });
  • }
  • @NgModule({
  • imports: [
  • // ...
  • DxChartModule
  • ],
  • // ...
  • })
  • <dx-chart [dataSource]="chartDataSource">
  • <dxo-common-series-settings
  • argumentField="Name"
  • type="bar">
  • </dxo-common-series-settings>
  • <dxi-series valueField="RecordHigh" name="Highest temperature, &deg;C"></dxi-series>
  • <dxi-series valueField="RecordLow" name="Lowest temperature, &deg;C"></dxi-series>
  • <dxi-series valueField="Average" name="Average temperature, &deg;C"></dxi-series>
  • </dx-chart>

As you may notice, in the previous code, the ODataStore is not declared explicilty. Instead, it is wrapped in the DataSource instance. That is because the Chart requires pagination to be off in order to prevent data from partitioning. Other than that, the DataSource provides wide data-processing capabilities. For example, it can filter data.

TypeScript
HTML
  • import { DxChartModule } from "devextreme-angular";
  • import "devextreme/data/odata/store";
  • import DataSource from "devextreme/data/data_source";
  • // ...
  • export class AppComponent {
  • chartDataSource = new DataSource({
  • store: {
  • type: 'odata',
  • url: 'https://js.devexpress.com/Demos/WidgetsGallery/odata/WeatherItems',
  • key: 'Id'
  • },
  • paginate: false,
  • // Takes the summer months only
  • filter: [
  • ['Id', '>=', 6],
  • ['Id', '<=', 8]
  • ]
  • });
  • }
  • @NgModule({
  • imports: [
  • // ...
  • DxChartModule
  • ],
  • // ...
  • })
  • <dx-chart [dataSource]="chartDataSource">
  • <dxo-common-series-settings
  • argumentField="Name"
  • type="bar">
  • </dxo-common-series-settings>
  • <dxi-series valueField="RecordHigh" name="Highest temperature, &deg;C"></dxi-series>
  • <dxi-series valueField="RecordLow" name="Lowest temperature, &deg;C"></dxi-series>
  • <dxi-series valueField="Average" name="Average temperature, &deg;C"></dxi-series>
  • </dx-chart>

View Demo

See Also