Search results

Annotations in React Linear Gauge component

Annotations are used to mark the specific area of interest in the gauge area with texts, shapes or images. You can add any number of annotations to the gauge.

Annotation

By using the content property of annotation object, you can either specify the id of the element or specify the code to create a new element, that needs to be displayed in the gauge area.

<script id='fruits' type="text/x-template">
   <div id='apple'>
       <img src='src/lineargauge/images/apple.png'>
   </div>
</script>
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='fruits' x={100} y={100}>
            </AnnotationDirective>
        </AnnotationsDirective>
    </LinearGaugeComponent>,document.getElementById('gauge'));

Annotation Customization

You can customize the annotation using following properties.

  • zIndex - When annotation overlaps with another element, you can use this property to bring annotation to the front or back.
  • horizontalAlignment - To move annotation horizontally. Possible values are “Center”, “Far”, “Near”, “None”
  • verticalAlignment - To move annotation vertically. Possible values are “Center”, “Far”, “Near”, “None”
  • x and y - To move annotation to the specified location.

Changing the z-order

You can change the z-order of the annotation element by using the zIndex property.

Source
Preview
index.tsx
index.jsx
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'));
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'));

Positioning the Annotation

You can place the annotation anywhere in gauge area by specifying pixel values to the x and y properties.

Source
Preview
index.tsx
index.jsx
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}>
            </AnnotationDirective>
        </AnnotationsDirective>
    </LinearGaugeComponent>,document.getElementById('gauge'));
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}>
            </AnnotationDirective>
        </AnnotationsDirective>
    </LinearGaugeComponent>, document.getElementById('gauge'));

Alignment of Annotation

You can align the annotation using horizontalAlignment and verticalAlignment properties.

Source
Preview
index.tsx
index.jsx
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'>
            </AnnotationDirective>
        </AnnotationsDirective>
    </LinearGaugeComponent>,document.getElementById('gauge'));
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'>
            </AnnotationDirective>
        </AnnotationsDirective>
    </LinearGaugeComponent>, document.getElementById('gauge'));

Multiple Annotations

You can add multiple annotations to the gauge as demonstrated below.

Source
Preview
index.tsx
index.jsx
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 style="color:red;">Speed</h1></div>' verticalAlignment='Near' horizontalAlignment='Center' x={100} y={150}>
            </AnnotationDirective>
            <AnnotationDirective content='<div id="first"><h1 style="color:blue;">Meter</h1></div>' verticalAlignment='Center' horizontalAlignment='Center' x={-100} y={-100}>
            </AnnotationDirective>
        </AnnotationsDirective>
    </LinearGaugeComponent>,document.getElementById('gauge'));
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 style="color:red;">Speed</h1></div>' verticalAlignment='Near' horizontalAlignment='Center' x={100} y={150}>
            </AnnotationDirective>
            <AnnotationDirective content='<div id="first"><h1 style="color:blue;">Meter</h1></div>' verticalAlignment='Center' horizontalAlignment='Center' x={-100} y={-100}>
            </AnnotationDirective>
        </AnnotationsDirective>
    </LinearGaugeComponent>, document.getElementById('gauge'));