Period selector in EJ2 JavaScript Stock chart control
8 May 20239 minutes to read
The period selector allows to select a range with specified periods. By default the period selector is enabled in stock chart.
Periods
Periods is an array of objects that allows users to specify the range of periods
. The interval
property specifies the count value of the button, and the text
property specifies the text to be displayed on button. The intervalType
property allows users to customize the intervals of the buttons. The intervalType
property supports the following interval types:
- Auto
- Years
- Quarter
- Months
- Weeks
- Days
- Hours
- Minutes
- Seconds
function GetDateTimeData() {
var series1 = [];
var point1;
var value = 80;
var i;
for (i = 1; i < 500; i++) {
if (Math.random() > .5) {
value += Math.random();
} else {
value -= Math.random();
}
point1 = { x: new Date(2000, 1, 1, 0, i), y: value.toFixed(1) };
series1.push(point1);
}
}
var stockChart = new ej.charts.StockChart({
primaryXAxis: { valueType: 'DateTime', majorGridLines: { color: 'transparent' },
crosshairTooltip: { enable: true } },
primaryYAxis: {
lineStyle: { color: 'transparent' },
majorTickLines: { color: 'transparent', width: 0 },
crosshairTooltip: { enable: true }
},
series: [
{
dataSource: series1, type: 'Line', xName: 'x', yName: 'y', name: 'google'
}
],
seriesType: [],
indicatorType: [],
exportType: [],
trendlineType : [],
periods: [
{ intervalType: 'Minutes', interval: 1, text: '1m' },
{ intervalType: 'Minutes', interval: 30, text: '30m' },
{ intervalType: 'Hours', interval: 1, text: '1H' },
{ intervalType: 'Hours', interval: 12, text: '12H', selected: true },
{ text: '1D' }
],
title: 'AAPL stock price by minutes',
crosshair: {
enable: true
},
});
stockChart.appendTo('#element');
<!DOCTYPE html><html lang="en"><head>
<title>EJ2 Animation</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Typescript UI Controls">
<meta name="author" content="Syncfusion">
<link href="./index.css" rel="stylesheet">
<link href="http://cdn.syncfusion.com/ej2/material.css" rel="stylesheet">
<script src="https://cdn.syncfusion.com/ej2/27.2.2/dist/ej2.min.js" type="text/javascript"></script>
<script src="es5-datasource.js" type="text/javascript"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id="container">
<div id="element"></div>
</div>
<script>
var ele = document.getElementById('container');
if(ele) {
ele.style.visibility = "visible";
}
</script>
<script src="index.js" type="text/javascript"></script>
</body></html>
Visibility of period selector
The enablePeriodSelector
property allows users to toggle the visibility of period selector.
var stockChart = new ej.charts.StockChart({
enablePeriodSelector: false,
primaryXAxis: { valueType: 'DateTime', majorGridLines: { color: 'transparent' },
crosshairTooltip: { enable: true } },
primaryYAxis: {
lineStyle: { color: 'transparent' },
majorTickLines: { color: 'transparent', width: 0 },
crosshairTooltip: { enable: true }
},
series: [
{
dataSource: chartData, type: 'Candle', name: 'google',
}
],
title: 'AAPL stock price by minutes',
crosshair: {
enable: true
}
});
stockChart.appendTo('#element');
<!DOCTYPE html><html lang="en"><head>
<title>EJ2 Animation</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Typescript UI Controls">
<meta name="author" content="Syncfusion">
<link href="./index.css" rel="stylesheet">
<link href="http://cdn.syncfusion.com/ej2/material.css" rel="stylesheet">
<script src="https://cdn.syncfusion.com/ej2/27.2.2/dist/ej2.min.js" type="text/javascript"></script>
<script src="es5-datasource.js" type="text/javascript"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id="container">
<div id="element"></div>
</div>
<script>
var ele = document.getElementById('container');
if(ele) {
ele.style.visibility = "visible";
}
</script>
<script src="index.js" type="text/javascript"></script>
</body></html>