React PieChart - OData Service
To bind the PieChart to data provided by an OData service, use the ODataStore.
jQuery
$(function() { $("#pieChartContainer").dxPieChart({ dataSource: new DevExpress.data.DataSource({ store: { type: 'odata', url: 'https://www.example.com/dataservices/odata/targetData', key: 'Id' }, paginate: false }), // ... }); });
Angular
<dx-pie-chart [dataSource]="pieChartDataSource"> <!-- ... --> </dx-pie-chart>
import { Component } from '@angular/core'; import 'devextreme/data/odata/store'; import DataSource from 'devextreme/data/data_source'; @Component({ selector: 'app-root', templateUrl: './app.component.html', styleUrls: ['./app.component.css'] }) export class AppComponent { pieChartDataSource = new DataSource({ store: { type: 'odata', url: 'https://www.example.com/dataservices/odata/targetData', key: 'Id' }, paginate: false }); }
import { BrowserModule } from '@angular/platform-browser'; import { NgModule } from '@angular/core'; import { AppComponent } from './app.component'; import { DxPieChartModule } from 'devextreme-angular'; @NgModule({ declarations: [ AppComponent ], imports: [ BrowserModule, DxPieChartModule ], providers: [ ], bootstrap: [AppComponent] }) export class AppModule { }
Vue
<template> <DxPieChart :data-source="pieChartDataSource"> <!-- ... --> </DxPieChart> </template> <script> import DxPieChart from 'devextreme-vue/pie-chart'; import 'devextreme/data/odata/store'; import DataSource from 'devextreme/data/data_source'; const pieChartDataSource = new DataSource({ store: { type: 'odata', url: 'https://www.example.com/dataservices/odata/targetData', key: 'Id' }, paginate: false }); export default { components: { DxPieChart }, data() { return { pieChartDataSource } } } </script>
React
import PieChart from 'devextreme-react/pie-chart'; import 'devextreme/data/odata/store'; import DataSource from 'devextreme/data/data_source'; const pieChartDataSource = new DataSource({ store: { type: 'odata', url: 'https://www.example.com/dataservices/odata/targetData', key: 'Id' }, paginate: false }); export default function App() { return ( <PieChart dataSource={pieChartDataSource}> {/* ... */} </PieChart> ); }
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 PieChart 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
$(function() { $("#pieChartContainer").dxPieChart({ dataSource: new DevExpress.data.DataSource({ store: { type: 'odata', url: 'https://www.example.com/dataservices/odata/targetData', key: 'Id' }, paginate: false, // Take summer months only filter: [ ['Id', '>=', 6], ['Id', '<=', 8] ] }), // ... }); });
Angular
<dx-pie-chart [dataSource]="pieChartDataSource"> <!-- ... --> </dx-pie-chart>
import { Component } from '@angular/core'; import 'devextreme/data/odata/store'; import DataSource from 'devextreme/data/data_source'; @Component({ selector: 'app-root', templateUrl: './app.component.html', styleUrls: ['./app.component.css'] }) export class AppComponent { pieChartDataSource = new DataSource({ store: { type: 'odata', url: 'https://www.example.com/dataservices/odata/targetData', key: 'Id' }, paginate: false, // Take summer months only filter: [ ['Id', '>=', 6], ['Id', '<=', 8] ] }); }
import { BrowserModule } from '@angular/platform-browser'; import { NgModule } from '@angular/core'; import { AppComponent } from './app.component'; import { DxPieChartModule } from 'devextreme-angular'; @NgModule({ declarations: [ AppComponent ], imports: [ BrowserModule, DxPieChartModule ], providers: [ ], bootstrap: [AppComponent] }) export class AppModule { }
Vue
<template> <DxPieChart :data-source="pieChartDataSource"> <!-- ... --> </DxPieChart> </template> <script> import DxPieChart from 'devextreme-vue/pie-chart'; import 'devextreme/data/odata/store'; import DataSource from 'devextreme/data/data_source'; const pieChartDataSource = new DataSource({ store: { type: 'odata', url: 'https://www.example.com/dataservices/odata/targetData', key: 'Id' }, paginate: false, // Take summer months only filter: [ ['Id', '>=', 6], ['Id', '<=', 8] ] }); export default { components: { DxPieChart }, data() { return { pieChartDataSource } } } </script>
React
import PieChart from 'devextreme-react/pie-chart'; import 'devextreme/data/odata/store'; import DataSource from 'devextreme/data/data_source'; const pieChartDataSource = new DataSource({ store: { type: 'odata', url: 'https://www.example.com/dataservices/odata/targetData', key: 'Id' }, paginate: false, // Take summer months only filter: [ ['Id', '>=', 6], ['Id', '<=', 8] ] }); export default function App() { return ( <PieChart dataSource={pieChartDataSource}> {/* ... */} </PieChart> ); }
A 1-Click Solution for CRUD Web API Services with Role-based Access Control via EF Core
If you target .NET for your backend API, be sure to check out Web API Service and register your free copy today. The Solution Wizard scaffolds an OData v4 Web API Service (.NET 6+) with integrated authorization & CRUD operations powered by EF Core ORM. You can use OAuth2, JWT or custom authentication strategies alongside tools like Postman or Swagger (OpenAPI) for API testing. The built-in Web API Service also filters out secured server data based on permissions granted to users. Advanced/enterprise functions include audit trail, endpoints to download reports, file attachments, check validation, obtain localized captions, etc.
To use the free Solution Wizard (which creates the Web API Service), run the Universal Component Installer from the DevExpress Download Manager and use our predefined template in Visual Studio 2022+.
Read Tutorial | View Examples: JavaScript (DevExtreme) & JavaScript (Svelte) | Watch Videos
See Also
If you have technical questions, please create a support ticket in the DevExpress Support Center.