Thursday, November 28, 2024
Google search engine
HomeLanguagesReactJS UI Ant Design Statistic Component

ReactJS UI Ant Design Statistic Component

Ant Design Library has this component pre-built, and it is very easy to integrate as well. Statistic Component is used when we want to display statistic numbers. It can be used in applications that have to display statistic data like games applications for scores, cricket scores website, etc. We can use the following approach in ReactJS to use the Ant Design Statistic Component.

Statistic Props:

  • decimalSeparator: It is used to denote the decimal separator.
  • formatter: It is used to customize value display logic.
  • groupSeparator: It is used to denote the group separator.
  • loading: It is used to denote the loading status of Statistic.
  • precision: It is used to set the precision of input value.
  • prefix: It is used to denote the prefix node of value.
  • suffix: It is used to denote the suffix node of value.
  • title: It is used to describe the display title.
  • value: It is used to denote the display value.
  • valueStyle: It is used to set the value CSS style.

Statistic.Countdown Props:

  • format: It is used to denote the format as moment.
  • prefix: It is used to denote the prefix node of value.
  • suffix: It is used to denote the suffix node of value.
  • title: It is used to describe the display title.
  • value: It is used to set the target countdown time.
  • valueStyle: It is used to set the value CSS style.
  • onFinish: It is a callback function that is trigger when time’s up.
  • onChange: It is triggered when time changes.

Creating React Application And Installing Module:

  • Step 1: Create a React application using the following command:

    npx create-react-app foldername
  • Step 2: After creating your project folder i.e. foldername, move to it using the following command:

    cd foldername
  • Step 3: After creating the ReactJS application, Install the required module using the following command:

    npm install antd

Project Structure: It will look like the following.

Project Structure

Example: Now write down the following code in the App.js file. Here, App is our default component where we have written our code.

App.js




import React from 'react'
import "antd/dist/antd.css";
import { Statistic } from 'antd';
  
const { Countdown } = Statistic;
const deadline = Date.now() + 1000 * 60 ; 
  
export default function App() {
  return (
    <div style={{
      display: 'block', width: 700, padding: 30
    }}>
      <h4>ReactJS Ant-Design Statistic Component</h4>
      <Countdown title="1 Minute Timer:" 
        value={deadline} 
      format="HH:mm:ss:SSS" />
    </div>
  );
}


Step to Run Application: Run the application using the following command from the root directory of the project:

npm start

Output: Now open your browser and go to http://localhost:3000/, you will see the following output:

Reference: https://ant.design/components/statistic/

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!

RELATED ARTICLES

Most Popular

Recent Comments