Axes is a collection of linear axis which can be used to indicate the numeric values. Line, ticks, labels, ranges and pointers are the sub elements of an axis.
The line
property of an axis provides options to customize the height
, width
, color
and offset
of the axis line.
import * as React from "react";
import * as ReactDOM from "react-dom";
import { LinearGaugeComponent, AxesDirective, AxisDirective } from '@syncfusion/ej2-react-lineargauge';
ReactDOM.render(
<LinearGaugeComponent id='gauge'>
<AxesDirective>
<AxisDirective line={ { height:150, width:2, color:'#4286f4', offset:2 } }>
</AxisDirective>
</AxesDirective>
</LinearGaugeComponent>,document.getElementById('gauge'));
import * as React from "react";
import * as ReactDOM from "react-dom";
import { LinearGaugeComponent, AxesDirective, AxisDirective } from '@syncfusion/ej2-react-lineargauge';
ReactDOM.render(<LinearGaugeComponent id='gauge'>
<AxesDirective>
<AxisDirective line={{ height: 150, width: 2, color: '#4286f4', offset: 2 }}>
</AxisDirective>
</AxesDirective>
</LinearGaugeComponent>, document.getElementById('gauge'));
You can customize the height
, color
and width
of major and minor ticks, by using majorTicks
and minorTicks
property. By default, interval for major ticks will be calculated automatically and also you can customize the interval for major and minor ticks using interval property.
import * as React from "react";
import * as ReactDOM from "react-dom";
import { LinearGaugeComponent, AxesDirective, AxisDirective } from '@syncfusion/ej2-react-lineargauge';
ReactDOM.render(
<LinearGaugeComponent id='gauge'>
<AxesDirective>
<AxisDirective minimum={20} maximum={140} majorTicks={ { interval:20 } } minorTicks={ { interval:5, color:'red' } } >
</AxisDirective>
</AxesDirective>
</LinearGaugeComponent>,document.getElementById('gauge'));
import * as React from "react";
import * as ReactDOM from "react-dom";
import { LinearGaugeComponent, AxesDirective, AxisDirective } from '@syncfusion/ej2-react-lineargauge';
ReactDOM.render(<LinearGaugeComponent id='gauge'>
<AxesDirective>
<AxisDirective minimum={20} maximum={140} majorTicks={{ interval: 20 }} minorTicks={{ interval: 5, color: 'red' }}>
</AxisDirective>
</AxesDirective>
</LinearGaugeComponent>, document.getElementById('gauge'));
The labelStyle
property of an axis provides options to
customize the offset
, format
, color
and font
of the axis labels.
import * as React from "react";
import * as ReactDOM from "react-dom";
import { LinearGaugeComponent, AxesDirective, AxisDirective } from '@syncfusion/ej2-react-lineargauge';
ReactDOM.render(
<LinearGaugeComponent id='gauge'>
<AxesDirective>
<AxisDirective labelStyle={ { font:{color:'red' } } }>
</AxisDirective>
</AxesDirective>
</LinearGaugeComponent>,document.getElementById('gauge'));
import * as React from "react";
import * as ReactDOM from "react-dom";
import { LinearGaugeComponent, AxesDirective, AxisDirective } from '@syncfusion/ej2-react-lineargauge';
ReactDOM.render(<LinearGaugeComponent id='gauge'>
<AxesDirective>
<AxisDirective labelStyle={{ font: { color: 'red' } }}>
</AxisDirective>
</AxesDirective>
</LinearGaugeComponent>, document.getElementById('gauge'));
Customize the display of the last label
If the last label is not in the visible range, it will be hidden by default. If you want to show the last label, set the showLastLabel
property to true in the axes property of linear gauge.
import * as React from "react";
import * as ReactDOM from "react-dom";
import { LinearGaugeComponent, AxesDirective, AxisDirective } from '@syncfusion/ej2-react-lineargauge';
ReactDOM.render(
<LinearGaugeComponent id='gauge'>
<AxesDirective>
<AxisDirective showLastLabel='true' labelStyle={ { font:{color:'red' } } } line={{ color: '#9E9E9E' }} >
<PointersDirective>
<PointerDirective value={20} height={15} width={15} offset={30} color='#757575'>
</PointerDirective>
</PointersDirective>
</AxisDirective>
</AxesDirective>
</LinearGaugeComponent>,document.getElementById('gauge'));
import * as React from "react";
import * as ReactDOM from "react-dom";
import { LinearGaugeComponent, AxesDirective, AxisDirective } from '@syncfusion/ej2-react-lineargauge';
ReactDOM.render(<LinearGaugeComponent id='gauge'>
<AxesDirective>
<AxisDirective showLastLabel='true' labelStyle={{ font: { color: 'red' } }} line={{ color: '#9E9E9E' }}>
<PointersDirective>
<PointerDirective value={20} height={15} width={15} offset={30} color='#757575'>
</PointerDirective>
</PointersDirective>
</AxisDirective>
</AxesDirective>
</LinearGaugeComponent>, document.getElementById('gauge'));
Label Format
Axis labels can be formatted by using the format
property in labelStyle
and it supports all the globalized formats.
import * as React from "react";
import * as ReactDOM from "react-dom";
import { LinearGaugeComponent, AxesDirective, AxisDirective } from '@syncfusion/ej2-react-lineargauge';
ReactDOM.render(
<LinearGaugeComponent id='gauge'>
<AxesDirective>
<AxisDirective labelStyle={ { format:'c' } }>
</AxisDirective>
</AxesDirective>
</LinearGaugeComponent>,document.getElementById('gauge'));
import * as React from "react";
import * as ReactDOM from "react-dom";
import { LinearGaugeComponent, AxesDirective, AxisDirective } from '@syncfusion/ej2-react-lineargauge';
ReactDOM.render(<LinearGaugeComponent id='gauge'>
<AxesDirective>
<AxisDirective labelStyle={{ format: 'c' }}>
</AxisDirective>
</AxesDirective>
</LinearGaugeComponent>, document.getElementById('gauge'));
The following table describes the result of applying some commonly used label formats on numeric values.
Label Value | Label Format property value | Result | Description |
1000 | n1 | 1000.0 | The Number is rounded to 1 decimal place |
1000 | n2 | 1000.00 | The Number is rounded to 2 decimal place |
1000 | n3 | 1000.000 | The Number is rounded to 3 decimal place |
0.01 | p1 | 1.0% | The Number is converted to percentage with 1 decimal place |
0.01 | p2 | 1.00% | The Number is converted to percentage with 2 decimal place |
0.01 | p3 | 1.000% | The Number is converted to percentage with 3 decimal place |
1000 | c1 | $1,000.0 | The Currency symbol is appended to number and number is rounded to 1 decimal place |
1000 | c2 | $1,000.00 | The Currency symbol is appended to number and number is rounded to 2 decimal place |
Custom Label Format
Axis also supports custom label format using placeholder like {value}°C, in which the value represents the axis label e.g. 20°C.
import * as React from "react";
import * as ReactDOM from "react-dom";
import { LinearGaugeComponent, AxesDirective, AxisDirective } from '@syncfusion/ej2-react-lineargauge';
ReactDOM.render(
<LinearGaugeComponent id='gauge'>
<AxesDirective>
<AxisDirective labelStyle={ { format:'{value}°C' } }>
</AxisDirective>
</AxesDirective>
</LinearGaugeComponent>,document.getElementById('gauge'));
import * as React from "react";
import * as ReactDOM from "react-dom";
import { LinearGaugeComponent, AxesDirective, AxisDirective } from '@syncfusion/ej2-react-lineargauge';
ReactDOM.render(<LinearGaugeComponent id='gauge'>
<AxesDirective>
<AxisDirective labelStyle={{ format: '{value}°C' }}>
</AxisDirective>
</AxesDirective>
</LinearGaugeComponent>, document.getElementById('gauge'));
isInversed
property is used to choose the rendering of axis either bottom to top or top to bottom direction.
import * as React from "react";
import * as ReactDOM from "react-dom";
import { LinearGaugeComponent, AxesDirective, AxisDirective } from '@syncfusion/ej2-react-lineargauge';
ReactDOM.render(
<LinearGaugeComponent id='gauge'>
<AxesDirective>
<AxisDirective isInversed={true}>
</AxisDirective>
</AxesDirective>
</LinearGaugeComponent>,document.getElementById('gauge'));
import * as React from "react";
import * as ReactDOM from "react-dom";
import { LinearGaugeComponent, AxesDirective, AxisDirective } from '@syncfusion/ej2-react-lineargauge';
ReactDOM.render(<LinearGaugeComponent id='gauge'>
<AxesDirective>
<AxisDirective isInversed={true}>
</AxisDirective>
</AxesDirective>
</LinearGaugeComponent>, document.getElementById('gauge'));
To place an axis opposite from its original position, set opposedPosition
property as true in the axis.
import * as React from "react";
import * as ReactDOM from "react-dom";
import { LinearGaugeComponent, AxesDirective, AxisDirective } from '@syncfusion/ej2-react-lineargauge';
ReactDOM.render(
<LinearGaugeComponent id='gauge'>
<AxesDirective>
<AxisDirective opposedPosition={true}>
</AxisDirective>
</AxesDirective>
</LinearGaugeComponent>,document.getElementById('gauge'));
import * as React from "react";
import * as ReactDOM from "react-dom";
import { LinearGaugeComponent, AxesDirective, AxisDirective } from '@syncfusion/ej2-react-lineargauge';
ReactDOM.render(<LinearGaugeComponent id='gauge'>
<AxesDirective>
<AxisDirective opposedPosition={true}>
</AxisDirective>
</AxesDirective>
</LinearGaugeComponent>, document.getElementById('gauge'));
You can render any number of axis for a linear gauge by using array of axis objects. Each axis will have its own ranges, pointers, annotations and customization options.
import * as React from "react";
import * as ReactDOM from "react-dom";
import { LinearGaugeComponent, AxesDirective, AxisDirective } from '@syncfusion/ej2-react-lineargauge';
ReactDOM.render(
<LinearGaugeComponent id='gauge'>
<AxesDirective>
<AxisDirective labelStyle={ { format:'{value}°C' } }>
</AxisDirective>
<AxisDirective opposedPosition={true} labelStyle={ { format:'{value}°F' } }>
</AxisDirective>
</AxesDirective>
</LinearGaugeComponent>,document.getElementById('gauge'));
import * as React from "react";
import * as ReactDOM from "react-dom";
import { LinearGaugeComponent, AxesDirective, AxisDirective } from '@syncfusion/ej2-react-lineargauge';
ReactDOM.render(<LinearGaugeComponent id='gauge'>
<AxesDirective>
<AxisDirective labelStyle={{ format: '{value}°C' }}>
</AxisDirective>
<AxisDirective opposedPosition={true} labelStyle={{ format: '{value}°F' }}>
</AxisDirective>
</AxesDirective>
</LinearGaugeComponent>, document.getElementById('gauge'));