Search results

Annotations in React Linear Gauge component

22 Jul 2021 / 3 minutes to read

Annotations are used to mark the specific area of interest in the Linear Gauge with text, HTML elements, or images. Any number of annotations can be added to the Linear Gauge component.

Adding annotation

To render the custom HTML elements in the Linear Gauge component, use the content property in the AnnotationDirective. The annotation can be rendered either by specifying the id of the element or specifying the code to create a new element that needs to be displayed in the gauge area.

Copied to clipboard
<script id='fruits' type="text/x-template">
   <div id='apple'>
       <img src='src/lineargauge/images/apple.png'>
   </div>
</script>
Copied to clipboard
import * as React from "react";
import * as ReactDOM from "react-dom";
import { LinearGaugeComponent, AnnotationsDirective, AnnotationDirective, Annotations, Inject } from '@syncfusion/ej2-react-lineargauge';

ReactDOM.render(
    <LinearGaugeComponent>
        <Inject services={[Annotations]}/>
        <AnnotationsDirective>
            <AnnotationDirective content='#fruits' x={100} zIndex='1' y={100}>
            </AnnotationDirective>
        </AnnotationsDirective>
    </LinearGaugeComponent>,document.getElementById('gauge'));

Customization

The following properties are used to customize the annotation.

  • zIndex - This property is used to bring the annotation to the front or back, when annotation overlaps with another element.
  • axisValue - This property is used to place the annotation in the specified axis value with respect to the provided axis index.
  • axisIndex - This property is used to place the annotation in the specified axis with respect to the provided axis value.
  • horizontalAlignment - This property is used to place the annotation horizontally.
  • verticalAlignment - This property is used to place the annotation vertically.
  • x, y - This property is used to place the annotation in the specified location.

Changing the z-index

To change the stack order of an annotation element, the zIndex property of the AnnotationDirective can be used.

Source
Preview
index.tsx
index.jsx
Copied to clipboard
import * as React from "react";
import * as ReactDOM from "react-dom";
import { LinearGaugeComponent, AnnotationsDirective, AnnotationDirective, Annotations,Inject } from '@syncfusion/ej2-react-lineargauge';

ReactDOM.render(
<LinearGaugeComponent  id='gauge'>
    <Inject services={[Annotations]}/>
    <AnnotationsDirective>
        <AnnotationDirective content='<div id="first"><h1>Gauge</h1></div>' zIndex='1' >
        </AnnotationDirective>
    </AnnotationsDirective>
</LinearGaugeComponent>,document.getElementById('gauge'));
Copied to clipboard
import * as React from "react";
import * as ReactDOM from "react-dom";
import { LinearGaugeComponent, AnnotationsDirective, AnnotationDirective, Annotations, Inject } from '@syncfusion/ej2-react-lineargauge';
ReactDOM.render(<LinearGaugeComponent id='gauge'>
    <Inject services={[Annotations]}/>
    <AnnotationsDirective>
        <AnnotationDirective content='<div id="first"><h1>Gauge</h1></div>' zIndex='1'>
        </AnnotationDirective>
    </AnnotationsDirective>
</LinearGaugeComponent>, document.getElementById('gauge'));

Positioning an annotation

The annotation can be placed anywhere in the Linear Gauge by setting the pixel value to the x and y properties in the AnnotationDirective.

Source
Preview
index.tsx
index.jsx
Copied to clipboard
import * as React from "react";
import * as ReactDOM from "react-dom";
import { LinearGaugeComponent, AnnotationsDirective, AnnotationDirective, Annotations, Inject } from '@syncfusion/ej2-react-lineargauge';

ReactDOM.render(
<LinearGaugeComponent  id='gauge'>
    <Inject services={[Annotations]}/>
    <AnnotationsDirective>
        <AnnotationDirective content='<div id="first"><h1>Gauge</h1></div>' x={100} y={100} zIndex='1' >
        </AnnotationDirective>
    </AnnotationsDirective>
</LinearGaugeComponent>,document.getElementById('gauge'));
Copied to clipboard
import * as React from "react";
import * as ReactDOM from "react-dom";
import { LinearGaugeComponent, AnnotationsDirective, AnnotationDirective, Annotations, Inject } from '@syncfusion/ej2-react-lineargauge';
ReactDOM.render(<LinearGaugeComponent id='gauge'>
    <Inject services={[Annotations]}/>
    <AnnotationsDirective>
        <AnnotationDirective content='<div id="first"><h1>Gauge</h1></div>' x={100} y={100} zIndex='1'>
        </AnnotationDirective>
    </AnnotationsDirective>
</LinearGaugeComponent>, document.getElementById('gauge'));

Alignment of annotation

The annotation can be aligned horizontally and vertically by using the horizontalAlignment and verticalAlignment properties respectively. The possible values can be ”Center”, ”Far”, ”Near”, and ”None”. The horizontalAlignment and verticalAlignment properties are not applicable when the x and y properties are set in the AnnotationDirective.

Source
Preview
index.tsx
index.jsx
Copied to clipboard
import * as React from "react";
import * as ReactDOM from "react-dom";
import { LinearGaugeComponent, AnnotationsDirective, AnnotationDirective, Annotations, Inject } from '@syncfusion/ej2-react-lineargauge';

ReactDOM.render(
<LinearGaugeComponent  id='gauge'>
    <Inject services={[Annotations]}/>
    <AnnotationsDirective>
        <AnnotationDirective content='<div id="first"><h1>Gauge</h1></div>' verticalAlignment="Center" horizontalAlignment="Center" zIndex='1' >
        </AnnotationDirective>
    </AnnotationsDirective>
</LinearGaugeComponent>,document.getElementById('gauge'));
Copied to clipboard
import * as React from "react";
import * as ReactDOM from "react-dom";
import { LinearGaugeComponent, AnnotationsDirective, AnnotationDirective, Annotations, Inject } from '@syncfusion/ej2-react-lineargauge';
ReactDOM.render(<LinearGaugeComponent id='gauge'>
    <Inject services={[Annotations]}/>
    <AnnotationsDirective>
        <AnnotationDirective content='<div id="first"><h1>Gauge</h1></div>' verticalAlignment="Center" horizontalAlignment="Center" zIndex='1'>
        </AnnotationDirective>
    </AnnotationsDirective>
</LinearGaugeComponent>, document.getElementById('gauge'));

Multiple annotations

Multiple annotations can be added to the Linear Gauge component by adding the multiple AnnotationDirective in the AnnotationsDirective and customization for the annotation can be done with the AnnotationDirective.

Source
Preview
index.tsx
index.jsx
Copied to clipboard
import * as React from "react";
import * as ReactDOM from "react-dom";
import { LinearGaugeComponent, AnnotationsDirective, AnnotationDirective, Annotations, Inject } from '@syncfusion/ej2-react-lineargauge';

ReactDOM.render(
<LinearGaugeComponent  id='gauge'>
    <Inject services={[Annotations]}/>
    <AnnotationsDirective>
        <AnnotationDirective content='<div><h1 style="color:red;">Speed</h1></div>' verticalAlignment='Near' horizontalAlignment='Center' zIndex='1'>
        </AnnotationDirective>
        <AnnotationDirective content='<div><h1 style="color:blue;">Meter</h1></div>' zIndex='1' x={150} y={400}>
        </AnnotationDirective>
    </AnnotationsDirective>
</LinearGaugeComponent>,document.getElementById('gauge'));
Copied to clipboard
import * as React from "react";
import * as ReactDOM from "react-dom";
import { LinearGaugeComponent, AnnotationsDirective, AnnotationDirective, Annotations, Inject } from '@syncfusion/ej2-react-lineargauge';
ReactDOM.render(<LinearGaugeComponent id='gauge'>
    <Inject services={[Annotations]}/>
    <AnnotationsDirective>
        <AnnotationDirective content='<div><h1 style="color:red;">Speed</h1></div>' verticalAlignment='Near' horizontalAlignment='Center' zIndex='1'>
        </AnnotationDirective>
        <AnnotationDirective content='<div><h1 style="color:blue;">Meter</h1></div>' zIndex='1' x={150} y={400}>
        </AnnotationDirective>
    </AnnotationsDirective>
</LinearGaugeComponent>, document.getElementById('gauge'));