Search results

Labels in React Range Navigator component

31 Jan 2023 / 4 minutes to read

Multilevel labels

The multi-level labels for the Range Selector can be enabled by setting the enableGrouping property to true. This is restricted to the DateTime axis alone.

Source
Preview
index.jsx
index.tsx
Copied to clipboard
import { DateTime, Inject, RangeNavigatorComponent } from '@syncfusion/ej2-react-charts';
import * as React from "react";
import * as ReactDOM from "react-dom";
function App() {
    const data = [];
    function chartLoad() {
        let value = 0;
        let point = {};
        for (let j = 1; j < 1090; j++) {
            value += (Math.random() * 10 - 5);
            value = value < 0 ? Math.abs(value) : value;
            point = { x: new Date(2000, 0, j), y: value, z: value + 10 };
            data.push(point);
        }
    }
    chartLoad();
    return <RangeNavigatorComponent id='charts' valueType='DateTime' intervalType='Months' intervalType='Quarter' enableGrouping={true} value={[new Date('2001-01-01'), new Date('2002-01-01')]} dataSource={data} xName='x' yName='y'>
      <Inject services={[DateTime]}/>
    </RangeNavigatorComponent>;
}
;
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));
Copied to clipboard
import {
     AreaSeries, DateTime, Inject, RangeNavigatorComponent, RangenavigatorSeriesCollectionDirective,
     RangenavigatorSeriesDirective,RangeTooltip
} from '@syncfusion/ej2-react-charts';
import * as React from "react";
import * as ReactDOM from "react-dom";
import { GetDateTimeData } from 'default_data.ts';

function App() {

  const data: object[] = [];
  function chartLoad(): void {
    let value: number = 0; let point: object = {};
    for (let j: number = 1; j < 1090; j++) {
      value += (Math.random() * 10 - 5);
      value = value < 0 ? Math.abs(value) : value;
      point = { x: new Date(2000, 0, j), y: value, z: value + 10 };
      data.push(point);
    }
  }

  chartLoad();
  return <RangeNavigatorComponent id='charts'
      valueType='DateTime' intervalType='Months'
      intervalType='Quarter' enableGrouping={true}
      value={[new Date('2001-01-01'), new Date('2002-01-01')]}
      dataSource={data} xName='x' yName='y'>
      <Inject services={[DateTime]} />
    </RangeNavigatorComponent>

};
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));

Grouping

The multi-level labels can be grouped using the groupBy property with the following interval types:

  • Auto
  • Years
  • Quarter
  • Months
  • Weeks
  • Days
  • Hours
  • Minutes
  • Seconds
Source
Preview
index.jsx
index.tsx
Copied to clipboard
import { DateTime, Inject, RangeNavigatorComponent } from '@syncfusion/ej2-react-charts';
import * as React from "react";
import * as ReactDOM from "react-dom";
function App() {
    const data = [];
    function chartLoad() {
        let value = 0;
        let point = {};
        for (let j = 1; j < 1090; j++) {
            value += (Math.random() * 10 - 5);
            value = value < 0 ? Math.abs(value) : value;
            point = { x: new Date(2000, 0, j), y: value, z: value + 10 };
            data.push(point);
        }
    }
    chartLoad();
    return <RangeNavigatorComponent id='charts' valueType='DateTime' intervalType='Months' intervalType='Quarter' enableGrouping={true} groupBy='Years' value={[new Date('2001-01-01'), new Date('2002-01-01')]} dataSource={data} xName='x' yName='y'>
  <Inject services={[DateTime]}/>
</RangeNavigatorComponent>;
}
;
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));
Copied to clipboard
import {
 AreaSeries, DateTime, Inject, RangeNavigatorComponent, RangenavigatorSeriesCollectionDirective,
 RangenavigatorSeriesDirective,RangeTooltip
} from '@syncfusion/ej2-react-charts';
import * as React from "react";
import * as ReactDOM from "react-dom";
import { GetDateTimeData } from 'default_data.ts';

function App() {

  const data: object[] = [];
  function chartLoad(): void {
let value: number = 0; let point: object = {};
for (let j: number = 1; j < 1090; j++) {
  value += (Math.random() * 10 - 5);
  value = value < 0 ? Math.abs(value) : value;
  point = { x: new Date(2000, 0, j), y: value, z: value + 10 };
  data.push(point);
}
  }

  chartLoad();
  return <RangeNavigatorComponent id='charts'
  valueType='DateTime' intervalType='Months'
  intervalType='Quarter'
  enableGrouping={true}
  groupBy='Years'
  value={[new Date('2001-01-01'), new Date('2002-01-01')]}
  dataSource={data} xName='x' yName='y'>
  <Inject services={[DateTime]} />
</RangeNavigatorComponent>

};
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));

Smart labels

The labelIntersectAction property is used to avoid overlapping of labels. The following code sample shows the setting of labelIntersectAction property to Hide.

Source
Preview
index.jsx
index.tsx
Copied to clipboard
import { AreaSeries, DateTime, Inject, RangeNavigatorComponent, RangenavigatorSeriesCollectionDirective, RangenavigatorSeriesDirective, RangeTooltip } from '@syncfusion/ej2-react-charts';
import * as React from "react";
import * as ReactDOM from "react-dom";
import { bitCoinData } from 'default_data.ts';
function App() {
    const data = bitCoinData;
    const tooltip = { enable: true };
    return <RangeNavigatorComponent id='charts' valueType='DateTime' labelFormat='y/M/d' value={[new Date('2017-09-01'), new Date('2018-02-01')]} tooltip={tooltip} labelIntersectAction='Hide'>
  <Inject services={[AreaSeries, DateTime, RangeTooltip]}/>
  <RangenavigatorSeriesCollectionDirective>
    <RangenavigatorSeriesDirective dataSource={data} xName='x' yName='y' type='Area' width={2}/>
  </RangenavigatorSeriesCollectionDirective>
</RangeNavigatorComponent>;
}
;
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));
Copied to clipboard
import {
 AreaSeries, DateTime, Inject, RangeNavigatorComponent, RangenavigatorSeriesCollectionDirective,
 RangenavigatorSeriesDirective,RangeTooltip,RangeTooltipSettingsModel
} from '@syncfusion/ej2-react-charts';
import * as React from "react";
import * as ReactDOM from "react-dom";
import { bitCoinData } from 'default_data.ts';

function App() {

  const data: object[] = bitCoinData;
  const tooltip: RangeTooltipSettingsModel = { enable: true };

  return <RangeNavigatorComponent id='charts'
  valueType='DateTime' labelFormat='y/M/d' value={[new Date('2017-09-01'), new Date('2018-02-01')]}
  tooltip={tooltip} labelIntersectAction='Hide'>
  <Inject services={[AreaSeries, DateTime, RangeTooltip]} />
  <RangenavigatorSeriesCollectionDirective>
    <RangenavigatorSeriesDirective dataSource={data} xName='x' yName='y' type='Area' width={2} />
  </RangenavigatorSeriesCollectionDirective>
</RangeNavigatorComponent>

};
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));

Label positioning

By default, the labels can be placed outside the Range Selector. It can also be placed inside the Range Selector using the labelPosition property.

Source
Preview
index.jsx
index.tsx
Copied to clipboard
import { AreaSeries, DateTime, Inject, RangeNavigatorComponent, RangenavigatorSeriesCollectionDirective, RangenavigatorSeriesDirective, RangeTooltip } from '@syncfusion/ej2-react-charts';
import * as React from "react";
import * as ReactDOM from "react-dom";
import { bitCoinData } from 'default_data.ts';
function App() {
    const data = bitCoinData;
    const tooltip = { enable: true };
    return <RangeNavigatorComponent id='charts' valueType='DateTime' labelPosition='Inside' value={[new Date('2017-09-01'), new Date('2018-02-01')]} tooltip={tooltip}>
  <Inject services={[AreaSeries, DateTime, RangeTooltip]}/>
  <RangenavigatorSeriesCollectionDirective>
    <RangenavigatorSeriesDirective dataSource={data} xName='x' yName='y' type='Area' width={2}/>
  </RangenavigatorSeriesCollectionDirective>
</RangeNavigatorComponent>;
}
;
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));
Copied to clipboard
import {
 AreaSeries, DateTime, Inject, RangeNavigatorComponent, RangenavigatorSeriesCollectionDirective,
 RangenavigatorSeriesDirective,RangeTooltip,RangeTooltipSettingsModel
} from '@syncfusion/ej2-react-charts';
import * as React from "react";
import * as ReactDOM from "react-dom";
import { bitCoinData } from 'default_data.ts';

function App() {

  const data: object[] = bitCoinData;
  const tooltip: RangeTooltipSettingsModel = { enable: true };

  return <RangeNavigatorComponent id='charts'
  valueType='DateTime' labelPosition='Inside' value={[new Date('2017-09-01'), new Date('2018-02-01')]}
  tooltip={tooltip}>
  <Inject services={[AreaSeries, DateTime, RangeTooltip]} />
  <RangenavigatorSeriesCollectionDirective>
    <RangenavigatorSeriesDirective dataSource={data} xName='x' yName='y' type='Area' width={2} />
  </RangenavigatorSeriesCollectionDirective>
</RangeNavigatorComponent>

};
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));

Labels customization

The font size, color, family, etc. can be customized using the labelStyle setting.

Source
Preview
index.jsx
index.tsx
Copied to clipboard
import { DateTime, Inject, RangeNavigatorComponent } from '@syncfusion/ej2-react-charts';
import * as React from "react";
import * as ReactDOM from "react-dom";
function App() {
    const data = [];
    const max = 100;
    function chartLoad() {
        let value = 0;
        let point = {};
        for (let j = 1; j < 1090; j++) {
            value += (Math.random() * 10 - 5);
            value = value < 0 ? Math.abs(value) : value;
            point = { x: new Date(2000, 0, j), y: value, z: value + 10 };
            data.push(point);
        }
    }
    chartLoad();
    return <RangeNavigatorComponent id='charts' valueType='DateTime' intervalType='Months' labelFormat='MMM' value={[new Date('2001-01-01'), new Date('2002-01-01')]} dataSource={data} xName='x' yName='y'>
  <Inject services={[DateTime]}/>
</RangeNavigatorComponent>;
}
;
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));
Copied to clipboard
import {
 AreaSeries, DateTime, Inject, RangeNavigatorComponent, RangenavigatorSeriesCollectionDirective,
 RangenavigatorSeriesDirective,RangeTooltip
} from '@syncfusion/ej2-react-charts';
import * as React from "react";
import * as ReactDOM from "react-dom";
import { GetDateTimeData } from 'default_data.ts';

function App() {

  const data: object[] = [];
  const max: number = 100;
  function chartLoad(): void {
let value: number = 0; let point: object = {};
for (let j: number = 1; j < 1090; j++) {
  value += (Math.random() * 10 - 5);
  value = value < 0 ? Math.abs(value) : value;
  point = { x: new Date(2000, 0, j), y: value, z: value + 10 };
  data.push(point);
}
  }

  chartLoad();
  return <RangeNavigatorComponent id='charts'
  valueType='DateTime' intervalType='Months' labelFormat='MMM'
  value={[new Date('2001-01-01'), new Date('2002-01-01')]}
  dataSource={data} xName='x' yName='y'>
  <Inject services={[DateTime]} />
</RangeNavigatorComponent>

};
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));