-
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 Vector Map - Colors Customization
This demo shows how to color different map elements. The map represented here indicates the top ten largest countries in the world by means of colors. These colors are assigned to the map areas using the customize callback function of the layers object. Moreover, when one of the areas is selected or hovered over, its color changes to those specified by the selectedColor and hoveredColor properties.
Backend API
import React from 'react';
import VectorMap, {
Layer,
Tooltip,
Border,
Font,
} from 'devextreme-react/vector-map';
import type { ILayerProps, ITooltipProps, VectorMapTypes } from 'devextreme-react/vector-map';
import * as mapsData from 'devextreme-dist/js/vectormap-data/world.js';
import { countries } from './data.ts';
type CountriesKey = keyof typeof countries;
const bounds = [-180, 85, 180, -60];
const customizeLayer: ILayerProps['customize'] = (elements) => {
elements.forEach((element) => {
const name = element.attribute('name') as CountriesKey;
const country = countries[name];
if (country) {
element.applySettings({
color: country.color,
hoveredColor: '#e0e000',
selectedColor: '#008f00',
});
}
});
};
const clickHandler = ({ target }: VectorMapTypes.ClickEvent) => {
const name = target?.attribute('name') as CountriesKey;
if (target && countries[name]) {
target.selected(!target.selected());
}
};
const customizeTooltip: ITooltipProps['customizeTooltip'] = ({ attribute }) => {
const name = attribute('name') as CountriesKey;
const country = countries[name];
if (country) {
return {
text: `${name}: ${country.totalArea}M km²`,
color: country.color,
};
}
return {};
};
export default function App() {
return (
<VectorMap
id="vector-map"
bounds={bounds}
onClick={clickHandler}
>
<Layer
dataSource={mapsData.world}
customize={customizeLayer}>
</Layer>
<Tooltip enabled={true}
customizeTooltip={customizeTooltip}
>
<Border visible={true}></Border>
<Font color="#fff"></Font>
</Tooltip>
</VectorMap>
);
}
import React from 'react';
import VectorMap, {
Layer, Tooltip, Border, Font,
} from 'devextreme-react/vector-map';
import * as mapsData from 'devextreme-dist/js/vectormap-data/world.js';
import { countries } from './data.js';
const bounds = [-180, 85, 180, -60];
const customizeLayer = (elements) => {
elements.forEach((element) => {
const name = element.attribute('name');
const country = countries[name];
if (country) {
element.applySettings({
color: country.color,
hoveredColor: '#e0e000',
selectedColor: '#008f00',
});
}
});
};
const clickHandler = ({ target }) => {
const name = target?.attribute('name');
if (target && countries[name]) {
target.selected(!target.selected());
}
};
const customizeTooltip = ({ attribute }) => {
const name = attribute('name');
const country = countries[name];
if (country) {
return {
text: `${name}: ${country.totalArea}M km²`,
color: country.color,
};
}
return {};
};
export default function App() {
return (
<VectorMap
id="vector-map"
bounds={bounds}
onClick={clickHandler}
>
<Layer
dataSource={mapsData.world}
customize={customizeLayer}
></Layer>
<Tooltip
enabled={true}
customizeTooltip={customizeTooltip}
>
<Border visible={true}></Border>
<Font color="#fff"></Font>
</Tooltip>
</VectorMap>
);
}
import React from 'react';
import ReactDOM from 'react-dom';
import App from './App.tsx';
ReactDOM.render(
<App />,
document.getElementById('app'),
);
export const countries = {
Russia: { totalArea: 17.12, color: '#1564C0' },
Canada: { totalArea: 9.98, color: '#B8860B' },
China: { totalArea: 9.59, color: '#BDB76B' },
'United States': { totalArea: 9.52, color: '#FFA07A' },
Brazil: { totalArea: 8.51, color: '#3CB371' },
Australia: { totalArea: 7.69, color: '#D8BFD8' },
India: { totalArea: 3.29, color: '#DB7093' },
Argentina: { totalArea: 2.78, color: '#FFD700' },
Kazakhstan: { totalArea: 2.72, color: '#CD5C5C' },
Algeria: { totalArea: 2.38, color: '#B0C4DE' },
};
declare module 'devextreme-dist/js/vectormap-data/world.js' {
type Position = number[];
type Geometry =
| { type: 'Point'; coordinates: Position }
| { type: 'MultiPoint'; coordinates: Position[] }
| { type: 'LineString'; coordinates: Position[] }
| { type: 'MultiLineString'; coordinates: Position[][] }
| { type: 'Polygon'; coordinates: Position[][] }
| { type: 'MultiPolygon'; coordinates: Position[][][] };
interface Feature {
type: 'Feature';
geometry: Geometry;
properties: Record<string, unknown>;
}
interface FeatureCollection {
type: 'FeatureCollection';
features: Feature[];
// eslint-disable-next-line spellcheck/spell-checker
bbox?: number[];
}
const world: FeatureCollection;
export { world };
export default world;
}
import React from 'react';
import ReactDOM from 'react-dom';
import App from './App.js';
ReactDOM.render(<App />, document.getElementById('app'));
export const countries = {
Russia: { totalArea: 17.12, color: '#1564C0' },
Canada: { totalArea: 9.98, color: '#B8860B' },
China: { totalArea: 9.59, color: '#BDB76B' },
'United States': { totalArea: 9.52, color: '#FFA07A' },
Brazil: { totalArea: 8.51, color: '#3CB371' },
Australia: { totalArea: 7.69, color: '#D8BFD8' },
India: { totalArea: 3.29, color: '#DB7093' },
Argentina: { totalArea: 2.78, color: '#FFD700' },
Kazakhstan: { totalArea: 2.72, color: '#CD5C5C' },
Algeria: { totalArea: 2.38, color: '#B0C4DE' },
};
<!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>
#vector-map {
height: 440px;
}
Tooltips for the map areas representing the largest countries are customized as well. Using the tooltip | customizeTooltip callback function, they are colored identical to the areas themselves and display the total area of the country.