Search results

Pointers in React Linear Gauge component

22 Jul 2021 / 7 minutes to read

Pointers are used to indicate values on an axis. The value of the pointer can be modified using the value property in PointerDirective.

Source
Preview
index.tsx
index.jsx
Copied to clipboard
import * as React from "react";
import * as ReactDOM from "react-dom";
import { LinearGaugeComponent, AxesDirective, AxisDirective, PointersDirective, PointerDirective } from '@syncfusion/ej2-react-lineargauge';

ReactDOM.render(
    <LinearGaugeComponent id='gauge'>
        <AxesDirective>
            <AxisDirective>
                <PointersDirective>
                    <PointerDirective value={80}>
                    </PointerDirective>
                </PointersDirective>
            </AxisDirective>
        </AxesDirective>
    </LinearGaugeComponent>,document.getElementById('gauge'));
Copied to clipboard
import * as React from "react";
import * as ReactDOM from "react-dom";
import { LinearGaugeComponent, AxesDirective, AxisDirective, PointersDirective, PointerDirective } from '@syncfusion/ej2-react-lineargauge';
ReactDOM.render(<LinearGaugeComponent id='gauge'>
        <AxesDirective>
            <AxisDirective>
                <PointersDirective>
                    <PointerDirective value={80}>
                    </PointerDirective>
                </PointersDirective>
            </AxisDirective>
        </AxesDirective>
    </LinearGaugeComponent>, document.getElementById('gauge'));

Types of pointer

The Linear Gauge supports the following types of pointers:

  • Bar
  • Marker

The type of pointer can be modified by using the type property in PointerDirective.

Marker pointer

A marker pointer is a shape that can be used to mark the pointer value in the Linear Gauge.

Types of marker shapes

By default, the marker shape for the pointer is ”InvertedTriangle”. To change the shape of the pointer, use the markerType property in PointerDirective. The following marker types are available in Linear Gauge.

  • Circle
  • Rectangle
  • Triangle
  • InvertedTriangle
  • Diamond
  • Image

An image can be rendered instead of rendering a shape as a pointer. It can be achieved by setting the markerType property to ”Image” and setting the source URL of image to imageUrl property in PointerDirective.

Source
Preview
index.tsx
index.jsx
Copied to clipboard
import * as React from "react";
import * as ReactDOM from "react-dom";
import { LinearGaugeComponent, AxesDirective, AxisDirective, PointersDirective, PointerDirective } from '@syncfusion/ej2-react-lineargauge';

ReactDOM.render(
<LinearGaugeComponent id='gauge'>
    <AxesDirective>
        <AxisDirective>
            <PointersDirective>
                <PointerDirective value={80} type='Marker' markerType='Circle'>
                </PointerDirective>
            </PointersDirective>
        </AxisDirective>
    </AxesDirective>
</LinearGaugeComponent>,document.getElementById('gauge'));
Copied to clipboard
import * as React from "react";
import * as ReactDOM from "react-dom";
import { LinearGaugeComponent, AxesDirective, AxisDirective, PointersDirective, PointerDirective } from '@syncfusion/ej2-react-lineargauge';
ReactDOM.render(<LinearGaugeComponent id='gauge'>
    <AxesDirective>
        <AxisDirective>
            <PointersDirective>
                <PointerDirective value={80} type='Marker' markerType='Circle'>
                </PointerDirective>
            </PointersDirective>
        </AxisDirective>
    </AxesDirective>
</LinearGaugeComponent>, document.getElementById('gauge'));

Marker Pointer Customization

The marker pointer can be customized using the following properties.

  • height - To set the height of the pointer.
  • position - The position of the pointer can be changed by setting the value as ”Inside”, ”Outside”, ”Cross”, or ”Auto“.
  • width - To set the width of the pointer.
  • color - To set the color of the pointer.
  • placement - To place the pointer in the specified position. By default, the pointer is placed ”Far” from the axis. To change the placement, set the placement property as ”Near”, ”Center”, or ”None“.
  • offset - To place the pointer with specified distance from the axis.
  • opacity - To set the opacity of the pointer.
  • animationDuration - To specify the duration of the animation in pointer.
  • border - To set the color and width for the border of the pointer.
Source
Preview
index.tsx
index.jsx
Copied to clipboard
import * as React from "react";
import * as ReactDOM from "react-dom";
import { LinearGaugeComponent, AxesDirective, AxisDirective, PointersDirective, PointerDirective } from '@syncfusion/ej2-react-lineargauge';

ReactDOM.render(
<LinearGaugeComponent id='gauge'>
    <AxesDirective>
        <AxisDirective>
            <PointersDirective>
                <PointerDirective value={80} type='Marker' markerType='Circle' height={15} width={15} color='#cd41f4'>
                </PointerDirective>
            </PointersDirective>
        </AxisDirective>
    </AxesDirective>
</LinearGaugeComponent>,document.getElementById('gauge'));
Copied to clipboard
import * as React from "react";
import * as ReactDOM from "react-dom";
import { LinearGaugeComponent, AxesDirective, AxisDirective, PointersDirective, PointerDirective } from '@syncfusion/ej2-react-lineargauge';
ReactDOM.render(<LinearGaugeComponent id='gauge'>
    <AxesDirective>
        <AxisDirective>
            <PointersDirective>
                <PointerDirective value={80} type='Marker' markerType='Circle' height={15} width={15} color='#cd41f4'>
                </PointerDirective>
            </PointersDirective>
        </AxisDirective>
    </AxesDirective>
</LinearGaugeComponent>, document.getElementById('gauge'));

Bar Pointer

The bar pointer is used to track the axis value. The bar pointer starts from the beginning of the gauge and ends at the pointer value. To enable bar pointer set the type property in PointerDirective as ”Bar“.

Source
Preview
index.tsx
index.jsx
Copied to clipboard
import * as React from "react";
import * as ReactDOM from "react-dom";
import { LinearGaugeComponent, AxesDirective, AxisDirective, PointersDirective, PointerDirective } from '@syncfusion/ej2-react-lineargauge';

ReactDOM.render(
<LinearGaugeComponent id='gauge'>
    <AxesDirective>
        <AxisDirective>
            <PointersDirective>
                <PointerDirective value={60} type='Bar'>
                </PointerDirective>
            </PointersDirective>
        </AxisDirective>
    </AxesDirective>
</LinearGaugeComponent>,document.getElementById('gauge'));
Copied to clipboard
import * as React from "react";
import * as ReactDOM from "react-dom";
import { LinearGaugeComponent, AxesDirective, AxisDirective, PointersDirective, PointerDirective } from '@syncfusion/ej2-react-lineargauge';
ReactDOM.render(<LinearGaugeComponent id='gauge'>
    <AxesDirective>
        <AxisDirective>
            <PointersDirective>
                <PointerDirective value={60} type='Bar'>
                </PointerDirective>
            </PointersDirective>
        </AxisDirective>
    </AxesDirective>
</LinearGaugeComponent>, document.getElementById('gauge'));

Bar pointer customization

The bar pointer can be customized using following properties.

  • width - To set the thickness of the bar pointer.
  • color - To set the color of the bar pointer.
  • offset - To place the bar pointer with the specified distance from it’s default position.
  • opacity - To set the opacity of the bar pointer.
  • roundedCornerRadius - To set the corner radius for the bar pointer.
  • border - To set the color and width for the border of the pointer.
  • animationDuration - To set the duration of the animation in bar pointer.

Note: The placement property is not applicable for the bar pointer.

Source
Preview
index.tsx
index.jsx
Copied to clipboard
import * as React from "react";
import * as ReactDOM from "react-dom";
import { LinearGaugeComponent, AxesDirective, AxisDirective, PointersDirective, PointerDirective } from '@syncfusion/ej2-react-lineargauge';

ReactDOM.render(
<LinearGaugeComponent id='gauge'>
    <AxesDirective>
        <AxisDirective>
            <PointersDirective>
                <PointerDirective value={60} type='Bar' width={20} color='#f44141'>
                </PointerDirective>
            </PointersDirective>
        </AxisDirective>
    </AxesDirective>
</LinearGaugeComponent>,document.getElementById('gauge'));
Copied to clipboard
import * as React from "react";
import * as ReactDOM from "react-dom";
import { LinearGaugeComponent, AxesDirective, AxisDirective, PointersDirective, PointerDirective } from '@syncfusion/ej2-react-lineargauge';
ReactDOM.render(<LinearGaugeComponent id='gauge'>
    <AxesDirective>
        <AxisDirective>
            <PointersDirective>
                <PointerDirective value={60} type='Bar' width={20} color='#f44141'>
                </PointerDirective>
            </PointersDirective>
        </AxisDirective>
    </AxesDirective>
</LinearGaugeComponent>, document.getElementById('gauge'));

Multiple pointers

Multiple pointers can be added to the Linear Gauge by adding multiple PointerDirective in the PointersDirective and customization for the pointers can be done with PointerDirective.

Source
Preview
index.tsx
index.jsx
Copied to clipboard
import * as React from "react";
import * as ReactDOM from "react-dom";
import { LinearGaugeComponent, AxesDirective, AxisDirective, PointersDirective, PointerDirective } from '@syncfusion/ej2-react-lineargauge';

ReactDOM.render(
<LinearGaugeComponent id='gauge'>
    <AxesDirective>
        <AxisDirective>
            <PointersDirective>
                <PointerDirective value={80}>
                </PointerDirective>
                <PointerDirective value={60} markerType='Circle'>
                </PointerDirective>
                <PointerDirective value={30} markerType='Diamond'>
                </PointerDirective>
            </PointersDirective>
        </AxisDirective>
    </AxesDirective>
</LinearGaugeComponent>,document.getElementById('gauge'));
Copied to clipboard
import * as React from "react";
import * as ReactDOM from "react-dom";
import { LinearGaugeComponent, AxesDirective, AxisDirective, PointersDirective, PointerDirective } from '@syncfusion/ej2-react-lineargauge';
ReactDOM.render(<LinearGaugeComponent id='gauge'>
    <AxesDirective>
        <AxisDirective>
            <PointersDirective>
                <PointerDirective value={80}>
                </PointerDirective>
                <PointerDirective value={60} markerType='Circle'>
                </PointerDirective>
                <PointerDirective value={30} markerType='Diamond'>
                </PointerDirective>
            </PointersDirective>
        </AxisDirective>
    </AxesDirective>
</LinearGaugeComponent>, document.getElementById('gauge'));

Pointer animation

Pointer is animated on loading the gauge. This can be handled using the animationDuration property. The duration of the animation can be specified in milliseconds.

Source
Preview
index.tsx
index.jsx
Copied to clipboard
import * as React from "react";
import * as ReactDOM from "react-dom";
import { LinearGaugeComponent, AxesDirective, AxisDirective, PointersDirective, PointerDirective } from '@syncfusion/ej2-react-lineargauge';

ReactDOM.render(
<LinearGaugeComponent id='gauge'>
    <AxesDirective>
        <AxisDirective>
            <PointersDirective>
                <PointerDirective value={60} animationDuration={1000}>
                </PointerDirective>
            </PointersDirective>
        </AxisDirective>
    </AxesDirective>
</LinearGaugeComponent>,document.getElementById('gauge'));
Copied to clipboard
import * as React from "react";
import * as ReactDOM from "react-dom";
import { LinearGaugeComponent, AxesDirective, AxisDirective, PointersDirective, PointerDirective } from '@syncfusion/ej2-react-lineargauge';
ReactDOM.render(<LinearGaugeComponent id='gauge'>
    <AxesDirective>
        <AxisDirective>
            <PointersDirective>
                <PointerDirective value={60} animationDuration={1000}>
                </PointerDirective>
            </PointersDirective>
        </AxisDirective>
    </AxesDirective>
</LinearGaugeComponent>, document.getElementById('gauge'));

Gradient Color

Gradient support allows the addition of multiple colors in the pointers of the Linear Gauge. The following gradient types are supported in the Linear Gauge.

  • Linear Gradient
  • Radial Gradient

Linear Gradient

Using linear gradient, colors will be applied in a linear progression. The start value of the linear gradient can be set using the startValue property. The end value of the linear gradient will be set using the endValue property. The color stop values such as color, opacity, and offset are set using colorStop property. The linear gradient can be rendered for the pointer in the Linear Gauge by using the below example.

Source
Preview
index.tsx
index.jsx
Copied to clipboard
import * as React from "react";
import * as ReactDOM from "react-dom";
import { LinearGaugeComponent, AxesDirective, AxisDirective, PointersDirective, PointerDirective, RangesDirective, Gradient, Inject, RangeDirective } from '@syncfusion/ej2-react-lineargauge';

ReactDOM.render(
<LinearGaugeComponent id='gauge' container={{width: 30, offset: 30}} orientation="Horizontal">
<Inject services={[Gradient]}/>
    <AxesDirective>
        <AxisDirective minimum={0} maximum={100} line={{width: 0}} majorTicks={{width: 0, interval:25}}
            minorTicks={{width:  0}} labelStyle={{font: {color: '#424242'}, offset: 70}}>
            <PointersDirective>
                <PointerDirective value={80} height={25} width={35} placement="Near" offset={-44}markerType="Triangle"
                linearGradient={{
                    startValue: '0%',
                    endValue: '100%',
                    colorStop: [
                    { color: '#fef3f9', offset: '0%', opacity: 1 },
                    { color: '#f54ea2', offset: '100%', opacity: 1 }]
                }}>
                </PointerDirective>
            </PointersDirective>
            <RangesDirective>
                <RangeDirective start={0} end={80} startWidth={30} endWidth={30} color="#f54ea2" offset={30}>
                </RangeDirective>
            </RangesDirective>
        </AxisDirective>
    </AxesDirective>
</LinearGaugeComponent>,document.getElementById('gauge'));
Copied to clipboard
import * as React from "react";
import * as ReactDOM from "react-dom";
import { LinearGaugeComponent, AxesDirective, AxisDirective, PointersDirective, PointerDirective, RangesDirective, Gradient, Inject, RangeDirective } from '@syncfusion/ej2-react-lineargauge';
ReactDOM.render(<LinearGaugeComponent id='gauge' container={{ width: 30, offset: 30 }} orientation="Horizontal">
<Inject services={[Gradient]}/>
    <AxesDirective>
        <AxisDirective minimum={0} maximum={100} line={{ width: 0 }} majorTicks={{ width: 0, interval: 25 }} minorTicks={{ width: 0 }} labelStyle={{ font: { color: '#424242' }, offset: 70 }}>
            <PointersDirective>
                <PointerDirective value={80} height={25} width={35} placement="Near" offset={-44} markerType="Triangle" linearGradient={{
    startValue: '0%',
    endValue: '100%',
    colorStop: [
        { color: '#fef3f9', offset: '0%', opacity: 1 },
        { color: '#f54ea2', offset: '100%', opacity: 1 }
    ]
}}>
                </PointerDirective>
            </PointersDirective>
            <RangesDirective>
                <RangeDirective start={0} end={80} startWidth={30} endWidth={30} color="#f54ea2" offset={30}>
                </RangeDirective>
            </RangesDirective>
        </AxisDirective>
    </AxesDirective>
</LinearGaugeComponent>, document.getElementById('gauge'));

Radial Gradient

Using radial gradient, colors will be applied in circular progression. The inner circle position of the radial gradient will be set using the innerPosition property. The outer circle position of the radial gradient can be set using the outerPosition property. The color stop values such as color, opacity, and offset are set using colorStop property. The radial gradient can be rendered for the pointer in the Linear Gauge by using the below example.

Source
Preview
index.tsx
index.jsx
Copied to clipboard
import * as React from "react";
import * as ReactDOM from "react-dom";
import { LinearGaugeComponent, AxesDirective, AxisDirective, PointersDirective, PointerDirective, RangesDirective, Gradient, Inject, RangeDirective } from '@syncfusion/ej2-react-lineargauge';

ReactDOM.render(
<LinearGaugeComponent id='gauge' container={{width: 30, offset: 30}} orientation="Horizontal">
<Inject services={[Gradient]}/>
    <AxesDirective>
        <AxisDirective minimum={0} maximum={100} line={{width: 0}} majorTicks={{width: 0, interval: 25}}
            minorTicks={{width:  0}} labelStyle={{font: {color: '#424242'}, offset: 70}}>
            <PointersDirective>
                <PointerDirective value={80} height={25} width={35} placement="Near" offset={-44}markerType="Triangle"
                radialGradient={{
                   radius: '60%',
                   outerPosition: { x: '50%', y: '50%' },
                   innerPosition: { x: '50%', y: '50%' },
                   colorStop: [
                   { color: '#fff5f5', offset: '0%', opacity: 0.9 },
                   { color: '#f54ea2', offset: '100%', opacity: 0.8 }]
                }}>
                </PointerDirective>
            </PointersDirective>
            <RangesDirective>
                <RangeDirective start={0} end={80} startWidth={30} endWidth={30} color="#f54ea2" offset={30}>
                </RangeDirective>
            </RangesDirective>
        </AxisDirective>
    </AxesDirective>
</LinearGaugeComponent>,document.getElementById('gauge'));
Copied to clipboard
import * as React from "react";
import * as ReactDOM from "react-dom";
import { LinearGaugeComponent, AxesDirective, AxisDirective, PointersDirective, PointerDirective, RangesDirective, Gradient, Inject, RangeDirective } from '@syncfusion/ej2-react-lineargauge';
ReactDOM.render(<LinearGaugeComponent id='gauge' container={{ width: 30, offset: 30 }} orientation="Horizontal">
<Inject services={[Gradient]}/>
    <AxesDirective>
        <AxisDirective minimum={0} maximum={100} line={{ width: 0 }} majorTicks={{ width: 0, interval: 25 }} minorTicks={{ width: 0 }} labelStyle={{ font: { color: '#424242' }, offset: 70 }}>
            <PointersDirective>
                <PointerDirective value={80} height={25} width={35} placement="Near" offset={-44} markerType="Triangle" radialGradient={{
    radius: '60%',
    outerPosition: { x: '50%', y: '50%' },
    innerPosition: { x: '50%', y: '50%' },
    colorStop: [
        { color: '#fff5f5', offset: '0%', opacity: 0.9 },
        { color: '#f54ea2', offset: '100%', opacity: 0.8 }
    ]
}}>
                </PointerDirective>
            </PointersDirective>
            <RangesDirective>
                <RangeDirective start={0} end={80} startWidth={30} endWidth={30} color="#f54ea2" offset={30}>
                </RangeDirective>
            </RangesDirective>
        </AxisDirective>
    </AxesDirective>
</LinearGaugeComponent>, document.getElementById('gauge'));

Note: If we set both gradients, only the linear gradient gets rendered. If we set the startValue and endValue of the linearGradient as empty strings, then the radial gradient gets rendered in the pointer of the Linear Gauge.