-
AI-powered Extensions
-
Data Grid
-
Tree List
-
Chat
-
HTML Editor
-
Form
-
-
Data Grids / Data Management
-
Data Grid
- Overview
-
Data Binding
-
Filtering
- Sorting
-
Editing
-
Grouping
-
Selection
- Focused Row
- Paging
-
Scrolling
-
Columns
- AI Assistant
-
Master-Detail
-
Data Summaries
-
Drag & Drop
-
Export to PDF
-
Export to Excel
- Appearance
-
Customization
- State Persistence
-
Adaptability
-
Keyboard Navigation
- Right-To-Left Support
-
Tree List
- Overview
-
Data Binding
-
Filtering
- Sorting
-
Editing
-
Selection
- Focused Row
- Paging
-
Columns
- Drag & Drop
- State Persistence
- Adaptability
-
Keyboard Navigation
-
Card View
-
Pivot Grid
- Overview
-
Data Binding
-
Field Management
-
Data Summaries
- Drill Down
- Filtering
-
Scrolling
-
Export to Excel
- Chart Integration
- Customization
- State Persistence
-
Filter Builder
-
-
Data Visualization
-
Charts
- Overview
-
Data Binding
-
Common Concepts
-
Axis
-
Aggregation
-
Tooltips
-
Selection
-
Customization
-
Zooming
-
Export
-
-
Area Charts
-
Bar Charts
- Bullet Charts
-
Doughnut Charts
-
Financial Charts
-
Funnel and Pyramid Charts
-
Line Charts
- Pareto Chart
-
Pie Charts
-
Point Charts
-
Polar and Radar Charts
-
Range Charts
- Sankey Chart
-
Sparkline Charts
-
Tree Map
-
Gauges
- Overview
-
Runtime update
-
Bar Gauge
-
Circular Gauge
-
Linear Gauge
-
Diagram
- Overview
-
Data Binding
-
Featured Shapes
-
Custom Shapes
-
Document Capabilities
-
User Interaction
- UI Customization
- Adaptability
-
-
Scheduling / Planning
-
Scheduler
- Overview
-
Data Binding
-
Views
-
Appointments
-
Timetable
- Editing
-
Grouping
- Virtual Scrolling
- Drag & Drop
-
Customization
- Adaptability
-
Gantt
- Overview
- Data Binding
-
Filtering
- Sorting
- Strip Lines
- Export to PDF
- Validation
-
Customization
-
-
Messaging
-
WYSIWYG Editor
-
Forms
-
Data Editors
- Overview
-
Common Concepts
-
Calendar
- Check Box
- Color Box
-
Date Box
-
Date Range Box
-
Number Box
- Radio Group
-
Range Selector
- Range Slider
- Slider
- Switch
- Text Area
- Text Box
-
Drop-Downs
- Autocomplete
-
Drop Down Box
-
Select Box
-
Tag Box
-
Lookup
-
Buttons
-
File Upload / File Management
-
File Manager
- Overview
-
File System Types
-
Customization
-
File Uploader
-
-
Popup and Notifications
-
Navigation
- Overview
- Accordion
-
Action Sheet
-
Context Menu
-
Menu
- Multi View
-
Drawer
-
Tab Panel
-
Tabs
-
Toolbar
-
Stepper
- Pagination
-
List
-
Tree View
- Right-to-Left Support
-
Layout
-
Tile View
- Splitter
-
Gallery
- Scroll View
- Box
- Responsive Box
-
-
Interactive Wrappers
-
Sortable
- Resizable
-
-
Progress Indicators
-
Maps
- Overview
-
Map
-
Vector Map
-
Data Binding
- Multiple Layers
-
Markers
- Legend
-
Zooming and Panning
-
Customization
-
-
Localization
Related Demos:
Your search did not match any results.
React Charts - Center Label Customization
To customize the doughnut's center, declare the SVG markup in the centerTemplate. This template accepts the PieChart instance. Use this instance to call PieChart methods. For example, call the getInnerRaduis() method to get the radius of the doughnut hole.
Backend API
import React from 'react';
import PieChart, {
Series,
Legend,
Label,
Connector,
} from 'devextreme-react/pie-chart';
import type { PieChartTypes } from 'devextreme-react/pie-chart';
import { data } from './data.ts';
import type { CountryData } from './types.ts';
import CenterTemplate from './CenterTemplate.tsx';
const countries: string[] = Array.from(new Set(data.map((item: CountryData): string => item.country)));
const customizeLabel = (e: PieChartTypes.PointInfo): string => `${e.argumentText}\n${e.valueText}`;
function App() {
const pies = countries.map((country: string) => (
<PieChart
id="pie-chart"
key={country}
dataSource={data.filter((i: CountryData): boolean => i.country === country)}
resolveLabelOverlapping="shift"
sizeGroup="piesGroup"
innerRadius={0.65}
centerRender={CenterTemplate}
type="doughnut"
>
<Series
argumentField="commodity"
valueField="total"
>
<Label visible={true}
format="fixedPoint"
customizeText={customizeLabel}
backgroundColor="none">
<Connector visible={true}></Connector>
</Label>
</Series>
<Legend visible={false}></Legend>
</PieChart>
));
return (
<div>
<div className="long-title"><h3>Energy Production (GWh, 2024)</h3></div>
<div className="pies-container">
{pies}
</div>
</div>
);
}
export default App;
import React from 'react';
import PieChart, {
Series, Legend, Label, Connector,
} from 'devextreme-react/pie-chart';
import { data } from './data.js';
import CenterTemplate from './CenterTemplate.js';
const countries = Array.from(new Set(data.map((item) => item.country)));
const customizeLabel = (e) => `${e.argumentText}\n${e.valueText}`;
function App() {
const pies = countries.map((country) => (
<PieChart
id="pie-chart"
key={country}
dataSource={data.filter((i) => i.country === country)}
resolveLabelOverlapping="shift"
sizeGroup="piesGroup"
innerRadius={0.65}
centerRender={CenterTemplate}
type="doughnut"
>
<Series
argumentField="commodity"
valueField="total"
>
<Label
visible={true}
format="fixedPoint"
customizeText={customizeLabel}
backgroundColor="none"
>
<Connector visible={true}></Connector>
</Label>
</Series>
<Legend visible={false}></Legend>
</PieChart>
));
return (
<div>
<div className="long-title">
<h3>Energy Production (GWh, 2024)</h3>
</div>
<div className="pies-container">{pies}</div>
</div>
);
}
export default App;
import React from 'react';
import type { PieChartRef } from 'devextreme-react/pie-chart';
const formatNumber = new Intl.NumberFormat('en-US', {
minimumFractionDigits: 0,
}).format;
function calculateTotal(pieChart: ReturnType<PieChartRef['instance']>): string {
return formatNumber(pieChart
.getAllSeries()[0]
.getVisiblePoints()
.reduce((s, p): number => s + Number(p.originalValue), 0));
}
function getImagePath(country: string): string {
return `../../../../images/flags/${country.replace(/\s/, '').toLowerCase()}.svg`;
}
export default function TooltipTemplate(pieChart: ReturnType<PieChartRef['instance']>) {
const { country } = pieChart.getAllSeries()[0].getVisiblePoints()[0].data;
return (
<svg>
<circle cx="100" cy="100" r={pieChart.getInnerRadius() - 6} fill="#eee"></circle>
<image href={getImagePath(country)} x="70" y="58" width="60" height="40" />
<text textAnchor="middle" x="100" y="120" style={{ fontSize: 18, fill: '#494949' }}>
<tspan x="100">{country}</tspan>
<tspan x="100" dy="20px" style={{ fontWeight: 600 }}>{
calculateTotal(pieChart)
}</tspan>
</text>
</svg>
);
}
import React from 'react';
import ReactDOM from 'react-dom';
import App from './App.tsx';
ReactDOM.render(
<App />,
document.getElementById('app'),
);
import type { CountryData } from './types.ts';
export const data: CountryData[] = [
{ country: 'France', commodity: 'Nuclear', total: 360000 },
{ country: 'France', commodity: 'Thermal', total: 52000 },
{ country: 'Germany', commodity: 'Thermal', total: 210000 },
{ country: 'France', commodity: 'Wind', total: 50000 },
{ country: 'Germany', commodity: 'Wind', total: 140000 },
{ country: 'France', commodity: 'Solar', total: 23000 },
{ country: 'Germany', commodity: 'Solar', total: 70000 },
{ country: 'Germany', commodity: 'Hydro', total: 20000 },
{ country: 'France', commodity: 'Hydro', total: 65000 },
{ country: 'Germany', commodity: 'Biomass', total: 45000 },
];
export type CountryData = {
country: string;
commodity: string;
total: number;
};
import React from 'react';
const formatNumber = new Intl.NumberFormat('en-US', {
minimumFractionDigits: 0,
}).format;
function calculateTotal(pieChart) {
return formatNumber(
pieChart
.getAllSeries()[0]
.getVisiblePoints()
.reduce((s, p) => s + Number(p.originalValue), 0),
);
}
function getImagePath(country) {
return `../../../../images/flags/${country.replace(/\s/, '').toLowerCase()}.svg`;
}
export default function TooltipTemplate(pieChart) {
const { country } = pieChart.getAllSeries()[0].getVisiblePoints()[0].data;
return (
<svg>
<circle
cx="100"
cy="100"
r={pieChart.getInnerRadius() - 6}
fill="#eee"
></circle>
<image
href={getImagePath(country)}
x="70"
y="58"
width="60"
height="40"
/>
<text
textAnchor="middle"
x="100"
y="120"
style={{ fontSize: 18, fill: '#494949' }}
>
<tspan x="100">{country}</tspan>
<tspan
x="100"
dy="20px"
style={{ fontWeight: 600 }}
>
{calculateTotal(pieChart)}
</tspan>
</text>
</svg>
);
}
import React from 'react';
import ReactDOM from 'react-dom';
import App from './App.js';
ReactDOM.render(<App />, document.getElementById('app'));
export const data = [
{ country: 'France', commodity: 'Nuclear', total: 360000 },
{ country: 'France', commodity: 'Thermal', total: 52000 },
{ country: 'Germany', commodity: 'Thermal', total: 210000 },
{ country: 'France', commodity: 'Wind', total: 50000 },
{ country: 'Germany', commodity: 'Wind', total: 140000 },
{ country: 'France', commodity: 'Solar', total: 23000 },
{ country: 'Germany', commodity: 'Solar', total: 70000 },
{ country: 'Germany', commodity: 'Hydro', total: 20000 },
{ country: 'France', commodity: 'Hydro', total: 65000 },
{ country: 'Germany', commodity: 'Biomass', total: 45000 },
];
<!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" />
<link rel="stylesheet" type="text/css" href="./bundle.css" />
</head>
<body class="dx-viewport">
<div class="demo-container">
<div id="app"></div>
</div>
<script src="bundles/vendor/react.vendor.js"></script>
<script src="./bundle.js"></script>
</body>
</html>
.pies-container {
margin: auto;
width: 800px;
}
.pies-container > div {
width: 400px;
float: left;
margin-top: -50px;
}
.long-title h3 {
font-weight: 200;
font-size: 28px;
text-align: center;
margin-bottom: 20px;
}
.dxc-hole-template:focus {
outline: none;
}