Data visualization tools are undeniably important in the day-to-day operations of small, medium, and large enterprises. They play a key role in tracking progress and monitoring key performance metrics and parameters. It would be impossible to understand data patterns without these tools. This is because raw statistics and numbers on a spreadsheet are difficult to comprehend, navigate, and interpret.
If you are a React developer looking to master React graphs, then you have come to the right place. React Graph is one of the best strategic ways to show data in a simple and easy-to-understand way to visualize it using graphs (charts). Read on to find out how you can gain skills at creating React Graphs using the FusionCharts React component in just 6 easy to follow simple steps. Now let’s get started.Table of Contents
npx create-react-app first-fusioncharts-project cd first-fusioncharts-project
npm install fusioncharts react-fusioncharts --saveAfter installing all dependencies open the App.js file in the src project directory. Delete all its contents and add the following at the start of the file to include all the FusionCharts dependencies:
import React from "react"; import ReactDOM from "react-dom"; // Include the react-fusioncharts component import ReactFC from "react-fusioncharts"; // Include the fusioncharts library import FusionCharts from "fusioncharts"; // Include the chart type import Column2D from "fusioncharts/fusioncharts.charts"; // Include the theme as fusion import FusionTheme from "fusioncharts/themes/fusioncharts.theme.fusion"; //Import FusionMaps. Omit if not needed import FusionMaps from 'fusioncharts/maps/es/fusioncharts.world'; import World from 'fusioncharts/fusioncharts.maps' // Adding the chart and theme as dependency to the core fusioncharts // You can omit the components you don't need (column2D, FusionMaps, World) ReactFC.fcRoot(FusionCharts, Column2D, FusionMaps, World, FusionTheme);
const continentData = [ { id: "NA", label: "North America", value: "16.3", showLabel: "1" }, { id: "SA", label: "South America", value: "12.0", showLabel: "1" }, { id: "AS", label: "Asia", value: "30.0", showLabel: "1" }, { id: "EU", label: "Europe", value: "6.7", showLabel: "1" }, { id: "AF", label: "Africa", value: "20.3", showLabel: "1" }, { id: "AU", label: "Australia", value: "5.2", showLabel: "1" } ];
const reactGraphConfigs = { type: "column2d", // The chart type width: "700", // Width of the chart height: "600", // Height of the chart dataFormat: "json", // Data type dataSource: { // Chart Configuration chart: { caption: "Percentage of Land Area on Planet Earth", subCaption: "Data Source: www.enchantedlearning.com", xAxisName: "Continent", yAxisName: "Percentage Land Area", numberSuffix: "%", theme: "umber" }, // Chart Data data: continentData } };
class App extends React.Component { render() { return (<ReactFC {...reactGraphConfigs} />); } } export default App;To view the React graph at the command prompt, type:
npm startThis will automatically load the following React graph in the browser:
const ReactMapConfigs = { type: "world", // Map type width: "600", // Width of the chart height: "400", // Height of the chart dataFormat: "json", // Data Type dataSource: { // Map Configuration chart: { caption: "Percentage of Land Area on Planet Earth", subcaption: "Data Source: www.enchantedlearning.com", numbersuffix: "%", includevalueinlabels: "1", labelsepchar: " - ", entityFillHoverColor: "#FFF9C4", theme: "fusion" }, data: continentData } };Next, render the map by replacing the App class with the following:
class App extends React.Component { render() { return (<ReactFC {...ReactMapConfigs} />); } } export default App;In your browser you’ll see the following map:
reactGraphConfigs
or reactMapConfigs
, depending on what you want to display in the App class. // *** Include Dependencies *** // Include react import React from "react"; import ReactDOM from "react-dom"; // Include the react-fusioncharts component import ReactFC from "react-fusioncharts"; // Include the fusioncharts library import FusionCharts from "fusioncharts"; // Include the chart type import Column2D from "fusioncharts/fusioncharts.charts"; // Include the theme as fusion import FusionTheme from "fusioncharts/themes/fusioncharts.theme.fusion"; /Import FusionMaps. Omit if not needed import FusionMaps from 'fusioncharts/maps/es/fusioncharts.world'; import World from 'fusioncharts/fusioncharts.maps' // Adding the chart and theme as dependency to the core fusioncharts // You can omit the components you don't need (column2D, FusionMaps, World) ReactFC.fcRoot(FusionCharts, Column2D, FusionMaps, World, FusionTheme); // *** Add data source *** const continentData = [ { id: "NA", label: "North America", value: "16.3", showLabel: "1" }, { id: "SA", label: "South America", value: "12.0", showLabel: "1" }, { id: "AS", label: "Asia", value: "30.0", showLabel: "1" }, { id: "EU", label: "Europe", value: "6.7", showLabel: "1" }, { id: "AF", label: "Africa", value: "20.3", showLabel: "1" }, { id: "AU", label: "Australia", value: "5.2", showLabel: "1" } ]; // *** Add JSON object for the React Graph configurations *** const reactGraphConfigs = { type: "column2d", // The chart type width: "700", // Width of the chart height: "600", // Height of the chart dataFormat: "json", // Data type dataSource: { // Chart Configuration chart: { caption: "Percentage of Land Area on Planet Earth", subCaption: "Data Source: www.enchantedlearning.com", xAxisName: "Continent", yAxisName: "Percentage Land Area", numberSuffix: "%", theme: "umber" }, // Chart Data data: continentData } }; const ReactMapConfigs = { type: "world", // Map type width: "600", // Width of the chart height: "400", // Height of the chart dataFormat: "json", // Data Type dataSource: { // Map Configuration chart: { caption: "Percentage of Land Area on Planet Earth", subcaption: "Data Source: www.enchantedlearning.com", numbersuffix: "%", includevalueinlabels: "1", labelsepchar: " - ", entityFillHoverColor: "#FFF9C4", theme: "fusion" }, data: continentData } }; // *** Creating the DOM element to pass the react-fusioncharts component *** class App extends React.Component { render() { //replace by reactGraphConfigs to display the bar chart return (<ReactFC {...ReactMapConfigs} />); } } export default App;
We’re excited to announce the upcoming release of FusionCharts v4.1—a groundbreaking step forward in the…
Have you ever been overwhelmed by a massive data set and wondered, "How do I…
If you’ve ever tried to make sense of the stock market, you’ve probably come across…
Imagine you’re comparing the sales performance of your top product lines across different regions, or…
Have you ever spent hours buried in documentation, hunting for a specific piece of code?…
Do you feel like your data is a cryptic puzzle, locked away from revealing its…