Contact Support
Animation in React Linear Gauge component
26 Dec 202311 minutes to read
All of the elements in the Linear Gauge, such as the axis lines, ticks, labels, ranges, pointers, and annotations, can be animated sequentially by using the animationDuration property. The animation for the Linear Gauge is enabled when the animationDuration
property is set to an appropriate value in milliseconds, providing a smooth rendering effect for the component. If the animationDuration
property is set to 0, which is the default value, the animation effect is disabled. If the animation is enabled, the component will behave in the following order.
- The axis line, ticks, labels, and ranges will all be animated at the same time.
- If available, pointers will be animated in the same way as pointer animation.
- If available, annotations will be animated.
The animation of the Linear Gauge is demonstrated in the following example.
import * as React from "react";
import * as ReactDOM from "react-dom";
import {
LinearGaugeComponent,
AxesDirective,
AxisDirective,
Inject,
PointersDirective,
PointerDirective,
AnnotationDirective,
Annotations,
AnnotationsDirective,
RangesDirective,
RangeDirective,
} from '@syncfusion/ej2-react-lineargauge';
export function App() {
return(
<LinearGaugeComponent
background="transparent"
id="gauge"
orientation="Horizontal"
width="650px" height="400px"
animationDuration={3000}
>
<Inject services={[Annotations]} />
<AxesDirective>
<AxisDirective
minorTicks={{ interval: 2, height: 10, color: '#9E9E9E' }}
majorTicks={{ interval: 10, height: 20, color: '#9E9E9E' }}
labelStyle={{ offset: 48, font: { fontFamily: 'inherit' } }}
>
<PointersDirective>
<PointerDirective
value={10}
placement="Near"
height={15}
width={15}
offset={-40}
markerType="Triangle"
></PointerDirective>
</PointersDirective>
<RangesDirective>
<RangeDirective
start={0}
end={50}
startWidth={10}
endWidth={10}
color="#F45656"
offset="35"
></RangeDirective>
</RangesDirective>
</AxisDirective>
</AxesDirective>
<AnnotationsDirective>
<AnnotationDirective
content='<div style="width: 70px;margin-top: 25%;font-size: 16px;">10 MPH</div>'
axisIndex={0}
axisValue={10}
x={10}
zIndex="1"
y={-70}
/>
</AnnotationsDirective>
</LinearGaugeComponent>);
}
const root = ReactDOM.createRoot(document.getElementById('container'));
root.render(<App />);
import * as React from "react";
import * as ReactDOM from "react-dom";
import {
LinearGaugeComponent,
AxesDirective,
AxisDirective,
Inject,
PointersDirective,
PointerDirective,
AnnotationDirective,
Annotations,
AnnotationsDirective,
RangesDirective,
RangeDirective,
} from '@syncfusion/ej2-react-lineargauge';
export function App() {
return(
<LinearGaugeComponent
background="transparent"
id="gauge"
orientation="Horizontal"
width="650px" height="400px"
animationDuration={3000}
>
<Inject services={[Annotations]} />
<AxesDirective>
<AxisDirective
minorTicks={{ interval: 2, height: 10, color: '#9E9E9E' }}
majorTicks={{ interval: 10, height: 20, color: '#9E9E9E' }}
labelStyle={{ offset: 48, font: { fontFamily: 'inherit' } }}
>
<PointersDirective>
<PointerDirective
value={10}
placement="Near"
height={15}
width={15}
offset={-40}
markerType="Triangle"
></PointerDirective>
</PointersDirective>
<RangesDirective>
<RangeDirective
start={0}
end={50}
startWidth={10}
endWidth={10}
color="#F45656"
offset="35"
></RangeDirective>
</RangesDirective>
</AxisDirective>
</AxesDirective>
<AnnotationsDirective>
<AnnotationDirective
content='<div style="width: 70px;margin-top: 25%;font-size: 16px;">10 MPH</div>'
axisIndex={0}
axisValue={10}
x={10}
zIndex="1"
y={-70}
/>
</AnnotationsDirective>
</LinearGaugeComponent>);
}
const root = ReactDOM.createRoot(document.getElementById('container'));
root.render(<App />);
Only the pointer of the Linear Gauge can be animated individually, not the axis lines, ticks, labels, ranges, and annotations. You can refer this link to enable only pointer animation.