Articles in this section
Category / Section

How to create a Tornado Chart in React Chart?

5 mins read

This article explains the process of creating a Tornado Chart in the React Chart.

Create a tornado chart

The tornado chart is a unique variation of a bar chart where bars extend from a defined baseline. It is commonly used to compare data across different categories and visualize the impact of various conditions on the final outcome. In a tornado chart, the bars are arranged horizontally.

In the following code example, you can create the tornado chart using the stacking bar series.

Index.js

import { createRoot } from 'react-dom/client';
import * as React from 'react';
import { ChartComponent, SeriesCollectionDirective, SeriesDirective, Inject, Legend, Category, StackingBarSeries,
 Tooltip, DataLabel, Highlight } from '@syncfusion/ej2-react-charts';
import { Browser } from '@syncfusion/ej2-base';

export let data = [
 { x: 'Factor A', y: 25, text: '25' },
 { x: 'Factor B', y: 18, text: '18' },
 { x: 'Factor C', y: 12, text: '12' },
 { x: 'Factor D', y: 8, text: '8' },
 { x: 'Factor E', y: 15, text: '15' },
 { x: 'Factor F', y: 10, text: '10' },
 { x: 'Factor G', y: 20, text: '20' },
 { x: 'Factor H', y: 16, text: '16' },
 { x: 'Factor I', y: 22, text: '22' },
 { x: 'Factor J', y: 28, text: '28' }
];
export let data2 = [
 { x: 'Factor A', y: -15, text: '15' },
 { x: 'Factor B', y: -12, text: '12' },
 { x: 'Factor C', y: -8, text: '8' },
 { x: 'Factor D', y: -6, text: '6' },
 { x: 'Factor E', y: -10, text: '10' },
 { x: 'Factor F', y: -5, text: '5' },
 { x: 'Factor G', y: -14, text: '14' },
 { x: 'Factor H', y: -11, text: '11' },
 { x: 'Factor I', y: -13, text: '13' },
 { x: 'Factor J', y: -18, text: '18' }
];

function textRender(args) {
   args.text = args.text.indexOf('-') > 0 ? args.text.replace('-', '') : args.text;
};

function dataLabelRender(args) {
   args.text = args.text.indexOf('-') > -1 ? args.text.replace('-', '') : args.text;
};

function labelRender(args) {
   if (args.value < 0) {
       args.text = (-args.value).toString();
   }
};

const NegativeStack = () => {
 return (
       <ChartComponent
         id="charts"
         primaryXAxis={{
           valueType: 'Category',
           title: 'Factors',
           interval: 1
         }}
         primaryYAxis={{
           labelFormat: '{value}',
           title: 'Impact Value',
           edgeLabelPlacement: 'Shift',
           rangePadding: 'Round'
         }}
         tooltipRender={textRender.bind(this)}
         dataLabelRender={dataLabelRender.bind(this)}
         axisLabelRender={labelRender.bind(this)}
         legendSettings={{
           position: Browser.isDevice ? 'Bottom' : 'Right',
           enableHighlight: true
         }}
         title="Comparison of Factors Impact Values"
         tooltip={{ enable: true }}
       >
         <Inject
           services={[ StackingBarSeries, DataLabel, Category, Legend, Tooltip, Highlight ]}
         />
         <SeriesCollectionDirective>
           <SeriesDirective
             dataSource={data}
             width={2}
             xName="x"
             yName="y"
             name="Positive Impact"
             columnWidth={0.5}
             type="StackingBar"
             marker={{
               dataLabel: {
                 name: 'text',
                 visible: true,
                 position: 'Top',
                 font: { fontWeight: '600' }
               }
             }}
           />
           <SeriesDirective
             dataSource={data2}
             width={2}
             xName="x"
             yName="y"
             name="Negative Impact"
             columnWidth={0.5}
             type="StackingBar"
             marker={{
               dataLabel: {
                 name: 'text',
                 visible: true,
                 position: 'Top',
                 font: { fontWeight: '600' }
               }
             }}
           />
         </SeriesCollectionDirective>
       </ChartComponent>
    );
};
export default NegativeStack;

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

The following screenshot illustrate the output of the above code snippet.

Screenshot:

React tornado chart

View Sample in Stackblitz

Conclusion

I hope you enjoyed learning how to create a Tornado Chart in the React Chart Component.

You can refer to our React Chart feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our React Chart example to understand how to create and manipulate data.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, support portal, or feedback portal. We are always happy to assist you!

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