Period selector in React Range navigator component
20 Jan 202319 minutes to read
The period selector allows to select a range with specified periods.
Periods
An array of objects that allows the users to specify pre-defined time intervals. The interval
property specifies the count value of the button, and the text
property specifies the text to be displayed on the button. The intervaltype
property allows the users to customize the interval type, and it supports the following types:
- Auto
- Years
- Quarter
- Months
- Weeks
- Days
- Hours
- Minutes
- Seconds
import { AreaSeries, DateTime, Inject, RangeNavigatorComponent, RangenavigatorSeriesCollectionDirective, RangenavigatorSeriesDirective, RangeTooltip, PeriodSelector } 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 };
const periodselector = {
position: 'Top',
periods: [
{ text: '1M', interval: 1, intervalType: 'Months' },
{ text: '3M', interval: 3, intervalType: 'Months' },
{ text: '6M', interval: 6, intervalType: 'Months' }, { text: 'YTD' },
{ text: '1Y', interval: 1, intervalType: 'Years' },
{ text: '2Y', interval: 2, intervalType: 'Years', selected: true }, { text: 'All' }
]
};
return <RangeNavigatorComponent id='charts' valueType='DateTime' labelFormat='MMM-yy' value={[new Date('2017-09-01'), new Date('2018-02-01')]} tooltip={tooltip} periodSelectorSettings={periodselector}>
<Inject services={[AreaSeries, DateTime, RangeTooltip, PeriodSelector]} />
<RangenavigatorSeriesCollectionDirective>
<RangenavigatorSeriesDirective dataSource={data} xName='x' yName='y' type='Area' width={2} />
</RangenavigatorSeriesCollectionDirective>
</RangeNavigatorComponent>;
};
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));
import {
AreaSeries, DateTime, Inject, RangeNavigatorComponent, RangenavigatorSeriesCollectionDirective,
RangenavigatorSeriesDirective, RangeTooltip, PeriodSelector, RangeTooltipSettingsModel, PeriodSelectorSettingsModel
} 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 };
const periodselector: PeriodSelectorSettingsModel = {
position: 'Top',
periods: [
{ text: '1M', interval: 1, intervalType: 'Months' },
{ text: '3M', interval: 3, intervalType: 'Months' },
{ text: '6M', interval: 6, intervalType: 'Months' }, { text: 'YTD' },
{ text: '1Y', interval: 1, intervalType: 'Years' },
{ text: '2Y', interval: 2, intervalType: 'Years', selected: true }, { text: 'All' }
]
};
return <RangeNavigatorComponent id='charts'
valueType='DateTime' labelFormat='MMM-yy' value={[new Date('2017-09-01'), new Date('2018-02-01')]}
tooltip={tooltip}
periodSelectorSettings={periodselector}>
<Inject services={[AreaSeries, DateTime, RangeTooltip, PeriodSelector]} />
<RangenavigatorSeriesCollectionDirective>
<RangenavigatorSeriesDirective dataSource={data} xName='x' yName='y' type='Area' width={2} />
</RangenavigatorSeriesCollectionDirective>
</RangeNavigatorComponent>
};
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));
To use the period selector feature, inject the
PeriodSelector
module using theRangeNavigator.Inject(PeriodSelector)
method.
Positioning period selector
The position
property allows the users to position the period selector at the Top or Bottom.
import { AreaSeries, DateTime, Inject, RangeNavigatorComponent, RangenavigatorSeriesCollectionDirective, RangenavigatorSeriesDirective, RangeTooltip, PeriodSelector } 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 };
const periodselector = {
position: 'Bottom',
periods: [
{ text: '1M', interval: 1, intervalType: 'Months' },
{ text: '3M', interval: 3, intervalType: 'Months' },
{ text: '6M', interval: 6, intervalType: 'Months' }, { text: 'YTD' },
{ text: '1Y', interval: 1, intervalType: 'Years' },
{ text: '2Y', interval: 2, intervalType: 'Years', selected: true }, { text: 'All' }
]
};
return <RangeNavigatorComponent id='charts' valueType='DateTime' labelFormat='MMM-yy' value={[new Date('2017-09-01'), new Date('2018-02-01')]} tooltip={tooltip} periodSelectorSettings={periodselector}>
<Inject services={[AreaSeries, DateTime, RangeTooltip, PeriodSelector]} />
<RangenavigatorSeriesCollectionDirective>
<RangenavigatorSeriesDirective dataSource={data} xName='x' yName='y' type='Area' width={2} />
</RangenavigatorSeriesCollectionDirective>
</RangeNavigatorComponent>;
};
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));
import {
AreaSeries, DateTime, Inject, RangeNavigatorComponent, RangenavigatorSeriesCollectionDirective,
RangenavigatorSeriesDirective, RangeTooltip, PeriodSelector, RangeTooltipSettingsModel, PeriodSelectorSettingsModel
} 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 };
const periodselector: PeriodSelectorSettingsModel = {
position: 'Bottom',
periods: [
{ text: '1M', interval: 1, intervalType: 'Months' },
{ text: '3M', interval: 3, intervalType: 'Months' },
{ text: '6M', interval: 6, intervalType: 'Months' }, { text: 'YTD' },
{ text: '1Y', interval: 1, intervalType: 'Years' },
{ text: '2Y', interval: 2, intervalType: 'Years', selected: true }, { text: 'All' }
]
};
return <RangeNavigatorComponent id='charts'
valueType='DateTime' labelFormat='MMM-yy' value={[new Date('2017-09-01'), new Date('2018-02-01')]}
tooltip={tooltip}
periodSelectorSettings={periodselector}>
<Inject services={[AreaSeries, DateTime, RangeTooltip, PeriodSelector]} />
<RangenavigatorSeriesCollectionDirective>
<RangenavigatorSeriesDirective dataSource={data} xName='x' yName='y' type='Area' width={2} />
</RangenavigatorSeriesCollectionDirective>
</RangeNavigatorComponent>
};
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));
Height
The height
property allows the users to specify the height of the period selector. The default value of the height property is 43px.
import { AreaSeries, DateTime, Inject, RangeNavigatorComponent, RangenavigatorSeriesCollectionDirective, RangenavigatorSeriesDirective, RangeTooltip, PeriodSelector } 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 };
const periodselector = {
position: 'Top',
height: 65,
periods: [
{ text: '1M', interval: 1, intervalType: 'Months' },
{ text: '3M', interval: 3, intervalType: 'Months' },
{ text: '6M', interval: 6, intervalType: 'Months' }, { text: 'YTD' },
{ text: '1Y', interval: 1, intervalType: 'Years' },
{ text: '2Y', interval: 2, intervalType: 'Years', selected: true }, { text: 'All' }
]
};
return <RangeNavigatorComponent id='charts' valueType='DateTime' labelFormat='MMM-yy' value={[new Date('2017-09-01'), new Date('2018-02-01')]} tooltip={tooltip} periodSelectorSettings={periodselector}>
<Inject services={[AreaSeries, DateTime, RangeTooltip, PeriodSelector]} />
<RangenavigatorSeriesCollectionDirective>
<RangenavigatorSeriesDirective dataSource={data} xName='x' yName='y' type='Area' width={2} />
</RangenavigatorSeriesCollectionDirective>
</RangeNavigatorComponent>;
};
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));
import {
AreaSeries, DateTime, Inject, RangeNavigatorComponent, RangenavigatorSeriesCollectionDirective,
RangenavigatorSeriesDirective, RangeTooltip, PeriodSelector, RangeTooltipSettingsModel, PeriodSelectorSettingsModel
} 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 };
const periodselector: PeriodSelectorSettingsModel = {
position: 'Top',
height: 65,
periods: [
{ text: '1M', interval: 1, intervalType: 'Months' },
{ text: '3M', interval: 3, intervalType: 'Months' },
{ text: '6M', interval: 6, intervalType: 'Months' }, { text: 'YTD' },
{ text: '1Y', interval: 1, intervalType: 'Years' },
{ text: '2Y', interval: 2, intervalType: 'Years', selected: true }, { text: 'All' }
]
};
return <RangeNavigatorComponent id='charts'
valueType='DateTime' labelFormat='MMM-yy' value={[new Date('2017-09-01'), new Date('2018-02-01')]}
tooltip={tooltip}
periodSelectorSettings={periodselector}>
<Inject services={[AreaSeries, DateTime, RangeTooltip, PeriodSelector]} />
<RangenavigatorSeriesCollectionDirective>
<RangenavigatorSeriesDirective dataSource={data} xName='x' yName='y' type='Area' width={2} />
</RangenavigatorSeriesCollectionDirective>
</RangeNavigatorComponent>
};
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));
Visibility of range navigator
The disableRangeSelector
property allows the users to display only the period selector and not the Range Selector.
import { AreaSeries, DateTime, Inject, RangeNavigatorComponent, RangeTooltip, PeriodSelector } 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 };
const periodselector = {
position: 'Top',
periods: [
{ text: '1M', interval: 1, intervalType: 'Months' },
{ text: '3M', interval: 3, intervalType: 'Months' },
{ text: '6M', interval: 6, intervalType: 'Months' }, { text: 'YTD' },
{ text: '1Y', interval: 1, intervalType: 'Years' },
{ text: '2Y', interval: 2, intervalType: 'Years', selected: true }, { text: 'All' }
]
};
return <RangeNavigatorComponent id='charts' valueType='DateTime' labelFormat='MMM-yy' value={[new Date('2017-09-01'), new Date('2018-02-01')]} dataSource={data} xName='x' yName='y' disableRangeSelector={true} tooltip={tooltip} periodSelectorSettings={periodselector}>
<Inject services={[AreaSeries, DateTime, RangeTooltip, PeriodSelector]} />
</RangeNavigatorComponent>;
};
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));
import {
AreaSeries, DateTime, Inject, RangeNavigatorComponent, RangeTooltip, PeriodSelector, RangeTooltipSettingsModel, PeriodSelectorSettingsModel
} 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 };
const periodselector: PeriodSelectorSettingsModel = {
position: 'Top',
periods: [
{ text: '1M', interval: 1, intervalType: 'Months' },
{ text: '3M', interval: 3, intervalType: 'Months' },
{ text: '6M', interval: 6, intervalType: 'Months' }, { text: 'YTD' },
{ text: '1Y', interval: 1, intervalType: 'Years' },
{ text: '2Y', interval: 2, intervalType: 'Years', selected: true }, { text: 'All' }
]
};
return <RangeNavigatorComponent id='charts'
valueType='DateTime' labelFormat='MMM-yy' value={[new Date('2017-09-01'), new Date('2018-02-01')]}
dataSource={data} xName='x' yName='y'
disableRangeSelector={true}
tooltip={tooltip}
periodSelectorSettings={periodselector}>
<Inject services={[AreaSeries, DateTime, RangeTooltip, PeriodSelector]} />
</RangeNavigatorComponent>
};
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));