Search results

Labels in React Range Navigator component

26 Oct 2021 / 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.tsx
index.jsx
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';

class App extends React.Component<{}, {}> {

  public data: object[] = [];
  public 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 };
      this.data.push(point);
    }
  }

  render() {
    this.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={this.data} xName='x' yName='y'>
      <Inject services={[DateTime]} />
    </RangeNavigatorComponent>
  }

};
ReactDOM.render(<App />, document.getElementById("charts"));
Copied to clipboard
import { DateTime, Inject, RangeNavigatorComponent } from '@syncfusion/ej2-react-charts';
import * as React from "react";
import * as ReactDOM from "react-dom";
class App extends React.Component {
    constructor() {
        super(...arguments);
        this.data = [];
    }
    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 };
            this.data.push(point);
        }
    }
    render() {
        this.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={this.data} xName='x' yName='y'>
      <Inject services={[DateTime]}/>
    </RangeNavigatorComponent>;
    }
}
;
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.tsx
index.jsx
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';

class App extends React.Component<{}, {}> {

  public data: object[] = [];
  public 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 };
  this.data.push(point);
}
  }

  render() {
this.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={this.data} xName='x' yName='y'>
  <Inject services={[DateTime]} />
</RangeNavigatorComponent>
  }

};
ReactDOM.render(<App />, document.getElementById("charts"));
Copied to clipboard
import { DateTime, Inject, RangeNavigatorComponent } from '@syncfusion/ej2-react-charts';
import * as React from "react";
import * as ReactDOM from "react-dom";
class App extends React.Component {
    constructor() {
        super(...arguments);
        this.data = [];
    }
    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 };
            this.data.push(point);
        }
    }
    render() {
        this.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={this.data} xName='x' yName='y'>
  <Inject services={[DateTime]}/>
</RangeNavigatorComponent>;
    }
}
;
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.tsx
index.jsx
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';

class App extends React.Component<{}, {}> {

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

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

};
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 { bitCoinData } from 'default_data.ts';
class App extends React.Component {
    constructor() {
        super(...arguments);
        this.data = bitCoinData;
        this.tooltip = { enable: true };
    }
    render() {
        return <RangeNavigatorComponent id='charts' valueType='DateTime' labelFormat='y/M/d' value={[new Date('2017-09-01'), new Date('2018-02-01')]} tooltip={this.tooltip} labelIntersectAction='Hide'>
  <Inject services={[AreaSeries, DateTime, RangeTooltip]}/>
  <RangenavigatorSeriesCollectionDirective>
    <RangenavigatorSeriesDirective dataSource={this.data} xName='x' yName='y' type='Area' width={2}/>
  </RangenavigatorSeriesCollectionDirective>
</RangeNavigatorComponent>;
    }
}
;
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.tsx
index.jsx
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';

class App extends React.Component<{}, {}> {

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

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

};
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 { bitCoinData } from 'default_data.ts';
class App extends React.Component {
    constructor() {
        super(...arguments);
        this.data = bitCoinData;
        this.tooltip = { enable: true };
    }
    render() {
        return <RangeNavigatorComponent id='charts' valueType='DateTime' labelPosition='Inside' value={[new Date('2017-09-01'), new Date('2018-02-01')]} tooltip={this.tooltip}>
  <Inject services={[AreaSeries, DateTime, RangeTooltip]}/>
  <RangenavigatorSeriesCollectionDirective>
    <RangenavigatorSeriesDirective dataSource={this.data} xName='x' yName='y' type='Area' width={2}/>
  </RangenavigatorSeriesCollectionDirective>
</RangeNavigatorComponent>;
    }
}
;
ReactDOM.render(<App />, document.getElementById("charts"));

Labels customization

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

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

class App extends React.Component<{}, {}> {

  public data: object[] = [];
  public max: number = 100;
  public 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 };
  this.data.push(point);
}
  }

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

};
ReactDOM.render(<App />, document.getElementById("charts"));
Copied to clipboard
import { DateTime, Inject, RangeNavigatorComponent } from '@syncfusion/ej2-react-charts';
import * as React from "react";
import * as ReactDOM from "react-dom";
class App extends React.Component {
    constructor() {
        super(...arguments);
        this.data = [];
        this.max = 100;
    }
    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 };
            this.data.push(point);
        }
    }
    render() {
        this.chartLoad();
        return <RangeNavigatorComponent id='charts' valueType='DateTime' intervalType='Months' labelFormat='MMM' value={[new Date('2001-01-01'), new Date('2002-01-01')]} dataSource={this.data} xName='x' yName='y'>
  <Inject services={[DateTime]}/>
</RangeNavigatorComponent>;
    }
}
;
ReactDOM.render(<App />, document.getElementById("charts"));