Articles in this section
Category / Section

How to bind a complex data collection to React Chart?

3 mins read

This article explains how to bind a complex data collection in the React Chart.

Binding a complex data collection

You can easily bind complex data to the chart by setting the enableComplexProperty property to true for the series.

In the following code example, the group.y1 value is binding to the primary y axis.

Index.js

import { createRoot } from 'react-dom/client';
import * as React from 'react';
import { ChartComponent, SeriesCollectionDirective, SeriesDirective, Inject, Category,
ColumnSeries } from '@syncfusion/ej2-react-charts';

export let data = [
   { x: 'Jan', group: { y: 70, y1: 60 } },
   { x: 'Feb', group: { y: 75, y1: 68 } },
   { x: 'Mar', group: { y: 65, y1: 60 } },
   { x: 'Apr', group: { y: 60, y1: 45 } },
   { x: 'May', group: { y: 55, y1: 50 } }
];

const Column = () => {
return (
     <chartcomponent id="charts" primaryxaxis="{{" valuetype:="" 'category',="" interval:="" 1="" }}="" primaryyaxis="{{" minimum:="" 0,="" maximum:="" 80,="" 10="">
       <inject services="{[ColumnSeries," category]}="">
       <seriescollectiondirective>
         <seriesdirective datasource="{data}" xname="x" yname="group.y1" fill="#febe17" type="Column" enablecomplexproperty="true">
       </seriesdirective></seriescollectiondirective>
     </inject></chartcomponent>
   );
};
export default Column;

const root = createRoot(document.getElementById('sample'));
root.render(<column>);

The following screenshot portrays the results of the code snippet mentioned above.

Screenshot

React chart complex data collection

View Sample in Stackblitz

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied