Stacked Bar Chart in React Chart
17 Aug 202624 minutes to read
Stacked bar
Follow these steps to render a stacked bar series, which stacks multiple bar series vertically within each category to compare segment contributions across categories. To display proportional totals (100%), use StackingBar100 with the same configuration.
-
Set the series type: Set the series
typetoStackingBarin the series configuration. -
Inject the StackingBarSeries module: Add
StackingBarSeriesto theservicesarray of theInjectcomponent insideChartComponent. This registers the functionality required to render a stacked bar series.
import * as React from "react";
import * as ReactDOM from "react-dom";
import { ChartComponent, SeriesCollectionDirective, SeriesDirective, Inject, Legend, Category, Tooltip, DataLabel, StackingBarSeries } from '@syncfusion/ej2-react-charts';
import { stackBarData } from './datasource';
function App() {
const primaryxAxis = { valueType: 'Category', title: 'Months' };
const primaryyAxis = {
title: 'Percentage (%)', minimum: -20, maximum: 100,
edgeLabelPlacement: 'Shift', labelFormat: '{value}%'
};
return <ChartComponent id='charts' primaryXAxis={primaryxAxis} primaryYAxis={primaryyAxis} title='Sales Comparison'>
<Inject services={[StackingBarSeries, Legend, Tooltip, DataLabel, Category]}/>
<SeriesCollectionDirective>
<SeriesDirective dataSource={stackBarData} xName='x' yName='y' name='Apple' type='StackingBar'>
</SeriesDirective>
<SeriesDirective dataSource={stackBarData} xName='x' yName='y1' name='orange' type='StackingBar'>
</SeriesDirective>
<SeriesDirective dataSource={stackBarData} xName='x' yName='y2' name='Wastage' type='StackingBar'>
</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, StackingBarSeries, Selection}
from'@syncfusion/ej2-react-charts';
import { stackBarData } from './datasource';
function App() {
const primaryxAxis: AxisModel = { valueType: 'Category', title: 'Months' };
const primaryyAxis: AxisModel = {
title: 'Percentage (%)', minimum: -20, maximum: 100,
edgeLabelPlacement: 'Shift', labelFormat: '{value}%'
};
return <ChartComponent id='charts'
primaryXAxis={primaryxAxis}
primaryYAxis={primaryyAxis}
title='Sales Comparison'>
<Inject services={[StackingBarSeries, Legend, Tooltip, DataLabel, Category]} />
<SeriesCollectionDirective>
<SeriesDirective dataSource={stackBarData} xName='x' yName='y' name='Apple' type='StackingBar'>
</SeriesDirective>
<SeriesDirective dataSource={stackBarData} xName='x' yName='y1' name='orange' type='StackingBar'>
</SeriesDirective>
<SeriesDirective dataSource={stackBarData} xName='x' yName='y2' name='Wastage' type='StackingBar'>
</SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>
};
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));export let stackBarData = [
{ x: 'Jan', y: 6, y1: 6, y2: -1 }, { x: 'Feb', y: 8 , y1: 8, y2: -1.5 },
{ x: 'Mar', y: 12, y1: 11, y2: -2 }, { x: 'Apr', y: 15, y1: 16, y2: -2.5 },
{ x: 'May', y: 20, y1: 21, y2: -3 }, { x: 'Jun', y: 24, y1: 25, y2: -3.5 },
{ x: 'Jul', y: 28, y1: 27, y2: -4 }, { x: 'Aug', y: 32, y1: 31, y2: -4.5 },
{ x: 'Sep', y: 33, y1: 34, y2: -5 }, { x: 'Oct', y: 35, y1: 34, y2: -5.5 },
{ x: 'Nov', y: 40, y1: 41, y2: -6 }, { x: 'Dec', y: 42, y1: 42, y2: -6.5 }
];export let stackBarData: Object[] = [
{ x: 'Jan', y: 6, y1: 6, y2: -1 }, { x: 'Feb', y: 8 , y1: 8, y2: -1.5 },
{ x: 'Mar', y: 12, y1: 11, y2: -2 }, { x: 'Apr', y: 15, y1: 16, y2: -2.5 },
{ x: 'May', y: 20, y1: 21, y2: -3 }, { x: 'Jun', y: 24, y1: 25, y2: -3.5 },
{ x: 'Jul', y: 28, y1: 27, y2: -4 }, { x: 'Aug', y: 32, y1: 31, y2: -4.5 },
{ x: 'Sep', y: 33, y1: 34, y2: -5 }, { x: 'Oct', y: 35, y1: 34, y2: -5.5 },
{ x: 'Nov', y: 40, y1: 41, y2: -6 }, { x: 'Dec', y: 42, y1: 42, y2: -6.5 }
];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, StackingBarSeries } from '@syncfusion/ej2-react-charts';
import { stackBarData } from './datasource';
function App() {
const primaryxAxis = { valueType: 'Category', title: 'Months' };
const primaryyAxis = {
title: 'Percentage (%)', minimum: -20, maximum: 100,
edgeLabelPlacement: 'Shift', labelFormat: '{value}%'
};
return <ChartComponent id='charts' primaryXAxis={primaryxAxis} primaryYAxis={primaryyAxis} title='Sales Comparison'>
<Inject services={[StackingBarSeries, Legend, Tooltip, DataLabel, Category]}/>
<SeriesCollectionDirective>
<SeriesDirective dataSource={stackBarData} xName='x' yName='y' name='Apple' type='StackingBar'>
</SeriesDirective>
<SeriesDirective dataSource={stackBarData} xName='x' yName='y1' name='orange' type='StackingBar'>
</SeriesDirective>
<SeriesDirective dataSource={stackBarData} xName='x' yName='y2' name='Wastage' type='StackingBar'>
</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, StackingBarSeries, Selection}
from'@syncfusion/ej2-react-charts';
import { stackBarData } from './datasource';
function App() {
const primaryxAxis: AxisModel = { valueType: 'Category', title: 'Months' };
const primaryyAxis: AxisModel = {
title: 'Percentage (%)', minimum: -20, maximum: 100,
edgeLabelPlacement: 'Shift', labelFormat: '{value}%'
};
return <ChartComponent id='charts'
primaryXAxis={primaryxAxis}
primaryYAxis={primaryyAxis}
title='Sales Comparison'>
<Inject services={[StackingBarSeries, Legend, Tooltip, DataLabel, Category]} />
<SeriesCollectionDirective>
<SeriesDirective dataSource={stackBarData} xName='x' yName='y' name='Apple' type='StackingBar'>
</SeriesDirective>
<SeriesDirective dataSource={stackBarData} xName='x' yName='y1' name='orange' type='StackingBar'>
</SeriesDirective>
<SeriesDirective dataSource={stackBarData} xName='x' yName='y2' name='Wastage' type='StackingBar'>
</SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>
};
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));export let stackBarData = [
{ x: 'Jan', y: 6, y1: 6, y2: -1 }, { x: 'Feb', y: 8 , y1: 8, y2: -1.5 },
{ x: 'Mar', y: 12, y1: 11, y2: -2 }, { x: 'Apr', y: 15, y1: 16, y2: -2.5 },
{ x: 'May', y: 20, y1: 21, y2: -3 }, { x: 'Jun', y: 24, y1: 25, y2: -3.5 },
{ x: 'Jul', y: 28, y1: 27, y2: -4 }, { x: 'Aug', y: 32, y1: 31, y2: -4.5 },
{ x: 'Sep', y: 33, y1: 34, y2: -5 }, { x: 'Oct', y: 35, y1: 34, y2: -5.5 },
{ x: 'Nov', y: 40, y1: 41, y2: -6 }, { x: 'Dec', y: 42, y1: 42, y2: -6.5 }
];export let stackBarData: Object[] = [
{ x: 'Jan', y: 6, y1: 6, y2: -1 }, { x: 'Feb', y: 8 , y1: 8, y2: -1.5 },
{ x: 'Mar', y: 12, y1: 11, y2: -2 }, { x: 'Apr', y: 15, y1: 16, y2: -2.5 },
{ x: 'May', y: 20, y1: 21, y2: -3 }, { x: 'Jun', y: 24, y1: 25, y2: -3.5 },
{ x: 'Jul', y: 28, y1: 27, y2: -4 }, { x: 'Aug', y: 32, y1: 31, y2: -4.5 },
{ x: 'Sep', y: 33, y1: 34, y2: -5 }, { x: 'Oct', y: 35, y1: 34, y2: -5.5 },
{ x: 'Nov', y: 40, y1: 41, y2: -6 }, { x: 'Dec', y: 42, y1: 42, y2: -6.5 }
];Series customization
Customize the stacked bar series appearance with the following properties. Defaults are taken from the standard Series model.
| Property | Type | Default | Description |
|---|---|---|---|
fill |
string | null |
Color applied to the series. Accepts a CSS color or a gradient reference. |
opacity |
number | 1 |
Transparency of the fill (0 to 1). |
border |
BorderModel |
null |
Border settings: width, color, and dashArray. |
cornerRadius |
CornerRadiusModel |
null |
Per-corner radius for the stacked bar segments (topLeft, topRight, bottomLeft, bottomRight). |
Solid 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, StackingBarSeries } from '@syncfusion/ej2-react-charts';
import { stackBarData } from './datasource';
function App() {
const primaryxAxis = { valueType: 'Category', title: 'Months' };
const primaryyAxis = {
title: 'Percentage (%)', minimum: -20, maximum: 100,
edgeLabelPlacement: 'Shift', labelFormat: '{value}%'
};
return <ChartComponent id='charts' primaryXAxis={primaryxAxis} primaryYAxis={primaryyAxis} title='Sales Comparison'>
<Inject services={[StackingBarSeries, Legend, Tooltip, DataLabel, Category]}/>
<SeriesCollectionDirective>
<SeriesDirective dataSource={stackBarData} xName='x' yName='y' dashArray='5' type='StackingBar' fill='brown'>
</SeriesDirective>
<SeriesDirective dataSource={stackBarData} xName='x' yName='y1' dashArray='5' type='StackingBar' fill='grey'>
</SeriesDirective>
<SeriesDirective dataSource={stackBarData} xName='x' yName='y2' dashArray='5' type='StackingBar' fill='yellow'>
</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, StackingBarSeries, Selection}
from'@syncfusion/ej2-react-charts';
import { stackBarData } from './datasource';
function App() {
const primaryxAxis: AxisModel = { valueType: 'Category', title: 'Months' };
const primaryyAxis: AxisModel = {
title: 'Percentage (%)', minimum: -20, maximum: 100,
edgeLabelPlacement: 'Shift', labelFormat: '{value}%'
};
return <ChartComponent id='charts'
primaryXAxis={primaryxAxis}
primaryYAxis={primaryyAxis}
title='Sales Comparison'>
<Inject services={[StackingBarSeries, Legend, Tooltip, DataLabel, Category]} />
<SeriesCollectionDirective>
<SeriesDirective dataSource={stackBarData} xName='x' yName='y' dashArray='5' type='StackingBar' fill='brown'>
</SeriesDirective>
<SeriesDirective dataSource={stackBarData} xName='x' yName='y1' dashArray='5' type='StackingBar' fill='grey'>
</SeriesDirective>
<SeriesDirective dataSource={stackBarData} xName='x' yName='y2' dashArray='5' type='StackingBar' fill='yellow'>
</SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>
};
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));export let stackBarData = [
{ x: 'Jan', y: 6, y1: 6, y2: -1 }, { x: 'Feb', y: 8 , y1: 8, y2: -1.5 },
{ x: 'Mar', y: 12, y1: 11, y2: -2 }, { x: 'Apr', y: 15, y1: 16, y2: -2.5 },
{ x: 'May', y: 20, y1: 21, y2: -3 }, { x: 'Jun', y: 24, y1: 25, y2: -3.5 },
{ x: 'Jul', y: 28, y1: 27, y2: -4 }, { x: 'Aug', y: 32, y1: 31, y2: -4.5 },
{ x: 'Sep', y: 33, y1: 34, y2: -5 }, { x: 'Oct', y: 35, y1: 34, y2: -5.5 },
{ x: 'Nov', y: 40, y1: 41, y2: -6 }, { x: 'Dec', y: 42, y1: 42, y2: -6.5 }
];export let stackBarData: Object[] = [
{ x: 'Jan', y: 6, y1: 6, y2: -1 }, { x: 'Feb', y: 8 , y1: 8, y2: -1.5 },
{ x: 'Mar', y: 12, y1: 11, y2: -2 }, { x: 'Apr', y: 15, y1: 16, y2: -2.5 },
{ x: 'May', y: 20, y1: 21, y2: -3 }, { x: 'Jun', y: 24, y1: 25, y2: -3.5 },
{ x: 'Jul', y: 28, y1: 27, y2: -4 }, { x: 'Aug', y: 32, y1: 31, y2: -4.5 },
{ x: 'Sep', y: 33, y1: 34, y2: -5 }, { x: 'Oct', y: 35, y1: 34, y2: -5.5 },
{ x: 'Nov', y: 40, y1: 41, y2: -6 }, { x: 'Dec', y: 42, y1: 42, y2: -6.5 }
];Gradient fill
The fill property can be set to a CSS gradient reference such as url(#gradient) to apply a gradient color that transitions across the series. Define the gradient in an SVG <defs> block and reference it from the fill prop.
import * as React from "react";
import * as ReactDOM from "react-dom";
import { ChartComponent, SeriesCollectionDirective, SeriesDirective, Inject, Legend, Category, Tooltip, DataLabel, StackingBarSeries } from '@syncfusion/ej2-react-charts';
import { stackBarData } from './datasource';
function App() {
const primaryxAxis = { valueType: 'Category', title: 'Months' };
const primaryyAxis = {
title: 'Percentage (%)', minimum: -20, maximum: 100,
edgeLabelPlacement: 'Shift', labelFormat: '{value}%'
};
return <ChartComponent id='charts' primaryXAxis={primaryxAxis} primaryYAxis={primaryyAxis} title='Sales Comparison'>
<Inject services={[StackingBarSeries, Legend, Tooltip, DataLabel, Category]}/>
<SeriesCollectionDirective>
<SeriesDirective dataSource={stackBarData} xName='x' yName='y' dashArray='5' type='StackingBar' fill='url(#gradient1)'>
</SeriesDirective>
<SeriesDirective dataSource={stackBarData} xName='x' yName='y1' dashArray='5' type='StackingBar' fill='url(#gradient2)'>
</SeriesDirective>
<SeriesDirective dataSource={stackBarData} xName='x' yName='y2' dashArray='5' type='StackingBar' fill='url(#gradient3)'>
</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, StackingBarSeries, Selection}
from'@syncfusion/ej2-react-charts';
import { stackBarData } from './datasource';
function App() {
const primaryxAxis: AxisModel = { valueType: 'Category', title: 'Months' };
const primaryyAxis: AxisModel = {
title: 'Percentage (%)', minimum: -20, maximum: 100,
edgeLabelPlacement: 'Shift', labelFormat: '{value}%'
};
return <ChartComponent id='charts'
primaryXAxis={primaryxAxis}
primaryYAxis={primaryyAxis}
title='Sales Comparison'>
<Inject services={[StackingBarSeries, Legend, Tooltip, DataLabel, Category]} />
<SeriesCollectionDirective>
<SeriesDirective dataSource={stackBarData} xName='x' yName='y' dashArray='5' type='StackingBar' fill='url(#gradient1)'>
</SeriesDirective>
<SeriesDirective dataSource={stackBarData} xName='x' yName='y1' dashArray='5' type='StackingBar' fill='url(#gradient2)'>
</SeriesDirective>
<SeriesDirective dataSource={stackBarData} xName='x' yName='y2' dashArray='5' type='StackingBar' fill='url(#gradient3)'>
</SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>
};
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));export let stackBarData = [
{ x: 'Jan', y: 6, y1: 6, y2: -1 }, { x: 'Feb', y: 8 , y1: 8, y2: -1.5 },
{ x: 'Mar', y: 12, y1: 11, y2: -2 }, { x: 'Apr', y: 15, y1: 16, y2: -2.5 },
{ x: 'May', y: 20, y1: 21, y2: -3 }, { x: 'Jun', y: 24, y1: 25, y2: -3.5 },
{ x: 'Jul', y: 28, y1: 27, y2: -4 }, { x: 'Aug', y: 32, y1: 31, y2: -4.5 },
{ x: 'Sep', y: 33, y1: 34, y2: -5 }, { x: 'Oct', y: 35, y1: 34, y2: -5.5 },
{ x: 'Nov', y: 40, y1: 41, y2: -6 }, { x: 'Dec', y: 42, y1: 42, y2: -6.5 }
];export let stackBarData: Object[] = [
{ x: 'Jan', y: 6, y1: 6, y2: -1 }, { x: 'Feb', y: 8 , y1: 8, y2: -1.5 },
{ x: 'Mar', y: 12, y1: 11, y2: -2 }, { x: 'Apr', y: 15, y1: 16, y2: -2.5 },
{ x: 'May', y: 20, y1: 21, y2: -3 }, { x: 'Jun', y: 24, y1: 25, y2: -3.5 },
{ x: 'Jul', y: 28, y1: 27, y2: -4 }, { x: 'Aug', y: 32, y1: 31, y2: -4.5 },
{ x: 'Sep', y: 33, y1: 34, y2: -5 }, { x: 'Oct', y: 35, y1: 34, y2: -5.5 },
{ x: 'Nov', y: 40, y1: 41, y2: -6 }, { x: 'Dec', y: 42, y1: 42, y2: -6.5 }
];Opacity
The opacity property controls the transparency of the fill (0 to 1) and affects how the series blends with background or overlapping series.
import * as React from "react";
import * as ReactDOM from "react-dom";
import { ChartComponent, SeriesCollectionDirective, SeriesDirective, Inject, Legend, Category, Tooltip, DataLabel, StackingBarSeries } from '@syncfusion/ej2-react-charts';
import { stackBarData } from './datasource';
function App() {
const primaryxAxis = { valueType: 'Category', title: 'Months' };
const primaryyAxis = {
title: 'Percentage (%)', minimum: -20, maximum: 100,
edgeLabelPlacement: 'Shift', labelFormat: '{value}%'
};
return <ChartComponent id='charts' primaryXAxis={primaryxAxis} primaryYAxis={primaryyAxis} title='Sales Comparison'>
<Inject services={[StackingBarSeries, Legend, Tooltip, DataLabel, Category]}/>
<SeriesCollectionDirective>
<SeriesDirective dataSource={stackBarData} xName='x' yName='y' dashArray='5' type='StackingBar' opacity={0.5}>
</SeriesDirective>
<SeriesDirective dataSource={stackBarData} xName='x' yName='y1' dashArray='5' type='StackingBar' opacity={0.5}>
</SeriesDirective>
<SeriesDirective dataSource={stackBarData} xName='x' yName='y2' dashArray='5' type='StackingBar' 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, StackingBarSeries, Selection}
from'@syncfusion/ej2-react-charts';
import { stackBarData } from './datasource';
function App() {
const primaryxAxis: AxisModel = { valueType: 'Category', title: 'Months' };
const primaryyAxis: AxisModel = {
title: 'Percentage (%)', minimum: -20, maximum: 100,
edgeLabelPlacement: 'Shift', labelFormat: '{value}%'
};
return <ChartComponent id='charts'
primaryXAxis={primaryxAxis}
primaryYAxis={primaryyAxis}
title='Sales Comparison'>
<Inject services={[StackingBarSeries, Legend, Tooltip, DataLabel, Category]} />
<SeriesCollectionDirective>
<SeriesDirective dataSource={stackBarData} xName='x' yName='y' dashArray='5' type='StackingBar' opacity={0.5}>
</SeriesDirective>
<SeriesDirective dataSource={stackBarData} xName='x' yName='y1' dashArray='5' type='StackingBar' opacity={0.5}>
</SeriesDirective>
<SeriesDirective dataSource={stackBarData} xName='x' yName='y2' dashArray='5' type='StackingBar' opacity={0.5}>
</SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>
};
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));export let stackBarData = [
{ x: 'Jan', y: 6, y1: 6, y2: -1 }, { x: 'Feb', y: 8 , y1: 8, y2: -1.5 },
{ x: 'Mar', y: 12, y1: 11, y2: -2 }, { x: 'Apr', y: 15, y1: 16, y2: -2.5 },
{ x: 'May', y: 20, y1: 21, y2: -3 }, { x: 'Jun', y: 24, y1: 25, y2: -3.5 },
{ x: 'Jul', y: 28, y1: 27, y2: -4 }, { x: 'Aug', y: 32, y1: 31, y2: -4.5 },
{ x: 'Sep', y: 33, y1: 34, y2: -5 }, { x: 'Oct', y: 35, y1: 34, y2: -5.5 },
{ x: 'Nov', y: 40, y1: 41, y2: -6 }, { x: 'Dec', y: 42, y1: 42, y2: -6.5 }
];export let stackBarData: Object[] = [
{ x: 'Jan', y: 6, y1: 6, y2: -1 }, { x: 'Feb', y: 8 , y1: 8, y2: -1.5 },
{ x: 'Mar', y: 12, y1: 11, y2: -2 }, { x: 'Apr', y: 15, y1: 16, y2: -2.5 },
{ x: 'May', y: 20, y1: 21, y2: -3 }, { x: 'Jun', y: 24, y1: 25, y2: -3.5 },
{ x: 'Jul', y: 28, y1: 27, y2: -4 }, { x: 'Aug', y: 32, y1: 31, y2: -4.5 },
{ x: 'Sep', y: 33, y1: 34, y2: -5 }, { x: 'Oct', y: 35, y1: 34, y2: -5.5 },
{ x: 'Nov', y: 40, y1: 41, y2: -6 }, { x: 'Dec', y: 42, y1: 42, y2: -6.5 }
];Border
Use the border property to configure the border width, color, and dashArray of the stacked bar series.
import * as React from "react";
import * as ReactDOM from "react-dom";
import { ChartComponent, SeriesCollectionDirective, SeriesDirective, Inject, Legend, Category, StackingBarSeries } from '@syncfusion/ej2-react-charts';
import { stackBarData } from './datasource';
function App() {
const primaryxAxis = { valueType: 'Category', title: 'Months' };
const primaryyAxis = {
title: 'Percentage (%)', minimum: -20, maximum: 100,
edgeLabelPlacement: 'Shift', labelFormat: '{value}%'
};
const border = { width: 2, color: '#ff4251', dashArray: '5,5' };
const border1 = { width: 2, color: '#66BDB7', dashArray: '5,5' };
const border2 = { width: 2, color: '#794F1B', dashArray: '5,5' };
return <ChartComponent id='charts'
primaryXAxis={primaryxAxis}
primaryYAxis={primaryyAxis}
title='Sales Comparison'>
<Inject services={[StackingBarSeries, Legend, Category]} />
<SeriesCollectionDirective>
<SeriesDirective dataSource={stackBarData} xName='x' yName='y' name='Apple' type='StackingBar' border={border}>
</SeriesDirective>
<SeriesDirective dataSource={stackBarData} xName='x' yName='y1' name='Orange' type='StackingBar' border={border1}>
</SeriesDirective>
<SeriesDirective dataSource={stackBarData} xName='x' yName='y2' name='Wastage' type='StackingBar' border={border2}>
</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, AxisModel, BorderModel, Legend, Category, StackingBarSeries } from '@syncfusion/ej2-react-charts';
import { stackBarData } from './datasource';
function App() {
const primaryxAxis: AxisModel = { valueType: 'Category', title: 'Months' };
const primaryyAxis: AxisModel = {
title: 'Percentage (%)', minimum: -20, maximum: 100,
edgeLabelPlacement: 'Shift', labelFormat: '{value}%'
};
const border: BorderModel = { width: 2, color: '#ff4251', dashArray: '5,5' };
const border1: BorderModel = { width: 2, color: '#66BDB7', dashArray: '5,5' };
const border2: BorderModel = { width: 2, color: '#794F1B', dashArray: '5,5' };
return <ChartComponent id='charts'
primaryXAxis={primaryxAxis}
primaryYAxis={primaryyAxis}
title='Sales Comparison'>
<Inject services={[StackingBarSeries, Legend, Category]} />
<SeriesCollectionDirective>
<SeriesDirective dataSource={stackBarData} xName='x' yName='y' name='Apple' type='StackingBar' border={border}>
</SeriesDirective>
<SeriesDirective dataSource={stackBarData} xName='x' yName='y1' name='Orange' type='StackingBar' border={border1}>
</SeriesDirective>
<SeriesDirective dataSource={stackBarData} xName='x' yName='y2' name='Wastage' type='StackingBar' border={border2}>
</SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>
};
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));export let stackBarData = [
{ x: 'Jan', y: 6, y1: 6, y2: -1 },
{ x: 'Feb', y: 8 , y1: 8, y2: -1.5 },
{ x: 'Mar', y: 12, y1: 11, y2: -2 },
{ x: 'Apr', y: 15, y1: 16, y2: -2.5 },
{ x: 'May', y: 20, y1: 21, y2: -3 },
{ x: 'Jun', y: 24, y1: 25, y2: -3.5 },
{ x: 'Jul', y: 28, y1: 27, y2: -4 },
{ x: 'Aug', y: 32, y1: 31, y2: -4.5 },
{ x: 'Sep', y: 33, y1: 34, y2: -5 },
{ x: 'Oct', y: 35, y1: 34, y2: -5.5 },
{ x: 'Nov', y: 40, y1: 41, y2: -6 },
{ x: 'Dec', y: 42, y1: 42, y2: -6.5 }
];export let stackBarData: Object[] = [
{ x: 'Jan', y: 6, y1: 6, y2: -1 },
{ x: 'Feb', y: 8 , y1: 8, y2: -1.5 },
{ x: 'Mar', y: 12, y1: 11, y2: -2 },
{ x: 'Apr', y: 15, y1: 16, y2: -2.5 },
{ x: 'May', y: 20, y1: 21, y2: -3 },
{ x: 'Jun', y: 24, y1: 25, y2: -3.5 },
{ x: 'Jul', y: 28, y1: 27, y2: -4 },
{ x: 'Aug', y: 32, y1: 31, y2: -4.5 },
{ x: 'Sep', y: 33, y1: 34, y2: -5 },
{ x: 'Oct', y: 35, y1: 34, y2: -5.5 },
{ x: 'Nov', y: 40, y1: 41, y2: -6 },
{ x: 'Dec', y: 42, y1: 42, y2: -6.5 }
];Stacking group
Use the stackingGroup property to group stacked bar series. Series sharing the same group name are stacked together within a category; series in different groups are rendered as separate stacks side-by-side. The property accepts any string value.
import * as React from "react";
import * as ReactDOM from "react-dom";
import { ChartComponent, SeriesCollectionDirective, SeriesDirective, Inject, Legend, Category, Tooltip, DataLabel, StackingBarSeries } from '@syncfusion/ej2-react-charts';
import { groupData } from './datasource';
function App() {
const primaryxAxis = { title: 'Year', minimum: 2006, maximum: 2015, interval: 1 };
const primaryyAxis = { title: 'Sales Percentage(%)' };
return <ChartComponent id='charts' primaryXAxis={primaryxAxis} primaryYAxis={primaryyAxis} title='Sales by year'>
<Inject services={[StackingBarSeries, Legend, Tooltip, DataLabel, Category]}/>
<SeriesCollectionDirective>
<SeriesDirective dataSource={groupData} xName='x' yName='y' name='John' type='StackingBar' stackingGroup='JohnandAndrew'>
</SeriesDirective>
<SeriesDirective dataSource={groupData} xName='x' yName='y1' name='Andrew' type='StackingBar' stackingGroup='JohnandAndrew'>
</SeriesDirective>
<SeriesDirective dataSource={groupData} xName='x' yName='y2' name='Thomas' type='StackingBar' stackingGroup='ThomasandMichael'>
</SeriesDirective>
<SeriesDirective dataSource={groupData} xName='x' yName='y3' name='Michael' type='StackingBar' stackingGroup='ThomasandMichael'>
</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, StackingBarSeries, Selection}
from'@syncfusion/ej2-react-charts';
import { groupData } from './datasource';
function App() {
const primaryxAxis: AxisModel = { title: 'Year', minimum: 2006, maximum: 2015, interval: 1 };
const primaryyAxis: AxisModel = { title: 'Sales Percentage(%)' };
return <ChartComponent id='charts'
primaryXAxis={primaryxAxis}
primaryYAxis={primaryyAxis}
title='Sales by year'>
<Inject services={[StackingBarSeries, Legend, Tooltip, DataLabel, Category]} />
<SeriesCollectionDirective>
<SeriesDirective dataSource={groupData} xName='x' yName='y' name='John' type='StackingBar'
stackingGroup='JohnandAndrew'>
</SeriesDirective>
<SeriesDirective dataSource={groupData} xName='x' yName='y1' name='Andrew' type='StackingBar'
stackingGroup='JohnandAndrew'>
</SeriesDirective>
<SeriesDirective dataSource={groupData} xName='x' yName='y2' name='Thomas' type='StackingBar'
stackingGroup='ThomasandMichael'>
</SeriesDirective>
<SeriesDirective dataSource={groupData} xName='x' yName='y3' name='Michael' type='StackingBar'
stackingGroup='ThomasandMichael'>
</SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>
};
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));export let groupData = [
{ x: 2007, y: 453, y1: 876, y2: 356, y3: 122 },
{ x: 2008, y: 354, y1: 564, y2: 876, y3: 444 },
{ x: 2009, y: 282, y1: 242, y2: 898, y3: 222 },
{ x: 2010, y: 321, y1: 121, y2: 567, y3: 231 },
{ x: 2011, y: 333, y1: 343, y2: 456, y3: 122 },
{ x: 2012, y: 351, y1: 451, y2: 345, y3: 333 },
{ x: 2013, y: 403, y1: 203, y2: 543, y3: 354 },
{ x: 2014, y: 421, y1: 431, y2: 654, y3: 100 }
];export let groupData: Object[] = [
{ x: 2007, y: 453, y1: 876, y2: 356, y3: 122 },
{ x: 2008, y: 354, y1: 564, y2: 876, y3: 444 },
{ x: 2009, y: 282, y1: 242, y2: 898, y3: 222 },
{ x: 2010, y: 321, y1: 121, y2: 567, y3: 231 },
{ x: 2011, y: 333, y1: 343, y2: 456, y3: 122 },
{ x: 2012, y: 351, y1: 451, y2: 345, y3: 333 },
{ x: 2013, y: 403, y1: 203, y2: 543, y3: 354 },
{ x: 2014, y: 421, y1: 431, y2: 654, y3: 100 }
];Cylindrical stacked bar chart
To render a stacked bar with cylindrical (rounded) ends instead of a flat shape, set the columnFacet property to Cylinder on the chart series. The default value is Rect.
import * as React from "react";
import * as ReactDOM from "react-dom";
import { ChartComponent, SeriesCollectionDirective, SeriesDirective, Inject, Legend, Category, Tooltip, DataLabel, StackingBarSeries } from '@syncfusion/ej2-react-charts';
import { cylindricalData } from './datasource';
function App() {
return <ChartComponent id='charts'>
<Inject services={[StackingBarSeries, Legend, Tooltip, DataLabel, Category]} />
<SeriesCollectionDirective>
<SeriesDirective dataSource={cylindricalData} xName='x' yName='y' type='StackingBar' columnFacet='Cylinder'>
</SeriesDirective>
<SeriesDirective dataSource={cylindricalData} xName='x' yName='y1' type='StackingBar' columnFacet='Cylinder'>
</SeriesDirective>
<SeriesDirective dataSource={cylindricalData} xName='x' yName='y2' type='StackingBar' 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, StackingBarSeries, Selection
}
from '@syncfusion/ej2-react-charts';
import { cylindricalData } from './datasource';
function App() {
return <ChartComponent id='charts'>
<Inject services={[StackingBarSeries, Legend, Tooltip, DataLabel, Category]} />
<SeriesCollectionDirective>
<SeriesDirective dataSource={cylindricalData} xName='x' yName='y' type='StackingBar' columnFacet='Cylinder'>
</SeriesDirective>
<SeriesDirective dataSource={cylindricalData} xName='x' yName='y1' type='StackingBar' columnFacet='Cylinder'>
</SeriesDirective>
<SeriesDirective dataSource={cylindricalData} xName='x' yName='y2' type='StackingBar' columnFacet='Cylinder'>
</SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>
};
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));export let cylindricalData = [
{ x: 2000, y: 0.61, y1: 0.03, y2: 0.48 }, { x: 2001, y: 0.81, y1: 0.05, y2: 0.53 },
{ x: 2002, y: 0.91, y1: 0.06, y2: 0.57 }, { x: 2003, y: 1, y1: 0.09, y2: 0.61 },
{ x: 2004, y: 1.19, y1: 0.14, y2: 0.63 }, { x: 2005, y: 1.47, y1: 0.20, y2: 0.64 },
{ x: 2006, y: 1.74, y1: 0.29, y2: 0.66 }, { x: 2007, y: 1.98, y1: 0.46, y2: 0.76 },
{ x: 2008, y: 1.99, y1: 0.64, y2: 0.77 }, { x: 2009, y: 1.70, y1: 0.75, y2: 0.55 }
];export let cylindricalData: Object[] = [
{ x: 2000, y: 0.61, y1: 0.03, y2: 0.48 }, { x: 2001, y: 0.81, y1: 0.05, y2: 0.53 },
{ x: 2002, y: 0.91, y1: 0.06, y2: 0.57 }, { x: 2003, y: 1, y1: 0.09, y2: 0.61 },
{ x: 2004, y: 1.19, y1: 0.14, y2: 0.63 }, { x: 2005, y: 1.47, y1: 0.20, y2: 0.64 },
{ x: 2006, y: 1.74, y1: 0.29, y2: 0.66 }, { x: 2007, y: 1.98, y1: 0.46, y2: 0.76 },
{ x: 2008, y: 1.99, y1: 0.64, y2: 0.77 }, { x: 2009, y: 1.70, y1: 0.75, y2: 0.55 }
];Empty points
Data points with null or undefined values are considered empty. By default (mode: 'Gap'), empty points leave a gap in the stack; the mode property on emptyPointSettings lets you change how they are handled.
Mode
Use the mode property to control handling of empty points. Available modes: Gap, Drop, Zero, Average. The default mode is Gap.
import * as React from "react";
import * as ReactDOM from "react-dom";
import { ChartComponent, SeriesCollectionDirective, SeriesDirective, Inject, Legend, Category, Tooltip, DataLabel, StackingBarSeries } from '@syncfusion/ej2-react-charts';
import { stackBarData } from './datasource';
function App() {
const primaryxAxis = { valueType: 'Category', title: 'Months' };
const primaryyAxis = {
title: 'Percentage (%)', minimum: -20, maximum: 100,
edgeLabelPlacement: 'Shift', labelFormat: '{value}%'
};
const emptyPoint = { mode: 'Zero' };
const emptyPoint1 = { mode: 'Gap' };
const emptyPoint2 = { mode: 'Average' };
return <ChartComponent id='charts' primaryXAxis={primaryxAxis} primaryYAxis={primaryyAxis} title='Sales Comparison'>
<Inject services={[StackingBarSeries, Legend, Tooltip, DataLabel, Category]}/>
<SeriesCollectionDirective>
<SeriesDirective dataSource={stackBarData} xName='x' yName='y' dashArray='5' type='StackingBar' emptyPointSettings={emptyPoint}>
</SeriesDirective>
<SeriesDirective dataSource={stackBarData} xName='x' yName='y1' dashArray='5' type='StackingBar' emptyPointSettings={emptyPoint1}>
</SeriesDirective>
<SeriesDirective dataSource={stackBarData} xName='x' yName='y2' dashArray='5' type='StackingBar' emptyPointSettings={emptyPoint2}>
</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, StackingBarSeries, Selection}
from'@syncfusion/ej2-react-charts';
import { stackBarData } from './datasource';
function App() {
const primaryxAxis: AxisModel = { valueType: 'Category', title: 'Months' };
const primaryyAxis: AxisModel = {
title: 'Percentage (%)', minimum: -20, maximum: 100,
edgeLabelPlacement: 'Shift', labelFormat: '{value}%'
};
const emptyPoint: object = { mode: 'Zero' };
const emptyPoint1: object = { mode: 'Gap' };
const emptyPoint2: object = { mode: 'Average' };
return <ChartComponent id='charts'
primaryXAxis={primaryxAxis}
primaryYAxis={primaryyAxis}
title='Sales Comparison'>
<Inject services={[StackingBarSeries, Legend, Tooltip, DataLabel, Category]} />
<SeriesCollectionDirective>
<SeriesDirective dataSource={stackBarData} xName='x' yName='y' dashArray='5' type='StackingBar' emptyPointSettings={emptyPoint}>
</SeriesDirective>
<SeriesDirective dataSource={stackBarData} xName='x' yName='y1' dashArray='5' type='StackingBar' emptyPointSettings={emptyPoint1}>
</SeriesDirective>
<SeriesDirective dataSource={stackBarData} xName='x' yName='y2' dashArray='5' type='StackingBar' emptyPointSettings={emptyPoint2}>
</SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>
};
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));export let stackBarData = [
{ x: 'Jan', y: 6, y1: 6, y2: -1 },
{ x: 'Feb', y: 8 , y1: 8, y2: -1.5 },
{ x: 'Mar', y: 12, y1: 11, y2: null },
{ x: 'Apr', y: 15, y1: 16, y2: -2.5 },
{ x: 'May', y: 20, y1: 21, y2: -3 },
{ x: 'Jun', y: 24, y1: 25, y2: -3.5 },
{ x: 'Jul', y: 28, y1: undefined, y2: -4 },
{ x: 'Aug', y: 32, y1: 31, y2: -4.5 },
{ x: 'Sep', y: 33, y1: 34, y2: -5 },
{ x: 'Oct', y: null, y1: 34, y2: -5.5 },
{ x: 'Nov', y: 40, y1: 41, y2: -6 },
{ x: 'Dec', y: 42, y1: 42, y2: -6.5 }
];export let stackBarData: Object[] = [
{ x: 'Jan', y: 6, y1: 6, y2: -1 },
{ x: 'Feb', y: 8 , y1: 8, y2: -1.5 },
{ x: 'Mar', y: 12, y1: 11, y2: null },
{ x: 'Apr', y: 15, y1: 16, y2: -2.5 },
{ x: 'May', y: 20, y1: 21, y2: -3 },
{ x: 'Jun', y: 24, y1: 25, y2: -3.5 },
{ x: 'Jul', y: 28, y1: undefined, y2: -4 },
{ x: 'Aug', y: 32, y1: 31, y2: -4.5 },
{ x: 'Sep', y: 33, y1: 34, y2: -5 },
{ x: 'Oct', y: null, y1: 34, y2: -5.5 },
{ x: 'Nov', y: 40, y1: 41, y2: -6 },
{ x: 'Dec', y: 42, y1: 42, y2: -6.5 }
];Fill
Use the fill property to set the fill color for empty points.
import * as React from "react";
import * as ReactDOM from "react-dom";
import { ChartComponent, SeriesCollectionDirective, SeriesDirective, Inject, Legend, Category, Tooltip, DataLabel, StackingBarSeries } from '@syncfusion/ej2-react-charts';
import { stackBarData } from './datasource';
function App() {
const primaryxAxis = { valueType: 'Category', title: 'Months' };
const primaryyAxis = {
title: 'Percentage (%)', minimum: -20, maximum: 100,
edgeLabelPlacement: 'Shift', labelFormat: '{value}%'
};
const emptyPoint = { mode: 'Zero' };
const emptyPoint1 = { mode: 'Gap' };
const emptyPoint2 = { mode: 'Average', fill: 'red' };
return <ChartComponent id='charts' primaryXAxis={primaryxAxis} primaryYAxis={primaryyAxis} title='Sales Comparison'>
<Inject services={[StackingBarSeries, Legend, Tooltip, DataLabel, Category]}/>
<SeriesCollectionDirective>
<SeriesDirective dataSource={stackBarData} xName='x' yName='y' dashArray='5' type='StackingBar' emptyPointSettings={emptyPoint}>
</SeriesDirective>
<SeriesDirective dataSource={stackBarData} xName='x' yName='y1' dashArray='5' type='StackingBar' emptyPointSettings={emptyPoint1}>
</SeriesDirective>
<SeriesDirective dataSource={stackBarData} xName='x' yName='y2' dashArray='5' type='StackingBar' emptyPointSettings={emptyPoint2}>
</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, StackingBarSeries, Selection}
from'@syncfusion/ej2-react-charts';
import { stackBarData } from './datasource';
function App() {
const primaryxAxis: AxisModel = { valueType: 'Category', title: 'Months' };
const primaryyAxis: AxisModel = {
title: 'Percentage (%)', minimum: -20, maximum: 100,
edgeLabelPlacement: 'Shift', labelFormat: '{value}%'
};
const emptyPoint: object = { mode: 'Zero' };
const emptyPoint1: object = { mode: 'Gap' };
const emptyPoint2: object = { mode: 'Average', fill: 'red' };
return <ChartComponent id='charts'
primaryXAxis={primaryxAxis}
primaryYAxis={primaryyAxis}
title='Sales Comparison'>
<Inject services={[StackingBarSeries, Legend, Tooltip, DataLabel, Category]} />
<SeriesCollectionDirective>
<SeriesDirective dataSource={stackBarData} xName='x' yName='y' dashArray='5' type='StackingBar' emptyPointSettings={emptyPoint}>
</SeriesDirective>
<SeriesDirective dataSource={stackBarData} xName='x' yName='y1' dashArray='5' type='StackingBar' emptyPointSettings={emptyPoint1}>
</SeriesDirective>
<SeriesDirective dataSource={stackBarData} xName='x' yName='y2' dashArray='5' type='StackingBar' emptyPointSettings={emptyPoint2}>
</SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>
};
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));export let stackBarData = [
{ x: 'Jan', y: 6, y1: 6, y2: -1 },
{ x: 'Feb', y: 8 , y1: 8, y2: -1.5 },
{ x: 'Mar', y: 12, y1: 11, y2: null },
{ x: 'Apr', y: 15, y1: 16, y2: -2.5 },
{ x: 'May', y: 20, y1: 21, y2: -3 },
{ x: 'Jun', y: 24, y1: 25, y2: -3.5 },
{ x: 'Jul', y: 28, y1: undefined, y2: -4 },
{ x: 'Aug', y: 32, y1: 31, y2: -4.5 },
{ x: 'Sep', y: 33, y1: 34, y2: -5 },
{ x: 'Oct', y: null, y1: 34, y2: -5.5 },
{ x: 'Nov', y: 40, y1: 41, y2: -6 },
{ x: 'Dec', y: 42, y1: 42, y2: -6.5 }
];export let stackBarData: Object[] = [
{ x: 'Jan', y: 6, y1: 6, y2: -1 },
{ x: 'Feb', y: 8 , y1: 8, y2: -1.5 },
{ x: 'Mar', y: 12, y1: 11, y2: null },
{ x: 'Apr', y: 15, y1: 16, y2: -2.5 },
{ x: 'May', y: 20, y1: 21, y2: -3 },
{ x: 'Jun', y: 24, y1: 25, y2: -3.5 },
{ x: 'Jul', y: 28, y1: undefined, y2: -4 },
{ x: 'Aug', y: 32, y1: 31, y2: -4.5 },
{ x: 'Sep', y: 33, y1: 34, y2: -5 },
{ x: 'Oct', y: null, y1: 34, y2: -5.5 },
{ x: 'Nov', y: 40, y1: 41, y2: -6 },
{ x: 'Dec', y: 42, y1: 42, y2: -6.5 }
];Border
Use the border property to customize the border width and color for empty points.
import * as React from "react";
import * as ReactDOM from "react-dom";
import { ChartComponent, SeriesCollectionDirective, SeriesDirective, Inject, Legend, Category, Tooltip, DataLabel, StackingBarSeries } from '@syncfusion/ej2-react-charts';
import { stackBarData } from './datasource';
function App() {
const primaryxAxis = { valueType: 'Category', title: 'Months' };
const primaryyAxis = {
title: 'Percentage (%)', minimum: -20, maximum: 100,
edgeLabelPlacement: 'Shift', labelFormat: '{value}%'
};
const emptyPoint = { mode: 'Zero' };
const emptyPoint1 = { mode: 'Gap' };
const emptyPoint2 = { mode: 'Average', fill: 'red', border: {width: 1.5, color: 'blue'} };
return <ChartComponent id='charts' primaryXAxis={primaryxAxis} primaryYAxis={primaryyAxis} title='Sales Comparison'>
<Inject services={[StackingBarSeries, Legend, Tooltip, DataLabel, Category]}/>
<SeriesCollectionDirective>
<SeriesDirective dataSource={stackBarData} xName='x' yName='y' type='StackingBar' emptyPointSettings={emptyPoint}>
</SeriesDirective>
<SeriesDirective dataSource={stackBarData} xName='x' yName='y1' type='StackingBar' emptyPointSettings={emptyPoint1}>
</SeriesDirective>
<SeriesDirective dataSource={stackBarData} xName='x' yName='y2' type='StackingBar' emptyPointSettings={emptyPoint2}>
</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, StackingBarSeries, Selection}
from'@syncfusion/ej2-react-charts';
import { stackBarData } from './datasource';
function App() {
const primaryxAxis: AxisModel = { valueType: 'Category', title: 'Months' };
const primaryyAxis: AxisModel = {
title: 'Percentage (%)', minimum: -20, maximum: 100,
edgeLabelPlacement: 'Shift', labelFormat: '{value}%'
};
const emptyPoint: object = { mode: 'Zero' };
const emptyPoint1: object = { mode: 'Gap' };
const emptyPoint2: object = { mode: 'Average', fill: 'red', border: {width: 1.5, color: 'blue'}};
return <ChartComponent id='charts'
primaryXAxis={primaryxAxis}
primaryYAxis={primaryyAxis}
title='Sales Comparison'>
<Inject services={[StackingBarSeries, Legend, Tooltip, DataLabel, Category]} />
<SeriesCollectionDirective>
<SeriesDirective dataSource={stackBarData} xName='x' yName='y' type='StackingBar' emptyPointSettings={emptyPoint}>
</SeriesDirective>
<SeriesDirective dataSource={stackBarData} xName='x' yName='y1' type='StackingBar' emptyPointSettings={emptyPoint1}>
</SeriesDirective>
<SeriesDirective dataSource={stackBarData} xName='x' yName='y2' type='StackingBar' emptyPointSettings={emptyPoint2}>
</SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>
};
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));export let stackBarData = [
{ x: 'Jan', y: 6, y1: 6, y2: -1 },
{ x: 'Feb', y: 8 , y1: 8, y2: -1.5 },
{ x: 'Mar', y: 12, y1: 11, y2: null },
{ x: 'Apr', y: 15, y1: 16, y2: -2.5 },
{ x: 'May', y: 20, y1: 21, y2: -3 },
{ x: 'Jun', y: 24, y1: 25, y2: -3.5 },
{ x: 'Jul', y: 28, y1: undefined, y2: -4 },
{ x: 'Aug', y: 32, y1: 31, y2: -4.5 },
{ x: 'Sep', y: 33, y1: 34, y2: -5 },
{ x: 'Oct', y: null, y1: 34, y2: -5.5 },
{ x: 'Nov', y: 40, y1: 41, y2: -6 },
{ x: 'Dec', y: 42, y1: 42, y2: -6.5 }
];export let stackBarData: Object[] = [
{ x: 'Jan', y: 6, y1: 6, y2: -1 },
{ x: 'Feb', y: 8 , y1: 8, y2: -1.5 },
{ x: 'Mar', y: 12, y1: 11, y2: null },
{ x: 'Apr', y: 15, y1: 16, y2: -2.5 },
{ x: 'May', y: 20, y1: 21, y2: -3 },
{ x: 'Jun', y: 24, y1: 25, y2: -3.5 },
{ x: 'Jul', y: 28, y1: undefined, y2: -4 },
{ x: 'Aug', y: 32, y1: 31, y2: -4.5 },
{ x: 'Sep', y: 33, y1: 34, y2: -5 },
{ x: 'Oct', y: null, y1: 34, y2: -5.5 },
{ x: 'Nov', y: 40, y1: 41, y2: -6 },
{ x: 'Dec', y: 42, y1: 42, y2: -6.5 }
];Stack labels
The stack labels in stacked bar, stacked column, and stacked area charts display cumulative total values for stack segments as inline data labels. If a stacked point has negative values, the stack labels are displayed below the point. Stack labels are independent of the dataLabel settings within each series.
import * as React from "react";
import * as ReactDOM from "react-dom";
import { ChartComponent, SeriesCollectionDirective, SeriesDirective, Inject, Legend, Category, Tooltip, DataLabel, StackingBarSeries } from '@syncfusion/ej2-react-charts';
import { stackBarData } from './datasource';
function App() {
const primaryxAxis = { valueType: 'Category', title: 'Months' };
const primaryyAxis = {
title: 'Percentage (%)', minimum: -20, maximum: 100,
edgeLabelPlacement: 'Shift', labelFormat: '{value}%'
};
return <ChartComponent id='charts'
primaryXAxis={primaryxAxis}
primaryYAxis={primaryyAxis}
title='Sales Comparison'
stackLabels={{ visible: true }}>
<Inject services={[StackingBarSeries, Legend, Tooltip, DataLabel, Category]} />
<SeriesCollectionDirective>
<SeriesDirective dataSource={stackBarData} xName='x' yName='y' name='Apple' type='StackingBar' marker={{ dataLabel: { visible: true } }}>
</SeriesDirective>
<SeriesDirective dataSource={stackBarData} xName='x' yName='y1' name='orange' type='StackingBar' marker={{ dataLabel: { visible: true } }}>
</SeriesDirective>
<SeriesDirective dataSource={stackBarData} xName='x' yName='y2' name='Wastage' type='StackingBar' marker={{ dataLabel: { visible: true } }}>
</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, StackingBarSeries, Selection}
from'@syncfusion/ej2-react-charts';
import { stackBarData } from './datasource';
function App() {
const primaryxAxis: AxisModel = { valueType: 'Category', title: 'Months' };
const primaryyAxis: AxisModel = {
title: 'Percentage (%)', minimum: -20, maximum: 100,
edgeLabelPlacement: 'Shift', labelFormat: '{value}%'
};
return <ChartComponent id='charts'
primaryXAxis={primaryxAxis}
primaryYAxis={primaryyAxis}
title='Sales Comparison'
stackLabels={{ visible: true }}>
<Inject services={[StackingBarSeries, Legend, Tooltip, DataLabel, Category]} />
<SeriesCollectionDirective>
<SeriesDirective dataSource={stackBarData} xName='x' yName='y' name='Apple' type='StackingBar' marker={{ dataLabel: { visible: true } }}>
</SeriesDirective>
<SeriesDirective dataSource={stackBarData} xName='x' yName='y1' name='orange' type='StackingBar' marker={{ dataLabel: { visible: true } }}>
</SeriesDirective>
<SeriesDirective dataSource={stackBarData} xName='x' yName='y2' name='Wastage' type='StackingBar' marker={{ dataLabel: { visible: true } }}>
</SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>
};
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));export let stackBarData = [
{ x: 'Jan', y: 6, y1: 6, y2: -1 }, { x: 'Feb', y: 8 , y1: 8, y2: -1.5 },
{ x: 'Mar', y: 12, y1: 11, y2: -2 }, { x: 'Apr', y: 15, y1: 16, y2: -2.5 },
{ x: 'May', y: 20, y1: 21, y2: -3 }, { x: 'Jun', y: 24, y1: 25, y2: -3.5 },
{ x: 'Jul', y: 28, y1: 27, y2: -4 }, { x: 'Aug', y: 32, y1: 31, y2: -4.5 },
{ x: 'Sep', y: 33, y1: 34, y2: -5 }, { x: 'Oct', y: 35, y1: 34, y2: -5.5 },
{ x: 'Nov', y: 40, y1: 41, y2: -6 }, { x: 'Dec', y: 42, y1: 42, y2: -6.5 }
];export let stackBarData: Object[] = [
{ x: 'Jan', y: 6, y1: 6, y2: -1 }, { x: 'Feb', y: 8 , y1: 8, y2: -1.5 },
{ x: 'Mar', y: 12, y1: 11, y2: -2 }, { x: 'Apr', y: 15, y1: 16, y2: -2.5 },
{ x: 'May', y: 20, y1: 21, y2: -3 }, { x: 'Jun', y: 24, y1: 25, y2: -3.5 },
{ x: 'Jul', y: 28, y1: 27, y2: -4 }, { x: 'Aug', y: 32, y1: 31, y2: -4.5 },
{ x: 'Sep', y: 33, y1: 34, y2: -5 }, { x: 'Oct', y: 35, y1: 34, y2: -5.5 },
{ x: 'Nov', y: 40, y1: 41, y2: -6 }, { x: 'Dec', y: 42, y1: 42, y2: -6.5 }
];Stack labels customization
Stack labels have various properties for customization to enhance the visual based on your requirements:
| Property | Type | Default | Description |
|---|---|---|---|
visible |
boolean | false |
Specifies whether stack labels are visible. Setting to true displays the labels. |
fill |
string | transparent |
Background color of the stack labels. Accepts valid CSS color strings (hex, RGBA, etc.). |
format |
string | null |
Format string for the label text. Supports placeholders such as {value}. |
angle |
number | 0 |
Rotation angle for stack labels in degrees. |
rx |
number | 5 |
Rounded corner radius along the X-axis for the stack label background. |
ry |
number | 5 |
Rounded corner radius along the Y-axis for the stack label background. |
margin |
MarginModel |
null |
Margin around the stack label (left, right, top, bottom). |
border |
BorderModel |
null |
Border appearance of the stack label. |
font |
StackLabelsFontModel |
null |
Font customization (size, color, fontStyle, fontWeight, fontFamily). |
import * as React from "react";
import * as ReactDOM from "react-dom";
import { ChartComponent, SeriesCollectionDirective, SeriesDirective, Inject, Legend, Category, Tooltip, DataLabel, StackingBarSeries } from '@syncfusion/ej2-react-charts';
import { stackBarData } from './datasource';
function App() {
const primaryxAxis = { valueType: 'Category', title: 'Months' };
const primaryyAxis = {
title: 'Percentage (%)', minimum: -20, maximum: 100,
edgeLabelPlacement: 'Shift', labelFormat: '{value}%'
};
return <ChartComponent id='charts'
primaryXAxis={primaryxAxis}
primaryYAxis={primaryyAxis}
title='Sales Comparison'
stackLabels={{ visible: true, fill: 'rgba(0, 123, 255, 0.5)', format: '{value}', angle: 45, rx: 10, ry: 10, margin: { left: 10, right: 10, top: 10, bottom: 10 }, border: { width: 2, color: '#000' }, font: { size: '14px', color: '#fff', weight: 'bold', family: 'Arial', textAlignment: 'Left' } }}>
<Inject services={[StackingBarSeries, Legend, Tooltip, DataLabel, Category]} />
<SeriesCollectionDirective>
<SeriesDirective dataSource={stackBarData} xName='x' yName='y' name='Apple' type='StackingBar' marker={{ dataLabel: { visible: true } }}>
</SeriesDirective>
<SeriesDirective dataSource={stackBarData} xName='x' yName='y1' name='orange' type='StackingBar' marker={{ dataLabel: { visible: true } }}>
</SeriesDirective>
<SeriesDirective dataSource={stackBarData} xName='x' yName='y2' name='Wastage' type='StackingBar' marker={{ dataLabel: { visible: true } }}>
</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, StackingBarSeries, Selection}
from'@syncfusion/ej2-react-charts';
import { stackBarData } from './datasource';
function App() {
const primaryxAxis: AxisModel = { valueType: 'Category', title: 'Months' };
const primaryyAxis: AxisModel = {
title: 'Percentage (%)', minimum: -20, maximum: 100,
edgeLabelPlacement: 'Shift', labelFormat: '{value}%'
};
return <ChartComponent id='charts'
primaryXAxis={primaryxAxis}
primaryYAxis={primaryyAxis}
title='Sales Comparison'
stackLabels={{ visible: true, fill: 'rgba(0, 123, 255, 0.5)', format: '{value}', angle: 45, rx: 10, ry: 10, margin: { left: 10, right: 10, top: 10, bottom: 10 }, border: { width: 2, color: '#000' }, font: { size: '14px', color: '#fff', weight: 'bold', family: 'Arial', textAlignment: 'Left' } }}>
<Inject services={[StackingBarSeries, Legend, Tooltip, DataLabel, Category]} />
<SeriesCollectionDirective>
<SeriesDirective dataSource={stackBarData} xName='x' yName='y' name='Apple' type='StackingBar' marker={{ dataLabel: { visible: true } }}>
</SeriesDirective>
<SeriesDirective dataSource={stackBarData} xName='x' yName='y1' name='orange' type='StackingBar' marker={{ dataLabel: { visible: true } }}>
</SeriesDirective>
<SeriesDirective dataSource={stackBarData} xName='x' yName='y2' name='Wastage' type='StackingBar' marker={{ dataLabel: { visible: true } }}>
</SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>
};
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));export let stackBarData = [
{ x: 'Jan', y: 6, y1: 6, y2: -1 }, { x: 'Feb', y: 8 , y1: 8, y2: -1.5 },
{ x: 'Mar', y: 12, y1: 11, y2: -2 }, { x: 'Apr', y: 15, y1: 16, y2: -2.5 },
{ x: 'May', y: 20, y1: 21, y2: -3 }, { x: 'Jun', y: 24, y1: 25, y2: -3.5 },
{ x: 'Jul', y: 28, y1: 27, y2: -4 }, { x: 'Aug', y: 32, y1: 31, y2: -4.5 },
{ x: 'Sep', y: 33, y1: 34, y2: -5 }, { x: 'Oct', y: 35, y1: 34, y2: -5.5 },
{ x: 'Nov', y: 40, y1: 41, y2: -6 }, { x: 'Dec', y: 42, y1: 42, y2: -6.5 }
];export let stackBarData: Object[] = [
{ x: 'Jan', y: 6, y1: 6, y2: -1 }, { x: 'Feb', y: 8 , y1: 8, y2: -1.5 },
{ x: 'Mar', y: 12, y1: 11, y2: -2 }, { x: 'Apr', y: 15, y1: 16, y2: -2.5 },
{ x: 'May', y: 20, y1: 21, y2: -3 }, { x: 'Jun', y: 24, y1: 25, y2: -3.5 },
{ x: 'Jul', y: 28, y1: 27, y2: -4 }, { x: 'Aug', y: 32, y1: 31, y2: -4.5 },
{ x: 'Sep', y: 33, y1: 34, y2: -5 }, { x: 'Oct', y: 35, y1: 34, y2: -5.5 },
{ x: 'Nov', y: 40, y1: 41, y2: -6 }, { x: 'Dec', y: 42, y1: 42, y2: -6.5 }
];Corner radius
The cornerRadius property on the chart series is used to round the corners of stacked bar segments. Each corner can be customized individually using topLeft, topRight, bottomLeft, and bottomRight; values are in pixels.
import * as React from "react";
import * as ReactDOM from "react-dom";
import { ChartComponent, SeriesCollectionDirective, SeriesDirective, Inject, Legend, Category, Tooltip, DataLabel, StackingBarSeries } from '@syncfusion/ej2-react-charts';
import { stackBarData } from './datasource';
function App() {
const primaryxAxis = { valueType: 'Category', title: 'Months' };
const primaryyAxis = {
title: 'Percentage (%)', minimum: -20, maximum: 100,
edgeLabelPlacement: 'Shift', labelFormat: '{value}%'
};
const pointRender = (args) => {
if (args.series.index === 0) {
args.fill = '#ff4251';
}
else if (args.series.index === 1) {
args.fill = '#4C4C4C';
}
else if (args.series.index === 2) {
args.fill = '#794F1B';
}
};
return <ChartComponent id='charts' primaryXAxis={primaryxAxis} primaryYAxis={primaryyAxis} title='Sales Comparison' pointRender={pointRender}>
<Inject services={[StackingBarSeries, Legend, Tooltip, DataLabel, Category]}/>
<SeriesCollectionDirective>
<SeriesDirective dataSource={stackBarData} xName='x' yName='y' type='StackingBar'>
</SeriesDirective>
<SeriesDirective dataSource={stackBarData} xName='x' yName='y1' type='StackingBar' cornerRadius= {{ topRight: 10, bottomRight: 10 }}>
</SeriesDirective>
<SeriesDirective dataSource={stackBarData} xName='x' yName='y2' type='StackingBar' cornerRadius= {{ topRight: 10, bottomRight: 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, StackingBarSeries, IPointRenderEventArgs}
from'@syncfusion/ej2-react-charts';
import { stackBarData } from './datasource';
function App() {
const primaryxAxis: AxisModel = { valueType: 'Category', title: 'Months' };
const primaryyAxis: AxisModel = {
title: 'Percentage (%)', minimum: -20, maximum: 100,
edgeLabelPlacement: 'Shift', labelFormat: '{value}%'
};
const pointRender = (args: IPointRenderEventArgs) => {
if (args.series.index === 0) {
args.fill = '#ff4251';
}
else if (args.series.index === 1) {
args.fill = '#4C4C4C';
}
else if (args.series.index === 2) {
args.fill = '#794F1B';
}
};
return <ChartComponent id='charts'
primaryXAxis={primaryxAxis}
primaryYAxis={primaryyAxis}
title='Sales Comparison' pointRender={pointRender}>
<Inject services={[StackingBarSeries, Legend, Tooltip, DataLabel, Category]} />
<SeriesCollectionDirective>
<SeriesDirective dataSource={stackBarData} xName='x' yName='y' type='StackingBar' >
</SeriesDirective>
<SeriesDirective dataSource={stackBarData} xName='x' yName='y1' type='StackingBar' cornerRadius= {{ topRight: 10, bottomRight: 10 }}>
</SeriesDirective>
<SeriesDirective dataSource={stackBarData} xName='x' yName='y2' type='StackingBar' cornerRadius= {{ topRight: 10, bottomRight: 10 }} >
</SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>
};
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));export let stackBarData = [
{ x: 'Jan', y: 6, y1: 6, y2: -1 }, { x: 'Feb', y: 8 , y1: 8, y2: -1.5 },
{ x: 'Mar', y: 12, y1: 11, y2: -2 }, { x: 'Apr', y: 15, y1: 16, y2: -2.5 },
{ x: 'May', y: 20, y1: 21, y2: -3 }, { x: 'Jun', y: 24, y1: 25, y2: -3.5 },
{ x: 'Jul', y: 28, y1: 27, y2: -4 }, { x: 'Aug', y: 32, y1: 31, y2: -4.5 },
{ x: 'Sep', y: 33, y1: 34, y2: -5 }, { x: 'Oct', y: 35, y1: 34, y2: -5.5 },
{ x: 'Nov', y: 40, y1: 41, y2: -6 }, { x: 'Dec', y: 42, y1: 42, y2: -6.5 }
];export let stackBarData: Object[] = [
{ x: 'Jan', y: 6, y1: 6, y2: -1 }, { x: 'Feb', y: 8 , y1: 8, y2: -1.5 },
{ x: 'Mar', y: 12, y1: 11, y2: -2 }, { x: 'Apr', y: 15, y1: 16, y2: -2.5 },
{ x: 'May', y: 20, y1: 21, y2: -3 }, { x: 'Jun', y: 24, y1: 25, y2: -3.5 },
{ x: 'Jul', y: 28, y1: 27, y2: -4 }, { x: 'Aug', y: 32, y1: 31, y2: -4.5 },
{ x: 'Sep', y: 33, y1: 34, y2: -5 }, { x: 'Oct', y: 35, y1: 34, y2: -5.5 },
{ x: 'Nov', y: 40, y1: 41, y2: -6 }, { x: 'Dec', y: 42, y1: 42, y2: -6.5 }
];Point corner radius
You can override the corner radius for individual stacked bar points by using the pointRender event and setting the cornerRadius property on the event-args object. Use this to apply conditional rounding (for example, larger radius on the topmost segment of each stack).
import * as React from "react";
import * as ReactDOM from "react-dom";
import { ChartComponent, SeriesCollectionDirective, SeriesDirective, Inject, Legend, Category, Tooltip, DataLabel, StackingBarSeries } from '@syncfusion/ej2-react-charts';
import { stackBarData } from './datasource';
function App() {
const primaryxAxis = { valueType: 'Category', title: 'Months' };
const primaryyAxis = {
title: 'Percentage (%)', minimum: -20, maximum: 100,
edgeLabelPlacement: 'Shift', labelFormat: '{value}%'
};
const pointRender = (args) => {
if (args.point.index === 1 && args.point.series.index === 1) {
args.cornerRadius = { topLeft: 0, bottomLeft: 0, topRight: 10, bottomRight: 10 };
}
if (args.point.index === 4 && args.point.series.index === 1) {
args.cornerRadius = { topLeft: 0, bottomLeft: 0, topRight: 10, bottomRight: 10 };
}
if (args.point.index === 6 && args.point.series.index === 1) {
args.cornerRadius = { topLeft: 0, bottomLeft: 0, topRight: 10, bottomRight: 10 };
}
if (args.point.index === 8 && args.point.series.index === 1) {
args.cornerRadius = { topLeft: 0, bottomLeft: 0, topRight: 10, bottomRight: 10 };
}
};
return <ChartComponent id='charts' primaryXAxis={primaryxAxis} primaryYAxis={primaryyAxis} title='Sales Comparison' pointRender={pointRender}>
<Inject services={[StackingBarSeries, Legend, Tooltip, DataLabel, Category]}/>
<SeriesCollectionDirective>
<SeriesDirective dataSource={stackBarData} xName='x' yName='y' type='StackingBar'>
</SeriesDirective>
<SeriesDirective dataSource={stackBarData} xName='x' yName='y1' type='StackingBar'>
</SeriesDirective>
<SeriesDirective dataSource={stackBarData} xName='x' yName='y2' type='StackingBar'>
</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, StackingBarSeries, IPointRenderEventArgs}
from'@syncfusion/ej2-react-charts';
import { stackBarData } from './datasource';
function App() {
const primaryxAxis: AxisModel = { valueType: 'Category', title: 'Months' };
const primaryyAxis: AxisModel = {
title: 'Percentage (%)', minimum: -20, maximum: 100,
edgeLabelPlacement: 'Shift', labelFormat: '{value}%'
};
const pointRender = (args: IPointRenderEventArgs) => {
if (args.point.index === 1 && args.point.series.index === 1) {
args.cornerRadius = { topLeft: 0, bottomLeft: 0, topRight: 10, bottomRight: 10 };
}
if (args.point.index === 4 && args.point.series.index === 1) {
args.cornerRadius = { topLeft: 0, bottomLeft: 0, topRight: 10, bottomRight: 10 };
}
if (args.point.index === 6 && args.point.series.index === 1) {
args.cornerRadius = { topLeft: 0, bottomLeft: 0, topRight: 10, bottomRight: 10 };
}
if (args.point.index === 8 && args.point.series.index === 1) {
args.cornerRadius = { topLeft: 0, bottomLeft: 0, topRight: 10, bottomRight: 10 };
}
};
return <ChartComponent id='charts'
primaryXAxis={primaryxAxis}
primaryYAxis={primaryyAxis}
title='Sales Comparison' pointRender={pointRender}>
<Inject services={[StackingBarSeries, Legend, Tooltip, DataLabel, Category]} />
<SeriesCollectionDirective>
<SeriesDirective dataSource={stackBarData} xName='x' yName='y' type='StackingBar'>
</SeriesDirective>
<SeriesDirective dataSource={stackBarData} xName='x' yName='y1' type='StackingBar'>
</SeriesDirective>
<SeriesDirective dataSource={stackBarData} xName='x' yName='y2' type='StackingBar'>
</SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>
};
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));export let stackBarData = [
{ x: 'Jan', y: 6, y1: 6, y2: -1 }, { x: 'Feb', y: 8 , y1: 8, y2: -1.5 },
{ x: 'Mar', y: 12, y1: 11, y2: -2 }, { x: 'Apr', y: 15, y1: 16, y2: -2.5 },
{ x: 'May', y: 20, y1: 21, y2: -3 }, { x: 'Jun', y: 24, y1: 25, y2: -3.5 },
{ x: 'Jul', y: 28, y1: 27, y2: -4 }, { x: 'Aug', y: 32, y1: 31, y2: -4.5 },
{ x: 'Sep', y: 33, y1: 34, y2: -5 }, { x: 'Oct', y: 35, y1: 34, y2: -5.5 },
{ x: 'Nov', y: 40, y1: 41, y2: -6 }, { x: 'Dec', y: 42, y1: 42, y2: -6.5 }
];export let stackBarData: Object[] = [
{ x: 'Jan', y: 6, y1: 6, y2: -1 }, { x: 'Feb', y: 8 , y1: 8, y2: -1.5 },
{ x: 'Mar', y: 12, y1: 11, y2: -2 }, { x: 'Apr', y: 15, y1: 16, y2: -2.5 },
{ x: 'May', y: 20, y1: 21, y2: -3 }, { x: 'Jun', y: 24, y1: 25, y2: -3.5 },
{ x: 'Jul', y: 28, y1: 27, y2: -4 }, { x: 'Aug', y: 32, y1: 31, y2: -4.5 },
{ x: 'Sep', y: 33, y1: 34, y2: -5 }, { x: 'Oct', y: 35, y1: 34, y2: -5.5 },
{ x: 'Nov', y: 40, y1: 41, y2: -6 }, { x: 'Dec', y: 42, y1: 42, y2: -6.5 }
];Events
Series render
The seriesRender event fires before each series is rendered and lets you modify series properties such as data, fill, or name. For a stacked bar series, use it to vary per-series fill or stackingGroup between renders.
import * as React from "react";
import * as ReactDOM from "react-dom";
import { ChartComponent, SeriesCollectionDirective, SeriesDirective, Inject, Legend, Category, Tooltip, DataLabel, StackingBarSeries } from '@syncfusion/ej2-react-charts';
import { stackBarData } from './datasource';
function App() {
const primaryxAxis = { valueType: 'Category', title: 'Months' };
const primaryyAxis = {
title: 'Percentage (%)', minimum: -20, maximum: 100,
edgeLabelPlacement: 'Shift', labelFormat: '{value}%'
};
const seriesRender = (args) => {
if (args.series.index === 0) {
args.fill = '#ff4251';
}
else if (args.series.index === 1) {
args.fill = '#4C4C4C';
}
else if (args.series.index === 2) {
args.fill = '#794F1B';
}
};
return <ChartComponent id='charts' primaryXAxis={primaryxAxis} primaryYAxis={primaryyAxis} title='Sales Comparison' seriesRender={seriesRender}>
<Inject services={[StackingBarSeries, Legend, Tooltip, DataLabel, Category]}/>
<SeriesCollectionDirective>
<SeriesDirective dataSource={stackBarData} xName='x' yName='y' type='StackingBar'>
</SeriesDirective>
<SeriesDirective dataSource={stackBarData} xName='x' yName='y1' type='StackingBar'>
</SeriesDirective>
<SeriesDirective dataSource={stackBarData} xName='x' yName='y2' type='StackingBar'>
</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, StackingBarSeries, ISeriesRenderEventArgs}
from'@syncfusion/ej2-react-charts';
import { stackBarData } from './datasource';
function App() {
const primaryxAxis: AxisModel = { valueType: 'Category', title: 'Months' };
const primaryyAxis: AxisModel = {
title: 'Percentage (%)', minimum: -20, maximum: 100,
edgeLabelPlacement: 'Shift', labelFormat: '{value}%'
};
const seriesRender = (args: ISeriesRenderEventArgs) => {
if (args.series.index === 0) {
args.fill = '#ff4251';
}
else if (args.series.index === 1) {
args.fill = '#4C4C4C';
}
else if (args.series.index === 2) {
args.fill = '#794F1B';
}
};
return <ChartComponent id='charts'
primaryXAxis={primaryxAxis}
primaryYAxis={primaryyAxis}
title='Sales Comparison' seriesRender={seriesRender}>
<Inject services={[StackingBarSeries, Legend, Tooltip, DataLabel, Category]} />
<SeriesCollectionDirective>
<SeriesDirective dataSource={stackBarData} xName='x' yName='y' type='StackingBar'>
</SeriesDirective>
<SeriesDirective dataSource={stackBarData} xName='x' yName='y1' type='StackingBar'>
</SeriesDirective>
<SeriesDirective dataSource={stackBarData} xName='x' yName='y2' type='StackingBar'>
</SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>
};
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));export let stackBarData = [
{ x: 'Jan', y: 6, y1: 6, y2: -1 }, { x: 'Feb', y: 8 , y1: 8, y2: -1.5 },
{ x: 'Mar', y: 12, y1: 11, y2: -2 }, { x: 'Apr', y: 15, y1: 16, y2: -2.5 },
{ x: 'May', y: 20, y1: 21, y2: -3 }, { x: 'Jun', y: 24, y1: 25, y2: -3.5 },
{ x: 'Jul', y: 28, y1: 27, y2: -4 }, { x: 'Aug', y: 32, y1: 31, y2: -4.5 },
{ x: 'Sep', y: 33, y1: 34, y2: -5 }, { x: 'Oct', y: 35, y1: 34, y2: -5.5 },
{ x: 'Nov', y: 40, y1: 41, y2: -6 }, { x: 'Dec', y: 42, y1: 42, y2: -6.5 }
];export let stackBarData: Object[] = [
{ x: 'Jan', y: 6, y1: 6, y2: -1 }, { x: 'Feb', y: 8 , y1: 8, y2: -1.5 },
{ x: 'Mar', y: 12, y1: 11, y2: -2 }, { x: 'Apr', y: 15, y1: 16, y2: -2.5 },
{ x: 'May', y: 20, y1: 21, y2: -3 }, { x: 'Jun', y: 24, y1: 25, y2: -3.5 },
{ x: 'Jul', y: 28, y1: 27, y2: -4 }, { x: 'Aug', y: 32, y1: 31, y2: -4.5 },
{ x: 'Sep', y: 33, y1: 34, y2: -5 }, { x: 'Oct', y: 35, y1: 34, y2: -5.5 },
{ x: 'Nov', y: 40, y1: 41, y2: -6 }, { x: 'Dec', y: 42, y1: 42, y2: -6.5 }
];Point render
The pointRender event fires before each data point is drawn, letting you customize per-point marker shape, border, fill, or corner radius. For a stacked bar series, use it to apply conditional formatting on individual bar segments.
import * as React from "react";
import * as ReactDOM from "react-dom";
import { ChartComponent, SeriesCollectionDirective, SeriesDirective, Inject, Legend, Category, Tooltip, DataLabel, StackingBarSeries } from '@syncfusion/ej2-react-charts';
import { stackBarData } from './datasource';
function App() {
const primaryxAxis = { valueType: 'Category', title: 'Months' };
const primaryyAxis = {
title: 'Percentage (%)', minimum: -20, maximum: 100,
edgeLabelPlacement: 'Shift', labelFormat: '{value}%'
};
const pointRender = (args) => {
if (args.series.index === 0) {
args.fill = '#ff4251';
}
else if (args.series.index === 1) {
args.fill = '#4C4C4C';
}
else if (args.series.index === 2) {
args.fill = '#794F1B';
}
};
return <ChartComponent id='charts' primaryXAxis={primaryxAxis} primaryYAxis={primaryyAxis} title='Sales Comparison' pointRender={pointRender}>
<Inject services={[StackingBarSeries, Legend, Tooltip, DataLabel, Category]}/>
<SeriesCollectionDirective>
<SeriesDirective dataSource={stackBarData} xName='x' yName='y' type='StackingBar'>
</SeriesDirective>
<SeriesDirective dataSource={stackBarData} xName='x' yName='y1' type='StackingBar'>
</SeriesDirective>
<SeriesDirective dataSource={stackBarData} xName='x' yName='y2' type='StackingBar'>
</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, StackingBarSeries, IPointRenderEventArgs}
from'@syncfusion/ej2-react-charts';
import { stackBarData } from './datasource';
function App() {
const primaryxAxis: AxisModel = { valueType: 'Category', title: 'Months' };
const primaryyAxis: AxisModel = {
title: 'Percentage (%)', minimum: -20, maximum: 100,
edgeLabelPlacement: 'Shift', labelFormat: '{value}%'
};
const pointRender = (args: IPointRenderEventArgs) => {
if (args.series.index === 0) {
args.fill = '#ff4251';
}
else if (args.series.index === 1) {
args.fill = '#4C4C4C';
}
else if (args.series.index === 2) {
args.fill = '#794F1B';
}
};
return <ChartComponent id='charts'
primaryXAxis={primaryxAxis}
primaryYAxis={primaryyAxis}
title='Sales Comparison' pointRender={pointRender}>
<Inject services={[StackingBarSeries, Legend, Tooltip, DataLabel, Category]} />
<SeriesCollectionDirective>
<SeriesDirective dataSource={stackBarData} xName='x' yName='y' type='StackingBar'>
</SeriesDirective>
<SeriesDirective dataSource={stackBarData} xName='x' yName='y1' type='StackingBar'>
</SeriesDirective>
<SeriesDirective dataSource={stackBarData} xName='x' yName='y2' type='StackingBar'>
</SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>
};
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));export let stackBarData = [
{ x: 'Jan', y: 6, y1: 6, y2: -1 }, { x: 'Feb', y: 8 , y1: 8, y2: -1.5 },
{ x: 'Mar', y: 12, y1: 11, y2: -2 }, { x: 'Apr', y: 15, y1: 16, y2: -2.5 },
{ x: 'May', y: 20, y1: 21, y2: -3 }, { x: 'Jun', y: 24, y1: 25, y2: -3.5 },
{ x: 'Jul', y: 28, y1: 27, y2: -4 }, { x: 'Aug', y: 32, y1: 31, y2: -4.5 },
{ x: 'Sep', y: 33, y1: 34, y2: -5 }, { x: 'Oct', y: 35, y1: 34, y2: -5.5 },
{ x: 'Nov', y: 40, y1: 41, y2: -6 }, { x: 'Dec', y: 42, y1: 42, y2: -6.5 }
];export let stackBarData: Object[] = [
{ x: 'Jan', y: 6, y1: 6, y2: -1 }, { x: 'Feb', y: 8 , y1: 8, y2: -1.5 },
{ x: 'Mar', y: 12, y1: 11, y2: -2 }, { x: 'Apr', y: 15, y1: 16, y2: -2.5 },
{ x: 'May', y: 20, y1: 21, y2: -3 }, { x: 'Jun', y: 24, y1: 25, y2: -3.5 },
{ x: 'Jul', y: 28, y1: 27, y2: -4 }, { x: 'Aug', y: 32, y1: 31, y2: -4.5 },
{ x: 'Sep', y: 33, y1: 34, y2: -5 }, { x: 'Oct', y: 35, y1: 34, y2: -5.5 },
{ x: 'Nov', y: 40, y1: 41, y2: -6 }, { x: 'Dec', y: 42, y1: 42, y2: -6.5 }
];