Bar Charts in React Chart component
14 Oct 202424 minutes to read
Bar
To render a bar series in your chart, you need to follow a few steps to configure it correctly. Here’s a concise guide on how to do this:
-
Set the series type: Define the series
type
asBar
in your chart configuration. This indicates that the data should be represented as a bar chart, which makes it easy to compare values across categories. -
Inject the BarSeries module: Inject the
BarSeries
module into theservices
. This step is essential, as it ensures that the necessary functionalities for rendering bar series are available in your chart.
import * as React from "react";
import * as ReactDOM from "react-dom";
import { ChartComponent, SeriesCollectionDirective, SeriesDirective, Inject, Legend, Category, Tooltip, DataLabel, BarSeries } from '@syncfusion/ej2-react-charts';
import { data } from './datasource';
function App() {
const primaryxAxis = { minimum: 2005, maximum: 2012, interval: 1, title: 'Year' };
const primaryyAxis = {
title: 'Percentage',
labelFormat: '{value}%'
};
return <ChartComponent id='charts' primaryXAxis={primaryxAxis} primaryYAxis={primaryyAxis} title='Unemployment rate (%)'>
<Inject services={[BarSeries, Legend, Tooltip, DataLabel, Category]}/>
<SeriesCollectionDirective>
<SeriesDirective dataSource={data} xName='x' yName='y' name='India' type='Bar'>
</SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>;
}
;
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));
import * as React from "react";
import * as ReactDOM from "react-dom";
import { AxisModel, ChartComponent, SeriesCollectionDirective, SeriesDirective, Inject,
Legend, Category, Tooltip, DataLabel, Zoom, Crosshair, BarSeries, Selection}
from'@syncfusion/ej2-react-charts';
import { data } from './datasource';
function App() {
const primaryxAxis: AxisModel = { minimum: 2005, maximum: 2012, interval: 1, title: 'Year' };
const primaryyAxis: AxisModel = {
title: 'Percentage',
labelFormat: '{value}%'
};
return <ChartComponent id='charts'
primaryXAxis={primaryxAxis}
primaryYAxis={primaryyAxis}
title='Unemployment rate (%)'>
<Inject services={[BarSeries, Legend, Tooltip, DataLabel, Category]} />
<SeriesCollectionDirective>
<SeriesDirective dataSource={data} xName='x' yName='y' name='India' type='Bar'>
</SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>
};
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));
export let data = [
{ x: 2005, y: 28 },
{ x: 2006, y: 25 },
{ x: 2007, y: 26 },
{ x: 2008, y: 27 },
{ x: 2009, y: 32 },
{ x: 2010, y: 35 },
{ x: 2011, y: 30 }
];
export let data: Object[] = [
{ x: 2005, y: 28 },
{ x: 2006, y: 25 },
{ x: 2007, y: 26 },
{ x: 2008, y: 27 },
{ x: 2009, y: 32 },
{ x: 2010, y: 35 },
{ x: 2011, y: 30 }
];
Binding data with series
You can bind data to the chart using the dataSource
property within the series configuration. This allows you to connect a JSON dataset or remote data to your chart. To display the data correctly, map the fields from the data to the chart series xName
and yName
properties.
import * as React from "react";
import * as ReactDOM from "react-dom";
import { ChartComponent, SeriesCollectionDirective, SeriesDirective, Inject, Legend, Category, Tooltip, DataLabel, BarSeries } from '@syncfusion/ej2-react-charts';
import { data } from './datasource';
function App() {
const primaryxAxis = { minimum: 2005, maximum: 2012, interval: 1, title: 'Year' };
const primaryyAxis = {
title: 'Percentage',
labelFormat: '{value}%'
};
return <ChartComponent id='charts' primaryXAxis={primaryxAxis} primaryYAxis={primaryyAxis} title='Unemployment rate (%)'>
<Inject services={[BarSeries, Legend, Tooltip, DataLabel, Category]}/>
<SeriesCollectionDirective>
<SeriesDirective dataSource={data} xName='x' yName='y' name='India' type='Bar'>
</SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>;
}
;
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));
import * as React from "react";
import * as ReactDOM from "react-dom";
import { AxisModel, ChartComponent, SeriesCollectionDirective, SeriesDirective, Inject,
Legend, Category, Tooltip, DataLabel, Zoom, Crosshair, BarSeries, Selection}
from'@syncfusion/ej2-react-charts';
import { data } from './datasource';
function App() {
const primaryxAxis: AxisModel = { minimum: 2005, maximum: 2012, interval: 1, title: 'Year' };
const primaryyAxis: AxisModel = {
title: 'Percentage',
labelFormat: '{value}%'
};
return <ChartComponent id='charts'
primaryXAxis={primaryxAxis}
primaryYAxis={primaryyAxis}
title='Unemployment rate (%)'>
<Inject services={[BarSeries, Legend, Tooltip, DataLabel, Category]} />
<SeriesCollectionDirective>
<SeriesDirective dataSource={data} xName='x' yName='y' name='India' type='Bar'>
</SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>
};
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));
export let data = [
{ x: 2005, y: 28 },
{ x: 2006, y: 25 },
{ x: 2007, y: 26 },
{ x: 2008, y: 27 },
{ x: 2009, y: 32 },
{ x: 2010, y: 35 },
{ x: 2011, y: 30 }
];
export let data: Object[] = [
{ x: 2005, y: 28 },
{ x: 2006, y: 25 },
{ x: 2007, y: 26 },
{ x: 2008, y: 27 },
{ x: 2009, y: 32 },
{ x: 2010, y: 35 },
{ x: 2011, y: 30 }
];
Series customization
The following properties can be used to customize the bar
series.
Fill
The fill property determines the color applied to the series.
import * as React from "react";
import * as ReactDOM from "react-dom";
import { ChartComponent, SeriesCollectionDirective, SeriesDirective, Inject, Legend, Category, Tooltip, DataLabel, BarSeries } from '@syncfusion/ej2-react-charts';
import { customData } from './datasource';
function App() {
const primaryxAxis = { minimum: 2005, maximum: 2012, interval: 1, title: 'Year' };
const primaryyAxis = {
minimum: 3, maximum: 12, interval: 1, title: 'Percentage',
labelFormat: '{value}%'
};
return <ChartComponent id='charts' primaryXAxis={primaryxAxis} primaryYAxis={primaryyAxis} title='Unemployment rate (%)'>
<Inject services={[BarSeries, Legend, Tooltip, DataLabel, Category]}/>
<SeriesCollectionDirective>
<SeriesDirective dataSource={customData} xName='x' yName='y' type='Bar' fill='red'>
</SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>;
}
;
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));
import * as React from "react";
import * as ReactDOM from "react-dom";
import { AxisModel, ChartComponent, SeriesCollectionDirective, SeriesDirective, Inject,
Legend, Category, Tooltip, DataLabel, Zoom, Crosshair, BarSeries, Selection}
from'@syncfusion/ej2-react-charts';
import { customData } from './datasource';
function App() {
const primaryxAxis: AxisModel = { minimum: 2005, maximum: 2012, interval: 1, title: 'Year' };
const primaryyAxis: AxisModel = {
minimum: 3, maximum: 12, interval: 1, title: 'Percentage',
labelFormat: '{value}%'
};
return <ChartComponent id='charts'
primaryXAxis={primaryxAxis}
primaryYAxis={primaryyAxis}
title='Unemployment rate (%)'>
<Inject services={[BarSeries, Legend, Tooltip, DataLabel, Category]} />
<SeriesCollectionDirective>
<SeriesDirective dataSource={customData} xName='x' yName='y' type='Bar' fill='red'>
</SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>
};
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));
export let customData = [
{ x: 2006, y: 7.8, point: 'red' },
{ x: 2007, y: 7.2, point: 'green' },
{ x: 2008, y: 6.8, point: 'orange' },
{ x: 2009, y: 10.7, point: 'yellow' },
{ x: 2010, y: 10.8, point: 'grey' },
{ x: 2011, y: 9.8, point: 'blue' }
];
export let customData: Object[] = [
{ x: 2006, y: 7.8, point: 'red' },
{ x: 2007, y: 7.2, point: 'green' },
{ x: 2008, y: 6.8, point: 'orange' },
{ x: 2009, y: 10.7, point: 'yellow' },
{ x: 2010, y: 10.8, point: 'grey' },
{ x: 2011, y: 9.8, point: 'blue' }
];
The fill property can be used to apply a gradient color to the bar series. By configuring this property with gradient values, you can create a visually appealing effect in which the color transitions smoothly from one shade to another.
import * as React from "react";
import * as ReactDOM from "react-dom";
import { ChartComponent, SeriesCollectionDirective, SeriesDirective, Inject, Legend, Category, Tooltip, DataLabel, BarSeries } from '@syncfusion/ej2-react-charts';
import { customData } from './datasource';
function App() {
const primaryxAxis = { minimum: 2005, maximum: 2012, interval: 1, title: 'Year' };
const primaryyAxis = {
minimum: 3, maximum: 12, interval: 1, title: 'Percentage',
labelFormat: '{value}%'
};
return <ChartComponent id='charts' primaryXAxis={primaryxAxis} primaryYAxis={primaryyAxis} title='Unemployment rate (%)'>
<Inject services={[BarSeries, Legend, Tooltip, DataLabel, Category]}/>
<SeriesCollectionDirective>
<SeriesDirective dataSource={customData} xName='x' yName='y' type='Bar' fill='url(#gradient)'>
</SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>;
}
;
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));
import * as React from "react";
import * as ReactDOM from "react-dom";
import { AxisModel, ChartComponent, SeriesCollectionDirective, SeriesDirective, Inject,
Legend, Category, Tooltip, DataLabel, Zoom, Crosshair, BarSeries, Selection}
from'@syncfusion/ej2-react-charts';
import { customData } from './datasource';
function App() {
const primaryxAxis: AxisModel = { minimum: 2005, maximum: 2012, interval: 1, title: 'Year' };
const primaryyAxis: AxisModel = {
minimum: 3, maximum: 12, interval: 1, title: 'Percentage',
labelFormat: '{value}%'
};
return <ChartComponent id='charts'
primaryXAxis={primaryxAxis}
primaryYAxis={primaryyAxis}
title='Unemployment rate (%)'>
<Inject services={[BarSeries, Legend, Tooltip, DataLabel, Category]} />
<SeriesCollectionDirective>
<SeriesDirective dataSource={customData} xName='x' yName='y' type='Bar' fill='url(#gradient)'>
</SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>
};
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));
export let customData = [
{ x: 2006, y: 7.8, point: 'red' },
{ x: 2007, y: 7.2, point: 'green' },
{ x: 2008, y: 6.8, point: 'orange' },
{ x: 2009, y: 10.7, point: 'yellow' },
{ x: 2010, y: 10.8, point: 'grey' },
{ x: 2011, y: 9.8, point: 'blue' }
];
export let customData: Object[] = [
{ x: 2006, y: 7.8, point: 'red' },
{ x: 2007, y: 7.2, point: 'green' },
{ x: 2008, y: 6.8, point: 'orange' },
{ x: 2009, y: 10.7, point: 'yellow' },
{ x: 2010, y: 10.8, point: 'grey' },
{ x: 2011, y: 9.8, point: 'blue' }
];
Opacity
The opacity property specifies the transparency level of the fill. Adjusting this property allows you to control how opaque or transparent the fill color of the series appears.
import * as React from "react";
import * as ReactDOM from "react-dom";
import { ChartComponent, SeriesCollectionDirective, SeriesDirective, Inject, Legend, Category, Tooltip, DataLabel, BarSeries } from '@syncfusion/ej2-react-charts';
import { customData } from './datasource';
function App() {
const primaryxAxis = { minimum: 2005, maximum: 2012, interval: 1, title: 'Year' };
const primaryyAxis = {
minimum: 3, maximum: 12, interval: 1, title: 'Percentage',
labelFormat: '{value}%'
};
return <ChartComponent id='charts' primaryXAxis={primaryxAxis} primaryYAxis={primaryyAxis} title='Unemployment rate (%)'>
<Inject services={[BarSeries, Legend, Tooltip, DataLabel, Category]}/>
<SeriesCollectionDirective>
<SeriesDirective dataSource={customData} xName='x' yName='y' type='Bar' opacity={0.5}>
</SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>;
}
;
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));
import * as React from "react";
import * as ReactDOM from "react-dom";
import { AxisModel, ChartComponent, SeriesCollectionDirective, SeriesDirective, Inject,
Legend, Category, Tooltip, DataLabel, Zoom, Crosshair, BarSeries, Selection}
from'@syncfusion/ej2-react-charts';
import { customData } from './datasource';
function App() {
const primaryxAxis: AxisModel = { minimum: 2005, maximum: 2012, interval: 1, title: 'Year' };
const primaryyAxis: AxisModel = {
minimum: 3, maximum: 12, interval: 1, title: 'Percentage',
labelFormat: '{value}%'
};
return <ChartComponent id='charts'
primaryXAxis={primaryxAxis}
primaryYAxis={primaryyAxis}
title='Unemployment rate (%)'>
<Inject services={[BarSeries, Legend, Tooltip, DataLabel, Category]} />
<SeriesCollectionDirective>
<SeriesDirective dataSource={customData} xName='x' yName='y' type='Bar' opacity={0.5}>
</SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>
};
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));
export let customData = [
{ x: 2006, y: 7.8, point: 'red' },
{ x: 2007, y: 7.2, point: 'green' },
{ x: 2008, y: 6.8, point: 'orange' },
{ x: 2009, y: 10.7, point: 'yellow' },
{ x: 2010, y: 10.8, point: 'grey' },
{ x: 2011, y: 9.8, point: 'blue' }
];
export let customData: Object[] = [
{ x: 2006, y: 7.8, point: 'red' },
{ x: 2007, y: 7.2, point: 'green' },
{ x: 2008, y: 6.8, point: 'orange' },
{ x: 2009, y: 10.7, point: 'yellow' },
{ x: 2010, y: 10.8, point: 'grey' },
{ x: 2011, y: 9.8, point: 'blue' }
];
Dash array
The dashArray property determines the pattern of dashes and gaps in the series.
import * as React from "react";
import * as ReactDOM from "react-dom";
import { ChartComponent, SeriesCollectionDirective, SeriesDirective, Inject, Legend, Category, Tooltip, DataLabel, BarSeries } from '@syncfusion/ej2-react-charts';
import { customData } from './datasource';
function App() {
const primaryxAxis = { minimum: 2005, maximum: 2012, interval: 1, title: 'Year' };
const primaryyAxis = {
minimum: 3, maximum: 12, interval: 1, title: 'Percentage',
labelFormat: '{value}%'
};
const border = {
width: 1.5, color: 'red'
};
return <ChartComponent id='charts' primaryXAxis={primaryxAxis} primaryYAxis={primaryyAxis} title='Unemployment rate (%)'>
<Inject services={[BarSeries, Legend, Tooltip, DataLabel, Category]}/>
<SeriesCollectionDirective>
<SeriesDirective dataSource={customData} xName='x' yName='y' type='Bar' dashArray='2,5' border={border}>
</SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>;
}
;
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));
import * as React from "react";
import * as ReactDOM from "react-dom";
import { AxisModel, ChartComponent, SeriesCollectionDirective, SeriesDirective, Inject,
Legend, Category, Tooltip, DataLabel, Zoom, Crosshair, BarSeries, Selection}
from'@syncfusion/ej2-react-charts';
import { customData } from './datasource';
function App() {
const primaryxAxis: AxisModel = { minimum: 2005, maximum: 2012, interval: 1, title: 'Year' };
const primaryyAxis: AxisModel = {
minimum: 3, maximum: 12, interval: 1, title: 'Percentage',
labelFormat: '{value}%'
};
const border: Object = {
width: 1.5, color: 'red'
};
return <ChartComponent id='charts'
primaryXAxis={primaryxAxis}
primaryYAxis={primaryyAxis}
title='Unemployment rate (%)'>
<Inject services={[BarSeries, Legend, Tooltip, DataLabel, Category]} />
<SeriesCollectionDirective>
<SeriesDirective dataSource={customData} xName='x' yName='y' type='Bar' dashArray='2,5' border={border}>
</SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>
};
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));
export let customData = [
{ x: 2006, y: 7.8, point: 'red' },
{ x: 2007, y: 7.2, point: 'green' },
{ x: 2008, y: 6.8, point: 'orange' },
{ x: 2009, y: 10.7, point: 'yellow' },
{ x: 2010, y: 10.8, point: 'grey' },
{ x: 2011, y: 9.8, point: 'blue' }
];
export let customData: Object[] = [
{ x: 2006, y: 7.8, point: 'red' },
{ x: 2007, y: 7.2, point: 'green' },
{ x: 2008, y: 6.8, point: 'orange' },
{ x: 2009, y: 10.7, point: 'yellow' },
{ x: 2010, y: 10.8, point: 'grey' },
{ x: 2011, y: 9.8, point: 'blue' }
];
Border
Use the border property to customize the width and color of the series border.
import * as React from "react";
import * as ReactDOM from "react-dom";
import { ChartComponent, SeriesCollectionDirective, SeriesDirective, Inject, Legend, Category, Tooltip, DataLabel, BarSeries } from '@syncfusion/ej2-react-charts';
import { customData } from './datasource';
function App() {
const primaryxAxis = { minimum: 2005, maximum: 2012, interval: 1, title: 'Year' };
const primaryyAxis = {
minimum: 3, maximum: 12, interval: 1, title: 'Percentage',
labelFormat: '{value}%'
};
const border = {
width: 1.5, color: 'red'
};
return <ChartComponent id='charts' primaryXAxis={primaryxAxis} primaryYAxis={primaryyAxis} title='Unemployment rate (%)'>
<Inject services={[BarSeries, Legend, Tooltip, DataLabel, Category]}/>
<SeriesCollectionDirective>
<SeriesDirective dataSource={customData} xName='x' yName='y' type='Bar' border={border}>
</SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>;
}
;
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));
import * as React from "react";
import * as ReactDOM from "react-dom";
import { AxisModel, ChartComponent, SeriesCollectionDirective, SeriesDirective, Inject,
Legend, Category, Tooltip, DataLabel, Zoom, Crosshair, BarSeries, Selection}
from'@syncfusion/ej2-react-charts';
import { customData } from './datasource';
function App() {
const primaryxAxis: AxisModel = { minimum: 2005, maximum: 2012, interval: 1, title: 'Year' };
const primaryyAxis: AxisModel = {
minimum: 3, maximum: 12, interval: 1, title: 'Percentage',
labelFormat: '{value}%'
};
const border: Object = {
width: 1.5, color: 'red'
};
return <ChartComponent id='charts'
primaryXAxis={primaryxAxis}
primaryYAxis={primaryyAxis}
title='Unemployment rate (%)'>
<Inject services={[BarSeries, Legend, Tooltip, DataLabel, Category]} />
<SeriesCollectionDirective>
<SeriesDirective dataSource={customData} xName='x' yName='y' type='Bar' border={border}>
</SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>
};
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));
export let customData = [
{ x: 2006, y: 7.8, point: 'red' },
{ x: 2007, y: 7.2, point: 'green' },
{ x: 2008, y: 6.8, point: 'orange' },
{ x: 2009, y: 10.7, point: 'yellow' },
{ x: 2010, y: 10.8, point: 'grey' },
{ x: 2011, y: 9.8, point: 'blue' }
];
export let customData: Object[] = [
{ x: 2006, y: 7.8, point: 'red' },
{ x: 2007, y: 7.2, point: 'green' },
{ x: 2008, y: 6.8, point: 'orange' },
{ x: 2009, y: 10.7, point: 'yellow' },
{ x: 2010, y: 10.8, point: 'grey' },
{ x: 2011, y: 9.8, point: 'blue' }
];
Bar space and width
Bar space
Use the columnSpacing
property in the series to adjust the space between bars.
import * as React from "react";
import * as ReactDOM from "react-dom";
import { ChartComponent, SeriesCollectionDirective, SeriesDirective, Inject, Legend, Category, Tooltip, DataLabel, BarSeries } from '@syncfusion/ej2-react-charts';
import { data } from './datasource';
function App() {
const primaryxAxis = { minimum: 2005, maximum: 2012, interval: 1, title: 'Year' };
const primaryyAxis = {
minimum: 3, maximum: 12, interval: 1, title: 'Percentage',
labelFormat: '{value}%'
};
return <ChartComponent id='charts' primaryXAxis={primaryxAxis} primaryYAxis={primaryyAxis} title='Unemployment rate (%)'>
<Inject services={[BarSeries, Legend, Tooltip, DataLabel, Category]}/>
<SeriesCollectionDirective>
<SeriesDirective dataSource={data} xName='x' yName='y' name='India' type='Bar'>
</SeriesDirective>
<SeriesDirective dataSource={data} xName='x' yName='y1' name='India' type='Bar' columnSpacing={0.5} columnWidth={0.75}>
</SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>;
}
;
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));
import * as React from "react";
import * as ReactDOM from "react-dom";
import { AxisModel, ChartComponent, SeriesCollectionDirective, SeriesDirective, Inject,
Legend, Category, Tooltip, DataLabel, Zoom, Crosshair, BarSeries, Selection}
from'@syncfusion/ej2-react-charts';
import { data } from './datasource';
function App() {
const primaryxAxis: AxisModel = { minimum: 2005, maximum: 2012, interval: 1, title: 'Year' };
const primaryyAxis: AxisModel = {
minimum: 3, maximum: 12, interval: 1, title: 'Percentage',
labelFormat: '{value}%'
};
return <ChartComponent id='charts'
primaryXAxis={primaryxAxis}
primaryYAxis={primaryyAxis}
title='Unemployment rate (%)'>
<Inject services={[BarSeries, Legend, Tooltip, DataLabel, Category]} />
<SeriesCollectionDirective>
<SeriesDirective dataSource={data} xName='x' yName='y' name='India' type='Bar'>
</SeriesDirective>
<SeriesDirective dataSource={data} xName='x' yName='y1' name='India' type='Bar' columnSpacing={0.5} columnWidth={0.75}>
</SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>
};
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));
export let data = [
{ x: 2006, y: 4, y1: 7 },
{ x: 2007, y: 7, y1: 4 },
{ x: 2008, y: 5, y1: 4 },
{ x: 2009, y: 4, y1: 5 },
{ x: 2010, y: 8, y1: 11 },
{ x: 2011, y: 11, y1: 8 }
];
export let data: Object[] = [
{ x: 2006, y: 4, y1: 7 },
{ x: 2007, y: 7, y1: 4 },
{ x: 2008, y: 5, y1: 4 },
{ x: 2009, y: 4, y1: 5 },
{ x: 2010, y: 8, y1: 11 },
{ x: 2011, y: 11, y1: 8 }
];
Bar width
Use the columnWidth
property in the series to adjust the width of the bars.
import * as React from "react";
import * as ReactDOM from "react-dom";
import { ChartComponent, SeriesCollectionDirective, SeriesDirective, Inject, Legend, Category, Tooltip, DataLabel, BarSeries } from '@syncfusion/ej2-react-charts';
import { customData } from './datasource';
function App() {
const primaryxAxis = { minimum: 2005, maximum: 2012, interval: 1, title: 'Year' };
const primaryyAxis = {
minimum: 3, maximum: 12, interval: 1, title: 'Percentage',
labelFormat: '{value}%'
};
return <ChartComponent id='charts' primaryXAxis={primaryxAxis} primaryYAxis={primaryyAxis} title='Unemployment rate (%)'>
<Inject services={[BarSeries, Legend, Tooltip, DataLabel, Category]}/>
<SeriesCollectionDirective>
<SeriesDirective dataSource={customData} xName='x' yName='y' type='Bar' columnWidth= '0.5'>
</SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>;
}
;
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));
import * as React from "react";
import * as ReactDOM from "react-dom";
import { AxisModel, ChartComponent, SeriesCollectionDirective, SeriesDirective, Inject,
Legend, Category, Tooltip, DataLabel, Zoom, Crosshair, BarSeries, Selection}
from'@syncfusion/ej2-react-charts';
import { customData } from './datasource';
function App() {
const primaryxAxis: AxisModel = { minimum: 2005, maximum: 2012, interval: 1, title: 'Year' };
const primaryyAxis: AxisModel = {
minimum: 3, maximum: 12, interval: 1, title: 'Percentage',
labelFormat: '{value}%'
};
return <ChartComponent id='charts'
primaryXAxis={primaryxAxis}
primaryYAxis={primaryyAxis}
title='Unemployment rate (%)'>
<Inject services={[BarSeries, Legend, Tooltip, DataLabel, Category]} />
<SeriesCollectionDirective>
<SeriesDirective dataSource={customData} xName='x' yName='y' type='Bar' columnWidth= '0.5'>
</SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>
};
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));
export let customData = [
{ x: 2006, y: 7.8, point: 'red' },
{ x: 2007, y: 7.2, point: 'green' },
{ x: 2008, y: 8, point: 'orange' },
{ x: 2009, y: 10.7, point: 'yellow' },
{ x: 2010, y: 10.8, point: 'grey' },
{ x: 2011, y: 9.8, point: 'blue' }
];
export let customData: Object[] = [
{ x: 2006, y: 7.8, point: 'red' },
{ x: 2007, y: 7.2, point: 'green' },
{ x: 2008, y: 8, point: 'orange' },
{ x: 2009, y: 10.7, point: 'yellow' },
{ x: 2010, y: 10.8, point: 'grey' },
{ x: 2011, y: 9.8, point: 'blue' }
];
Bar width in pixel
Use the columnWidthInPixel
property in the series to define the exact width of the bars in pixels. This property ensures that each bar maintains the specified width, providing a uniform appearance throughout the chart.
import * as React from "react";
import * as ReactDOM from "react-dom";
import { ChartComponent, SeriesCollectionDirective, SeriesDirective, Inject, Legend, Category, Tooltip, DataLabel, BarSeries } from '@syncfusion/ej2-react-charts';
import { customData } from './datasource';
function App() {
const primaryxAxis = { minimum: 2005, maximum: 2012, interval: 1, title: 'Year' };
const primaryyAxis = {
minimum: 3, maximum: 12, interval: 1, title: 'Percentage',
labelFormat: '{value}%'
};
return <ChartComponent id='charts' primaryXAxis={primaryxAxis} primaryYAxis={primaryyAxis} title='Unemployment rate (%)'>
<Inject services={[BarSeries, Legend, Tooltip, DataLabel, Category]}/>
<SeriesCollectionDirective>
<SeriesDirective dataSource={customData} xName='x' yName='y' type='Bar' columnWidthInPixel={10}>
</SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>;
}
;
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));
import * as React from "react";
import * as ReactDOM from "react-dom";
import { AxisModel, ChartComponent, SeriesCollectionDirective, SeriesDirective, Inject,
Legend, Category, Tooltip, DataLabel, Zoom, Crosshair, BarSeries, Selection}
from'@syncfusion/ej2-react-charts';
import { customData } from './datasource';
function App() {
const primaryxAxis: AxisModel = { minimum: 2005, maximum: 2012, interval: 1, title: 'Year' };
const primaryyAxis: AxisModel = {
minimum: 3, maximum: 12, interval: 1, title: 'Percentage',
labelFormat: '{value}%'
};
return <ChartComponent id='charts'
primaryXAxis={primaryxAxis}
primaryYAxis={primaryyAxis}
title='Unemployment rate (%)'>
<Inject services={[BarSeries, Legend, Tooltip, DataLabel, Category]} />
<SeriesCollectionDirective>
<SeriesDirective dataSource={customData} xName='x' yName='y' type='Bar' columnWidthInPixel={10}>
</SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>
};
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));
export let customData = [
{ x: 2006, y: 7.8, point: 'red' },
{ x: 2007, y: 7.2, point: 'green' },
{ x: 2008, y: 8, point: 'orange' },
{ x: 2009, y: 10.7, point: 'yellow' },
{ x: 2010, y: 10.8, point: 'grey' },
{ x: 2011, y: 9.8, point: 'blue' }
];
export let customData: Object[] = [
{ x: 2006, y: 7.8, point: 'red' },
{ x: 2007, y: 7.2, point: 'green' },
{ x: 2008, y: 8, point: 'orange' },
{ x: 2009, y: 10.7, point: 'yellow' },
{ x: 2010, y: 10.8, point: 'grey' },
{ x: 2011, y: 9.8, point: 'blue' }
];
Grouped bar
Use the groupName
property to group the data points in bar type charts. Data points with the same group name will be grouped together in the chart, making it easy to compare different sets of data.
import * as React from "react";
import * as ReactDOM from "react-dom";
import { ChartComponent, SeriesCollectionDirective, SeriesDirective, Inject, Legend, Category, Tooltip, BarSeries, DataLabel } from '@syncfusion/ej2-react-charts';
import { data1, data2, data3, data4, data5, data6 } from './datasource';
function App() {
return (<ChartComponent id="charts" style={{ textAlign: 'center' }} primaryXAxis={{
valueType: 'Category',
interval: 1,
majorGridLines: { width: 0 },
}} primaryYAxis={{
majorGridLines: { width: 0 },
majorTickLines: { width: 0 },
lineStyle: { width: 0 },
labelStyle: { color: 'transparent' },
}} chartArea={{ border: { width: 0 } }} tooltip={{ enable: true }} title="Olympics Medal Tally">
<Inject services={[BarSeries, Legend, Tooltip, Category, DataLabel]}/>
<SeriesCollectionDirective>
<SeriesDirective dataSource={data1} xName="x" yName="y" name="USA Total" type="Bar" groupName="USA" columnWidth={0.7} columnSpacing={0.1} marker={{
dataLabel: {
visible: true,
position: 'Top',
font: { fontWeight: '600', color: '#ffffff' },
},
}}></SeriesDirective>
<SeriesDirective dataSource={data2} xName="x" yName="y" name="USA Gold" type="Bar" groupName="USA" columnWidth={0.5} columnSpacing={0.1} marker={{
dataLabel: {
visible: true,
position: 'Top',
font: { fontWeight: '600', color: '#ffffff' },
},
}}></SeriesDirective>
<SeriesDirective dataSource={data3} xName="x" yName="y" name="UK Total" type="Bar" groupName="UK" columnWidth={0.7} columnSpacing={0.1} marker={{
dataLabel: {
visible: true,
position: 'Top',
font: { fontWeight: '600', color: '#ffffff' },
},
}}></SeriesDirective>
<SeriesDirective dataSource={data4} xName="x" yName="y" name="UK Gold" type="Bar" groupName="UK" columnWidth={0.5} columnSpacing={0.1} marker={{
dataLabel: {
visible: true,
position: 'Top',
font: { fontWeight: '600', color: '#ffffff' },
},
}}></SeriesDirective>
<SeriesDirective dataSource={data5} xName="x" yName="y" name="China Total" type="Bar" groupName="China" columnWidth={0.7} columnSpacing={0.1} marker={{
dataLabel: {
visible: true,
position: 'Top',
font: { fontWeight: '600', color: '#ffffff' },
},
}}></SeriesDirective>
<SeriesDirective dataSource={data6} xName="x" yName="y" name="China Gold" type="Bar" groupName="China" columnWidth={0.5} columnSpacing={0.1} marker={{
dataLabel: {
visible: true,
position: 'Top',
font: { fontWeight: '600', color: '#ffffff' },
},
}}></SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>);
}
;
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));
import * as React from "react";
import * as ReactDOM from "react-dom";
import {
ChartComponent,
SeriesCollectionDirective,
SeriesDirective,
Inject,
Legend,
Category,
Tooltip,
BarSeries,
DataLabel }
from'@syncfusion/ej2-react-charts';
import { data1, data2, data3, data4, data5, data6 } from './datasource';
function App() {
return (
<ChartComponent
id="charts"
style={{ textAlign: 'center' }}
primaryXAxis={{
valueType: 'Category',
interval: 1,
majorGridLines: { width: 0 },
}}
primaryYAxis={{
majorGridLines: { width: 0 },
majorTickLines: { width: 0 },
lineStyle: { width: 0 },
labelStyle: { color: 'transparent' },
}}
chartArea={{ border: { width: 0 } }}
tooltip={{ enable: true }}
title="Olympics Medal Tally"
>
<Inject
services={[BarSeries, Legend, Tooltip, Category, DataLabel]}
/>
<SeriesCollectionDirective>
<SeriesDirective
dataSource={data1}
xName="x"
yName="y"
name="USA Total"
type="Bar"
groupName="USA"
columnWidth={0.7}
columnSpacing={0.1}
marker={{
dataLabel: {
visible: true,
position: 'Top',
font: { fontWeight: '600', color: '#ffffff' },
},
}}
></SeriesDirective>
<SeriesDirective
dataSource={data2}
xName="x"
yName="y"
name="USA Gold"
type="Bar"
groupName="USA"
columnWidth={0.5}
columnSpacing={0.1}
marker={{
dataLabel: {
visible: true,
position: 'Top',
font: { fontWeight: '600', color: '#ffffff' },
},
}}
></SeriesDirective>
<SeriesDirective
dataSource={data3}
xName="x"
yName="y"
name="UK Total"
type="Bar"
groupName="UK"
columnWidth={0.7}
columnSpacing={0.1}
marker={{
dataLabel: {
visible: true,
position: 'Top',
font: { fontWeight: '600', color: '#ffffff' },
},
}}
></SeriesDirective>
<SeriesDirective
dataSource={data4}
xName="x"
yName="y"
name="UK Gold"
type="Bar"
groupName="UK"
columnWidth={0.5}
columnSpacing={0.1}
marker={{
dataLabel: {
visible: true,
position: 'Top',
font: { fontWeight: '600', color: '#ffffff' },
},
}}
></SeriesDirective>
<SeriesDirective
dataSource={data5}
xName="x"
yName="y"
name="China Total"
type="Bar"
groupName="China"
columnWidth={0.7}
columnSpacing={0.1}
marker={{
dataLabel: {
visible: true,
position: 'Top',
font: { fontWeight: '600', color: '#ffffff' },
},
}}
></SeriesDirective>
<SeriesDirective
dataSource={data6}
xName="x"
yName="y"
name="China Gold"
type="Bar"
groupName="China"
columnWidth={0.5}
columnSpacing={0.1}
marker={{
dataLabel: {
visible: true,
position: 'Top',
font: { fontWeight: '600', color: '#ffffff' },
},
}}
></SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>
);
};
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));
export let data1 = [
{ x: '2012', y: 104 },
{ x: '2016', y: 121 },
{ x: '2020', y: 113 }
];
export let data2 = [
{ x: '2012', y: 46 },
{ x: '2016', y: 46 },
{ x: '2020', y: 39 }
];
export let data3 = [
{ x: '2012', y: 65 },
{ x: '2016', y: 67 },
{ x: '2020', y: 65 }
];
export let data4 = [
{ x: '2012', y: 29 },
{ x: '2016', y: 27 },
{ x: '2020', y: 22 }
];
export let data5 = [
{ x: '2012', y: 91 },
{ x: '2016', y: 70 },
{ x: '2020', y: 88 }
];
export let data6 = [
{ x: '2012', y: 38 },
{ x: '2016', y: 26 },
{ x: '2020', y: 38 }
];
export let data1: Object[] = [
{ x: '2012', y: 104 },
{ x: '2016', y: 121 },
{ x: '2020', y: 113 }
];
export let data2: Object[] = [
{ x: '2012', y: 46 },
{ x: '2016', y: 46 },
{ x: '2020', y: 39 }
];
export let data3: Object[] = [
{ x: '2012', y: 65 },
{ x: '2016', y: 67 },
{ x: '2020', y: 65 }
];
export let data4: Object[] = [
{ x: '2012', y: 29 },
{ x: '2016', y: 27 },
{ x: '2020', y: 22 }
];
export let data5: Object[] = [
{ x: '2012', y: 91 },
{ x: '2016', y: 70 },
{ x: '2020', y: 88 }
];
export let data6: Object[] = [
{ x: '2012', y: 38 },
{ x: '2016', y: 26 },
{ x: '2020', y: 38 }
];
Cylindrical bar chart
To render a cylindrical bar chart, set the columnFacet
property to Cylinder
in the chart series. This property transforms the regular bars into cylindrical shapes, enhancing the visual representation of the data.
import * as React from "react";
import * as ReactDOM from "react-dom";
import { ChartComponent, SeriesCollectionDirective, SeriesDirective, Inject, Legend, Category, Tooltip, DataLabel, BarSeries } from '@syncfusion/ej2-react-charts';
import { cylindricalData } from './datasource';
function App() {
const primaryxAxis = { minimum: 2005, maximum: 2012, interval: 1 };
const primaryyAxis = {
minimum: 3,
maximum: 12,
interval: 1,
title: 'Percentage'
};
return <ChartComponent id='charts' primaryXAxis={primaryxAxis} primaryYAxis={primaryyAxis} title='Unemployment rate in percentage'>
<Inject services={[BarSeries, Legend, Tooltip, DataLabel, Category]}/>
<SeriesCollectionDirective>
<SeriesDirective dataSource={cylindricalData} xName='x' yName='y' name='India' type='Bar' columnFacet='Cylinder'>
</SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>;
}
;
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));
import * as React from "react";
import * as ReactDOM from "react-dom";
import { AxisModel, ChartComponent, SeriesCollectionDirective, SeriesDirective, Inject,
Legend, Category, Tooltip, DataLabel, Zoom, Crosshair, BarSeries, Selection}
from'@syncfusion/ej2-react-charts';
import { cylindricalData } from './datasource';
function App() {
const primaryxAxis: AxisModel = { minimum: 2005, maximum: 2012, interval: 1 };
const primaryyAxis: AxisModel = {
minimum: 3,
maximum: 12,
interval: 1,
title: 'Percentage'
};
return <ChartComponent id='charts'
primaryXAxis={primaryxAxis}
primaryYAxis={primaryyAxis}
title='Unemployment rate in percentage'>
<Inject services={[BarSeries, Legend, Tooltip, DataLabel, Category]} />
<SeriesCollectionDirective>
<SeriesDirective dataSource={cylindricalData} xName='x' yName='y' name='India' type='Bar' columnFacet='Cylinder'>
</SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>
};
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));
export let cylindricalData = [
{ x: 2006, y: 9 },
{ x: 2007, y: 7.8 },
{ x: 2008, y: 10.5 },
{ x: 2009, y: 8.4 },
{ x: 2010, y: 6 },
{ x: 2011, y: 11 }
];
export let cylindricalData: Object[] = [
{ x: 2006, y: 9 },
{ x: 2007, y: 7.8 },
{ x: 2008, y: 10.5 },
{ x: 2009, y: 8.4 },
{ x: 2010, y: 6 },
{ x: 2011, y: 11 }
];
Empty points
Data points with null
or undefined
values are considered empty. Empty data points are ignored and not plotted on the chart.
Mode
Use the mode
property to define how empty or missing data points are handled in the series. The default mode for empty points is Gap
.
import * as React from "react";
import * as ReactDOM from "react-dom";
import { ChartComponent, SeriesCollectionDirective, SeriesDirective, Inject, Legend, Category, Tooltip, DataLabel, BarSeries } from '@syncfusion/ej2-react-charts';
import { customData } from './datasource';
function App() {
const primaryxAxis = { minimum: 2005, maximum: 2012, interval: 1, title: 'Year' };
const primaryyAxis = {
minimum: 3, maximum: 12, interval: 1, title: 'Percentage',
labelFormat: '{value}%'
};
const emptyPoint = {
mode: 'Gap',
};
return <ChartComponent id='charts' primaryXAxis={primaryxAxis} primaryYAxis={primaryyAxis} title='Unemployment rate (%)'>
<Inject services={[BarSeries, Legend, Tooltip, DataLabel, Category]}/>
<SeriesCollectionDirective>
<SeriesDirective dataSource={customData} xName='x' yName='y' type='Bar' emptyPointSettings={emptyPoint}>
</SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>;
}
;
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));
import * as React from "react";
import * as ReactDOM from "react-dom";
import { AxisModel, ChartComponent, SeriesCollectionDirective, SeriesDirective, Inject,
Legend, Category, Tooltip, DataLabel, Zoom, Crosshair, BarSeries, Selection}
from'@syncfusion/ej2-react-charts';
import { customData } from './datasource';
function App() {
const primaryxAxis: AxisModel = { minimum: 2005, maximum: 2012, interval: 1, title: 'Year' };
const primaryyAxis: AxisModel = {
minimum: 3, maximum: 12, interval: 1, title: 'Percentage',
labelFormat: '{value}%'
};
const emptyPoint: Object = {
mode: 'Gap',
};
return <ChartComponent id='charts'
primaryXAxis={primaryxAxis}
primaryYAxis={primaryyAxis}
title='Unemployment rate (%)'>
<Inject services={[BarSeries, Legend, Tooltip, DataLabel, Category]} />
<SeriesCollectionDirective>
<SeriesDirective dataSource={customData} xName='x' yName='y' type='Bar' emptyPointSettings={emptyPoint}>
</SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>
};
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));
export let customData = [
{ x: 2006, y: 7.8, point: 'red' },
{ x: 2007, y: 7.2, point: 'green' },
{ x: 2008, y: null, point: 'orange' },
{ x: 2009, y: 10.7, point: 'yellow' },
{ x: 2010, y: 10.8, point: 'grey' },
{ x: 2011, y: 9.8, point: 'blue' }
];
export let customData: Object[] = [
{ x: 2006, y: 7.8, point: 'red' },
{ x: 2007, y: 7.2, point: 'green' },
{ x: 2008, y: null, point: 'orange' },
{ x: 2009, y: 10.7, point: 'yellow' },
{ x: 2010, y: 10.8, point: 'grey' },
{ x: 2011, y: 9.8, point: 'blue' }
];
Fill
Use the fill
property to customize the fill color of empty points in the series.
import * as React from "react";
import * as ReactDOM from "react-dom";
import { ChartComponent, SeriesCollectionDirective, SeriesDirective, Inject, Legend, Category, Tooltip, DataLabel, BarSeries } from '@syncfusion/ej2-react-charts';
import { customData } from './datasource';
function App() {
const primaryxAxis = { minimum: 2005, maximum: 2012, interval: 1, title: 'Year' };
const primaryyAxis = {
minimum: 3, maximum: 12, interval: 1, title: 'Percentage',
labelFormat: '{value}%'
};
const emptyPoint = {
mode: 'Average', fill: 'red'
};
return <ChartComponent id='charts' primaryXAxis={primaryxAxis} primaryYAxis={primaryyAxis} title='Unemployment rate (%)'>
<Inject services={[BarSeries, Legend, Tooltip, DataLabel, Category]}/>
<SeriesCollectionDirective>
<SeriesDirective dataSource={customData} xName='x' yName='y' type='Bar' emptyPointSettings={emptyPoint}>
</SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>;
}
;
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));
import * as React from "react";
import * as ReactDOM from "react-dom";
import { AxisModel, ChartComponent, SeriesCollectionDirective, SeriesDirective, Inject,
Legend, Category, Tooltip, DataLabel, Zoom, Crosshair, BarSeries, Selection}
from'@syncfusion/ej2-react-charts';
import { customData } from './datasource';
function App() {
const primaryxAxis: AxisModel = { minimum: 2005, maximum: 2012, interval: 1, title: 'Year' };
const primaryyAxis: AxisModel = {
minimum: 3, maximum: 12, interval: 1, title: 'Percentage',
labelFormat: '{value}%'
};
const emptyPoint: Object = {
mode: 'Average', fill: 'red'
};
return <ChartComponent id='charts'
primaryXAxis={primaryxAxis}
primaryYAxis={primaryyAxis}
title='Unemployment rate (%)'>
<Inject services={[BarSeries, Legend, Tooltip, DataLabel, Category]} />
<SeriesCollectionDirective>
<SeriesDirective dataSource={customData} xName='x' yName='y' type='Bar' emptyPointSettings={emptyPoint}>
</SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>
};
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));
export let customData = [
{ x: 2006, y: 7.8, point: 'red' },
{ x: 2007, y: 7.2, point: 'green' },
{ x: 2008, y: null, point: 'orange' },
{ x: 2009, y: 10.7, point: 'yellow' },
{ x: 2010, y: 10.8, point: 'grey' },
{ x: 2011, y: 9.8, point: 'blue' }
];
export let customData: Object[] = [
{ x: 2006, y: 7.8, point: 'red' },
{ x: 2007, y: 7.2, point: 'green' },
{ x: 2008, y: null, point: 'orange' },
{ x: 2009, y: 10.7, point: 'yellow' },
{ x: 2010, y: 10.8, point: 'grey' },
{ x: 2011, y: 9.8, point: 'blue' }
];
Border
Use the border
property to customize the width and color of the border for empty points.
import * as React from "react";
import * as ReactDOM from "react-dom";
import { ChartComponent, SeriesCollectionDirective, SeriesDirective, Inject, Legend, Category, Tooltip, DataLabel, BarSeries } from '@syncfusion/ej2-react-charts';
import { customData } from './datasource';
function App() {
const primaryxAxis = { minimum: 2005, maximum: 2012, interval: 1, title: 'Year' };
const primaryyAxis = {
minimum: 3, maximum: 12, interval: 1, title: 'Percentage',
labelFormat: '{value}%'
};
const emptyPoint = {
mode: 'Average', fill: 'red', border: {width:1.5, color: 'black'}
};
return <ChartComponent id='charts' primaryXAxis={primaryxAxis} primaryYAxis={primaryyAxis} title='Unemployment rate (%)'>
<Inject services={[BarSeries, Legend, Tooltip, DataLabel, Category]}/>
<SeriesCollectionDirective>
<SeriesDirective dataSource={customData} xName='x' yName='y' type='Bar' emptyPointSettings={emptyPoint}>
</SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>;
}
;
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));
import * as React from "react";
import * as ReactDOM from "react-dom";
import { AxisModel, ChartComponent, SeriesCollectionDirective, SeriesDirective, Inject,
Legend, Category, Tooltip, DataLabel, Zoom, Crosshair, BarSeries, Selection}
from'@syncfusion/ej2-react-charts';
import { customData } from './datasource';
function App() {
const primaryxAxis: AxisModel = { minimum: 2005, maximum: 2012, interval: 1, title: 'Year' };
const primaryyAxis: AxisModel = {
minimum: 3, maximum: 12, interval: 1, title: 'Percentage',
labelFormat: '{value}%'
};
const emptyPoint: Object = {
mode: 'Average', fill: 'red', border: {width:1.5, color: 'black'}
};
return <ChartComponent id='charts'
primaryXAxis={primaryxAxis}
primaryYAxis={primaryyAxis}
title='Unemployment rate (%)'>
<Inject services={[BarSeries, Legend, Tooltip, DataLabel, Category]} />
<SeriesCollectionDirective>
<SeriesDirective dataSource={customData} xName='x' yName='y' type='Bar' emptyPointSettings={emptyPoint}>
</SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>
};
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));
export let customData = [
{ x: 2006, y: 7.8, point: 'red' },
{ x: 2007, y: 7.2, point: 'green' },
{ x: 2008, y: null, point: 'orange' },
{ x: 2009, y: 10.7, point: 'yellow' },
{ x: 2010, y: 10.8, point: 'grey' },
{ x: 2011, y: 9.8, point: 'blue' }
];
export let customData: Object[] = [
{ x: 2006, y: 7.8, point: 'red' },
{ x: 2007, y: 7.2, point: 'green' },
{ x: 2008, y: null, point: 'orange' },
{ x: 2009, y: 10.7, point: 'yellow' },
{ x: 2010, y: 10.8, point: 'grey' },
{ x: 2011, y: 9.8, point: 'blue' }
];
Events
Series render
The seriesRender
event allows you to customize series properties, such as data, fill, and name, before they are rendered on the chart.
import * as React from "react";
import * as ReactDOM from "react-dom";
import { ChartComponent, SeriesCollectionDirective, SeriesDirective, Inject, Legend, Category, Tooltip, DataLabel, BarSeries } from '@syncfusion/ej2-react-charts';
import { customData } from './datasource';
function App() {
const primaryxAxis = { minimum: 2005, maximum: 2012, interval: 1, title: 'Year' };
const primaryyAxis = {
minimum: 3, maximum: 12, interval: 1, title: 'Percentage',
labelFormat: '{value}%'
};
const seriesRender = (args) => {
args.fill = '#ff6347';
};
return <ChartComponent id='charts' primaryXAxis={primaryxAxis} primaryYAxis={primaryyAxis} title='Unemployment rate (%)' seriesRender={seriesRender}>
<Inject services={[BarSeries, Legend, Tooltip, DataLabel, Category]} />
<SeriesCollectionDirective>
<SeriesDirective dataSource={customData} xName='x' yName='y' type='Bar'>
</SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>;
}
;
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));
import * as React from "react";
import * as ReactDOM from "react-dom";
import { AxisModel, ChartComponent, SeriesCollectionDirective, SeriesDirective, Inject,
Legend, Category, Tooltip, DataLabel, Zoom, Crosshair, BarSeries, Selection, ISeriesRenderEventArgs}
from'@syncfusion/ej2-react-charts';
import { customData } from './datasource';
import { EmitType } from '@syncfusion/ej2-base';
function App() {
const primaryxAxis: AxisModel = { minimum: 2005, maximum: 2012, interval: 1, title: 'Year' };
const primaryyAxis: AxisModel = {
minimum: 3, maximum: 12, interval: 1, title: 'Percentage',
labelFormat: '{value}%'
};
const seriesRender: EmitType<ISeriesRenderEventArgs> = (args: ISeriesRenderEventArgs): void => {
args.fill = '#ff6347';
};
return <ChartComponent id='charts'
primaryXAxis={primaryxAxis}
primaryYAxis={primaryyAxis}
title='Unemployment rate (%)' seriesRender={seriesRender}>
<Inject services={[BarSeries, Legend, Tooltip, DataLabel, Category]} />
<SeriesCollectionDirective>
<SeriesDirective dataSource={customData} xName='x' yName='y' type='Bar'>
</SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>
};
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));
export let customData = [
{ x: 2006, y: 7.8, point: 'red' },
{ x: 2007, y: 7.2, point: 'green' },
{ x: 2008, y: 8, point: 'orange' },
{ x: 2009, y: 10.7, point: 'yellow' },
{ x: 2010, y: 10.8, point: 'grey' },
{ x: 2011, y: 9.8, point: 'blue' }
];
export let customData: Object[] = [
{ x: 2006, y: 7.8, point: 'red' },
{ x: 2007, y: 7.2, point: 'green' },
{ x: 2008, y: 8, point: 'orange' },
{ x: 2009, y: 10.7, point: 'yellow' },
{ x: 2010, y: 10.8, point: 'grey' },
{ x: 2011, y: 9.8, point: 'blue' }
];
Point render
The pointRender
event allows you to customize each data point before it is rendered on the chart.
import * as React from "react";
import * as ReactDOM from "react-dom";
import { ChartComponent, SeriesCollectionDirective, SeriesDirective, Inject, Legend, Category, Tooltip, DataLabel, BarSeries } from '@syncfusion/ej2-react-charts';
import { customData } from './datasource';
function App() {
const primaryxAxis = { minimum: 2005, maximum: 2012, interval: 1, title: 'Year' };
const primaryyAxis = {
minimum: 3, maximum: 12, interval: 1, title: 'Percentage',
labelFormat: '{value}%'
};
export let pointRender = (args) => {
if (args.point.y < 7.5) {
args.fill = '#ff6347';
} else {
args.fill = '#009cb8';
}
};
return <ChartComponent id='charts' primaryXAxis={primaryxAxis} primaryYAxis={primaryyAxis} title='Unemployment rate (%)' pointRender={pointRender}>
<Inject services={[BarSeries, Legend, Tooltip, DataLabel, Category]}/>
<SeriesCollectionDirective>
<SeriesDirective dataSource={customData} xName='x' yName='y' type='Bar'>
</SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>;
}
;
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));
import * as React from "react";
import * as ReactDOM from "react-dom";
import { AxisModel, ChartComponent, SeriesCollectionDirective, SeriesDirective, Inject,
Legend, Category, Tooltip, DataLabel, Zoom, Crosshair, BarSeries, Selection, IPointRenderEventArgs}
from'@syncfusion/ej2-react-charts';
import { customData } from './datasource';
import { EmitType } from '@syncfusion/ej2-base';
function App() {
const primaryxAxis: AxisModel = { minimum: 2005, maximum: 2012, interval: 1, title: 'Year' };
const primaryyAxis: AxisModel = {
minimum: 3, maximum: 12, interval: 1, title: 'Percentage',
labelFormat: '{value}%'
};
const pointRender: EmitType<IPointRenderEventArgs> = (args: IPointRenderEventArgs): void => {
if (args.point.y < 7.5) {
args.fill = '#ff6347';
} else {
args.fill = '#009cb8';
}
};
return <ChartComponent id='charts'
primaryXAxis={primaryxAxis}
primaryYAxis={primaryyAxis}
title='Unemployment rate (%)'
pointRender={pointRender}>
<Inject services={[BarSeries, Legend, Tooltip, DataLabel, Category]} />
<SeriesCollectionDirective>
<SeriesDirective dataSource={customData} xName='x' yName='y' type='Bar'>
</SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>
};
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));
export let customData = [
{ x: 2006, y: 7.8, point: 'red' },
{ x: 2007, y: 7.2, point: 'green' },
{ x: 2008, y: 8, point: 'orange' },
{ x: 2009, y: 10.7, point: 'yellow' },
{ x: 2010, y: 10.8, point: 'grey' },
{ x: 2011, y: 9.8, point: 'blue' }
];
export let customData: Object[] = [
{ x: 2006, y: 7.8, point: 'red' },
{ x: 2007, y: 7.2, point: 'green' },
{ x: 2008, y: 8, point: 'orange' },
{ x: 2009, y: 10.7, point: 'yellow' },
{ x: 2010, y: 10.8, point: 'grey' },
{ x: 2011, y: 9.8, point: 'blue' }
];