Internationalization in React Circular Gauge component

6 Apr 202313 minutes to read

Circular Gauge provides internationalization support for below elements.

  • Axis Labels
  • Tooltip

For more information about number formatter, you can refer internationalization.

Globalization

Globalization is the process of designing and developing a component that works in different cultures/locales.
Internationalization library is used to globalize number in Circular Gauge component using format property in labelStyle.

Numeric Format

In the below example, axis labels are globalized to EUR.

import * as React from "react";
import * as ReactDOM from "react-dom";
import { CircularGaugeComponent, AxesDirective, AxisDirective } from '@syncfusion/ej2-react-circulargauge';
import { setCulture, setCurrencyCode } from '@syncfusion/ej2-base';
setCulture('de');
setCurrencyCode('EUR');
export function App() {
  return(
  <CircularGaugeComponent >
    <AxesDirective>
      <AxisDirective labelStyle = {{
            //Label format set as currency.
            format: 'c'
        }}>
      </AxisDirective>
    </AxesDirective>
  </CircularGaugeComponent>);
}
const root = ReactDOM.createRoot(document.getElementById('container'));
root.render(<App />);
import * as React from "react";
import * as ReactDOM from "react-dom";
import { CircularGaugeComponent, AxesDirective, AxisDirective } from '@syncfusion/ej2-react-circulargauge';
import { setCulture, setCurrencyCode } from '@syncfusion/ej2-base';
setCulture('de');
setCurrencyCode('EUR');
export function App() {
  return(
  <CircularGaugeComponent >
    <AxesDirective>
      <AxisDirective labelStyle = {{
            //Label format set as currency.
            format: 'c'
        }}>
      </AxisDirective>
    </AxesDirective>
  </CircularGaugeComponent>);
}
const root = ReactDOM.createRoot(document.getElementById('container'));
root.render(<App />);

Right-to-left

Circular Gauge can render its elements from right to left, which improves the user experience for certain language users. To do so, set the enableRtl property to true. When this property is enabled, elements such as the tooltip and legend will be rendered from right to left. Meanwhile, the axis can be rendered from right to left by setting the direction property to AntiClockWise. For more information on axis, click here.

The following example illustrates the right to left rendering of the Circular Gauge.

import * as React from "react";
import * as ReactDOM from "react-dom";
import { CircularGaugeComponent, AxesDirective, AxisDirective, PointersDirective, PointerDirective, RangesDirective, RangeDirective, GaugeTooltip, Legend, Inject  } from '@syncfusion/ej2-react-circulargauge';

export function App() {
  return(
    <CircularGaugeComponent
    enableRtl="true"
    tooltip={{
      type: ['Pointer', 'Range'],
      format: 'Pointer : {value} ',
      enable: true,
      enableAnimation: false,
    }}
    legendSettings={{
      visible: true,
    }}
  >
    <Inject services={[GaugeTooltip, Legend]} />
    <AxesDirective>
      <AxisDirective
        minimum={0}
        maximum={120}
        startAngle={210}
        endAngle={150}
        radius="80%"
        direction="AntiClockWise"
        majorTicks={{
          height: 10,
          offset: 5,
          color: '#9E9E9E',
        }}
        minorTicks={{
          height: 0,
        }}
        lineStyle={{ width: 10, color: 'transparent' }}
        labelStyle={{
          position: 'Inside',
          useRangeColor: false,
          font: {
            size: '12px',
            color: '#424242',
            fontFamily: 'Roboto',
            fontStyle: 'Regular',
          },
        }}
      >
        <RangesDirective>
          <RangeDirective start={0} end={40} color="#30B32D"></RangeDirective>
          <RangeDirective
            start={40}
            end={80}
            color="#FFDD00"
          ></RangeDirective>
          <RangeDirective
            start={80}
            end={120}
            color="#F03E3E"
          ></RangeDirective>
        </RangesDirective>
        <PointersDirective>
          <PointerDirective
            value={65}
            radius="60%"
            color="#757575"
            pointerWidth={8}
            animation={{
              enable: false,
            }}
            cap={{
              radius: 7,
              color: '#757575',
            }}
            needleTail={{
              length: '18%',
            }}
          ></PointerDirective>
        </PointersDirective>
      </AxisDirective>
    </AxesDirective>
  </CircularGaugeComponent>);
}
const root = ReactDOM.createRoot(document.getElementById('container'));
root.render(<App />);
import * as React from "react";
import * as ReactDOM from "react-dom";
import { CircularGaugeComponent, AxesDirective, AxisDirective, PointersDirective, PointerDirective, RangesDirective, RangeDirective, GaugeTooltip, Legend, Inject  } from '@syncfusion/ej2-react-circulargauge';

export function App() {
  return(
    <CircularGaugeComponent
    enableRtl="true"
    tooltip={{
      type: ['Pointer', 'Range'],
      format: 'Pointer : {value} ',
      enable: true,
      enableAnimation: false,
    }}
    legendSettings={{
      visible: true,
    }}
  >
    <Inject services={[GaugeTooltip, Legend]} />
    <AxesDirective>
      <AxisDirective
        minimum={0}
        maximum={120}
        startAngle={210}
        endAngle={150}
        radius="80%"
        direction="AntiClockWise"
        majorTicks={{
          height: 10,
          offset: 5,
          color: '#9E9E9E',
        }}
        minorTicks={{
          height: 0,
        }}
        lineStyle={{ width: 10, color: 'transparent' }}
        labelStyle={{
          position: 'Inside',
          useRangeColor: false,
          font: {
            size: '12px',
            color: '#424242',
            fontFamily: 'Roboto',
            fontStyle: 'Regular',
          },
        }}
      >
        <RangesDirective>
          <RangeDirective start={0} end={40} color="#30B32D"></RangeDirective>
          <RangeDirective
            start={40}
            end={80}
            color="#FFDD00"
          ></RangeDirective>
          <RangeDirective
            start={80}
            end={120}
            color="#F03E3E"
          ></RangeDirective>
        </RangesDirective>
        <PointersDirective>
          <PointerDirective
            value={65}
            radius="60%"
            color="#757575"
            pointerWidth={8}
            animation={{
              enable: false,
            }}
            cap={{
              radius: 7,
              color: '#757575',
            }}
            needleTail={{
              length: '18%',
            }}
          ></PointerDirective>
        </PointersDirective>
      </AxisDirective>
    </AxesDirective>
  </CircularGaugeComponent>);
}
const root = ReactDOM.createRoot(document.getElementById('container'));
root.render(<App />);