DevExtreme Angular - OData Service

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

jQuery
JavaScript
$(function() {
    $("#chartContainer").dxChart({
        dataSource: new DevExpress.data.DataSource({
            store: {
                type: 'odata',
                url: 'https://js.devexpress.com/Demos/WidgetsGallery/odata/WeatherItems',
                key: 'Id'
            },
            paginate: false
        }),
        commonSeriesSettings: {
            argumentField: 'Name',
            type: 'bar'
        },
        series: [
            { valueField: 'RecordHigh', name: 'Highest temperature, °C' },
            { valueField: 'RecordLow', name: 'Lowest temperature, °C' },
            { valueField: 'Average', name: 'Average temperature, °C' }
        ]
    });
});
Angular
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.

jQuery
JavaScript
$(function() {
    $("#chartContainer").dxChart({
        dataSource: new DevExpress.data.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]
            ]
        }),
        // ...
        // See the previous code for the series configuration
    });
});
Angular
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