Search results

Getting started with React Circular Gauge component

12 May 2022 / 3 minutes to read

This section explains you the steps required to create a simple circular gauge and demonstrate the basic usage of circular gauge control.

Dependencies

Following is the list of minimum dependencies required to use the Circular Gauge.

Copied to clipboard
|-- @syncfusion/ej2-react-circulargauge
    |-- @syncfusion/ej2-react-base
|-- @syncfusion/ej2-circulargauge
    |-- @syncfusion/ej2-base
    |-- @syncfusion/ej2-svg-base
    |-- @syncfusion/ej2-paf-export

Installation and configuration

To get started with the React application, create-react-app can be used to setup the application. To install create-react-app run the following command.

Copied to clipboard
npm install -g create-react-app

To create basic React application, run the following command.

Copied to clipboard
create-react-app quickstart

Now, the application is created in the quickstart folder. Run the following command one-by-one to navigate to the quickstart folder, and install the required npm packages.

Copied to clipboard
cd quickstart

npm install

In the quickstart application, the Syncfusion component is added in the JavaScript file.

Creating a React application with TypeScript

To create React application with TypeScript, use the following command.

Copied to clipboard
create-react-app quickstart --template typescript

Now, the application is created in the quickstart folder. Run the following command one-by-one to navigate to the quickstart folder, and install the required npm packages.

Copied to clipboard
cd quickstart

npm install

Adding Syncfusion packages

All the available Essential JS 2 packages are published in npmjs.com public registry. To install Circular Gauge package, use the following command.

Copied to clipboard
npm install @syncfusion/ej2-react-circulargauge --save

Adding Circular Gauge component to the Project

Now, the Circular Gauge component can be added in the application. To initialize the Circular Gauge control in the React application, import the Circular Gauge control in the src/App.js or src/App.tsx as per the application. Please use the below code to include the Circular Gauge component in the application.

Copied to clipboard
import React from 'react';
import { CircularGaugeComponent } from '@syncfusion/ej2-react-circulargauge';

function App() {
   return (<CircularGaugeComponent></CircularGaugeComponent>);
}
export default App;

Run the application

The Circular Gauge control is now included in the quickstart application. Use the following command to run the application.

Copied to clipboard
npm start

The below example shows the basic Circular Gauge.

Source
Preview
index.jsx
index.tsx
Copied to clipboard
import * as React from "react";
import * as ReactDOM from "react-dom";
import { CircularGaugeComponent } from '@syncfusion/ej2-react-circulargauge';
ReactDOM.render(<CircularGaugeComponent id='circulargauge'></CircularGaugeComponent>, document.getElementById('circulargauge'));
Copied to clipboard
import * as React from "react";
import * as ReactDOM from "react-dom";
import { CircularGaugeComponent } from '@syncfusion/ej2-react-circulargauge';
ReactDOM.render(<CircularGaugeComponent id='circulargauge'></CircularGaugeComponent>, document.getElementById('circulargauge'));

Set Pointer Value

You can change the pointer value in the above sample using value property in pointers.

Source
Preview
index.jsx
index.tsx
Copied to clipboard
import * as React from "react";
import * as ReactDOM from "react-dom";
import { CircularGaugeComponent, AxesDirective, AxisDirective, PointersDirective, PointerDirective } from '@syncfusion/ej2-react-circulargauge';
ReactDOM.render(<CircularGaugeComponent id='circulargauge'>
    <AxesDirective>
      <AxisDirective>
        <PointersDirective>
          <PointerDirective value={35}></PointerDirective>
        </PointersDirective>
      </AxisDirective>
    </AxesDirective>
  </CircularGaugeComponent>, document.getElementById('circulargauge'));
Copied to clipboard
import * as React from "react";
import * as ReactDOM from "react-dom";
import { CircularGaugeComponent, AxesDirective, AxisDirective, PointersDirective, PointerDirective } from '@syncfusion/ej2-react-circulargauge';
ReactDOM.render(
  <CircularGaugeComponent id='circulargauge'>
    <AxesDirective>
      <AxisDirective>
        <PointersDirective>
          <PointerDirective value={35}></PointerDirective>
        </PointersDirective>
      </AxisDirective>
    </AxesDirective>
  </CircularGaugeComponent>,document.getElementById('circulargauge'));