Search results

User Interaction in React Linear Gauge component

30 Jul 2021 / 4 minutes to read

Tooltip

Linear Gauge displays the details about a pointer value through tooltip, when the mouse hovers over the pointer. To enable the tooltip, set enable property as ”true” and inject GaugeTooltip into services.

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,GaugeTooltip, Inject } from '@syncfusion/ej2-react-lineargauge';

ReactDOM.render(
    <LinearGaugeComponent id='gauge' tooltip={ { enable: true } }>
        <Inject services={[GaugeTooltip]}/>
        <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, GaugeTooltip, Inject } from '@syncfusion/ej2-react-lineargauge';
ReactDOM.render(<LinearGaugeComponent id='gauge' tooltip={{ enable: true }}>
        <Inject services={[GaugeTooltip]}/>
        <AxesDirective>
            <AxisDirective>
                <PointersDirective>
                    <PointerDirective value={80}>
                    </PointerDirective>
                </PointersDirective>
            </AxisDirective>
        </AxesDirective>
    </LinearGaugeComponent>, document.getElementById('gauge'));

Tooltip format

Tooltip in the Linear Gauge control can be formatted using the format property in tooltip. It is used to render the tooltip in certain format or to add a user-defined unit in the tooltip. By default, the tooltip shows the pointer value only. In addition to that, more information can be added in the tooltip. For example, the format ”{value}km” shows pointer value with kilometer unit in the tooltip.

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, GaugeTooltip, Inject } from '@syncfusion/ej2-react-lineargauge';

ReactDOM.render(
    <LinearGaugeComponent id='gauge' tooltip={ { enable: true, format: '{value}km' } }>
    <Inject services={[GaugeTooltip]}/>
        <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, GaugeTooltip, Inject } from '@syncfusion/ej2-react-lineargauge';
ReactDOM.render(<LinearGaugeComponent id='gauge' tooltip={{ enable: true, format: '{value}km' }}>
    <Inject services={[GaugeTooltip]}/>
        <AxesDirective>
            <AxisDirective>
                <PointersDirective>
                    <PointerDirective value={80}>
                    </PointerDirective>
                </PointersDirective>
            </AxisDirective>
        </AxesDirective>
    </LinearGaugeComponent>, document.getElementById('gauge'));

Tooltip Template

The HTML elements rendered in the tooltip of the Linear Gauge using the template property of the tooltip. The ”${value}” can be used as placeholders in the HTML element to display the pointer values of the corresponding axis.

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, GaugeTooltip, Inject } from '@syncfusion/ej2-react-lineargauge';

ReactDOM.render(
    <LinearGaugeComponent id='gauge' tooltip={ { enable: true, template: '<div>Pointer: 80 </div>' } }>
    <Inject services={[GaugeTooltip]}/>
        <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, GaugeTooltip, Inject } from '@syncfusion/ej2-react-lineargauge';
ReactDOM.render(<LinearGaugeComponent id='gauge' tooltip={{ enable: true, template: '<div>Pointer: 80 </div>' }}>
    <Inject services={[GaugeTooltip]}/>
        <AxesDirective>
            <AxisDirective>
                <PointersDirective>
                    <PointerDirective value={80}>
                    </PointerDirective>
                </PointersDirective>
            </AxisDirective>
        </AxesDirective>
    </LinearGaugeComponent>, document.getElementById('gauge'));

Customize the appearance of the tooltip

The tooltip can be customized using the following properties in tooltip.

  • fill - To fill the color for tooltip.
  • enableAnimation - To enable or disable the tooltip animation.
  • border - To set the color and width for the border of the tooltip.
  • textStyle - To customize the style of the text in tooltip.
  • showAtMousePosition - To show the tooltip at the mouse position.
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, GaugeTooltip, Inject } from '@syncfusion/ej2-react-lineargauge';

ReactDOM.render(
<LinearGaugeComponent id='gauge' tooltip={ { enable: true, fill: '#e5bcbc', border: { color: '#000000' } } }>
<Inject services={[GaugeTooltip]}/>
    <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, GaugeTooltip, Inject } from '@syncfusion/ej2-react-lineargauge';
ReactDOM.render(<LinearGaugeComponent id='gauge' tooltip={{ enable: true, fill: '#e5bcbc', border: { color: '#000000' } }}>
<Inject services={[GaugeTooltip]}/>
    <AxesDirective>
        <AxisDirective>
            <PointersDirective>
                <PointerDirective value={80}>
                </PointerDirective>
            </PointersDirective>
        </AxisDirective>
    </AxesDirective>
</LinearGaugeComponent>, document.getElementById('gauge'));

Positioning the tooltip

The tooltip is positioned at the ”End” of the pointer. To change the position of the tooltip at the start, or center of the pointer, set the position property to ”Start” or ”Center“.

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, GaugeTooltip, Inject } from '@syncfusion/ej2-react-lineargauge';

ReactDOM.render(
<LinearGaugeComponent id='gauge' tooltip={ { enable: true, position: "Center" } }>
<Inject services={[GaugeTooltip]}/>
    <AxesDirective>
        <AxisDirective>
            <PointersDirective>
                <PointerDirective value={80} 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, GaugeTooltip, Inject } from '@syncfusion/ej2-react-lineargauge';
ReactDOM.render(<LinearGaugeComponent id='gauge' tooltip={{ enable: true, position: "Center" }}>
<Inject services={[GaugeTooltip]}/>
    <AxesDirective>
        <AxisDirective>
            <PointersDirective>
                <PointerDirective value={80} type="Bar">
                </PointerDirective>
            </PointersDirective>
        </AxisDirective>
    </AxesDirective>
</LinearGaugeComponent>, document.getElementById('gauge'));

Pointer Drag

To drag either marker or bar pointer to the desired axis value, set the enableDrag property as ”true” in the 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} enableDrag={true}>
                </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} enableDrag={true}>
                </PointerDirective>
            </PointersDirective>
        </AxisDirective>
    </AxesDirective>
</LinearGaugeComponent>, document.getElementById('gauge'));