- DateTime axis
- DateTimeCategory axis
- Logarithmic axis
- See also
Contact Support
Axis types in EJ2 JavaScript Stock chart control
25 Sep 202313 minutes to read
DateTime axis
DateTime axis uses date time scale and displays the date time values as axis labels in the specified format. To use DateTime axis, set the valueType
of axis to DateTime
.
var stockChart = new ej.charts.StockChart({
primaryXAxis: { valueType: 'DateTime' },
series: [
{
dataSource: chartData,
type: 'Candle'
},
],
});
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/28.2.3/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>
Note: To use this axis, we need to inject DateTime using
StockChart.Inject(DateTime)
method and set thevalueType
of axis toDateTime
.
DateTimeCategory axis
DateTimeCategory axis in the stock chart is used to display only business days. To use DateTimeCategory axis, set the valueType
of axis to DateTimeCategory
.
let datetimeCategoryData = [
{ x: new Date(2021, 1, 11) }, { x: new Date(2021, 1, 12) }, { x: new Date(2021, 1, 13) }, { x: new Date(2021, 1, 14) }, { x: new Date(2021, 1, 15) },
{ x: new Date(2021, 1, 19) }, { x: new Date(2021, 1, 20) }, { x: new Date(2021, 1, 21) }, { x: new Date(2021, 1, 22) }, { x: new Date(2021, 3, 1) },
{ x: new Date(2021, 3, 2) }, { x: new Date(2021, 4, 1) }, { x: new Date(2021, 4, 5) }, { x: new Date(2021, 4, 6) }, { x: new Date(2021, 4, 7) },
{ x: new Date(2021, 4, 11) }, { x: new Date(2021, 4, 13) }, { x: new Date(2021, 4, 15) }, { x: new Date(2021, 4, 16) }, { x: new Date(2021, 4, 17) },
{ x: new Date(2021, 4, 18) }, { x: new Date(2021, 4, 20) }, { x: new Date(2021, 4, 21) }, { x: new Date(2021, 4, 23) }, { x: new Date(2021, 4, 25) },
{ x: new Date(2021, 5, 1) }, { x: new Date(2021, 5, 2) }, { x: new Date(2021, 5, 6) }, { x: new Date(2021, 5, 7) }, { x: new Date(2021, 5, 8) },
{ x: new Date(2021, 5, 11) }, { x: new Date(2021, 5, 15) }, { x: new Date(2021, 5, 18) }, { x: new Date(2021, 5, 20) }, { x: new Date(2021, 5, 25) },
{ x: new Date(2021, 6, 1) }, { x: new Date(2021, 6, 2) }, { x: new Date(2021, 6, 3) }, { x: new Date(2021, 6, 4) }, { x: new Date(2021, 6, 5) },
{ x: new Date(2021, 6, 10) }, { x: new Date(2021, 6, 11) }, { x: new Date(2021, 6, 12) }, { x: new Date(2021, 6, 13) }, { x: new Date(2021, 6, 15) },
{ x: new Date(2021, 6, 16) }, { x: new Date(2021, 6, 17) }, { x: new Date(2021, 6, 18) }, { x: new Date(2021, 6, 19) }, { x: new Date(2021, 6, 20) }
]
let series2 = [];
let point2;
for (var i = 0; i < 46; i++) {
point2 = {
x: datetimeCategoryData[i].x,
y: getRandomInRange(120, 130),
high: getRandomInRange(88, 92),
low: getRandomInRange(76, 86),
open: getRandomInRange(75, 85),
close: getRandomInRange(85, 90),
volume: getRandomInRange(660187068, 965935749)
};
series2.push(point2);
}
function getRandomInRange(min, max) {
const randomDecimal = Math.random();
const randomValue = randomDecimal * (max - min) + min;
return randomValue;
}
var stockChart = new ej.charts.StockChart({
primaryXAxis: { valueType: 'DateTimeCategory', majorGridLines: { width: 0 }, crosshairTooltip: { enable: true } },
series: [
{
dataSource: series2,
type: 'Line', xName: 'x', yName: 'y'
},
],
tooltip: {
enable: true, header: 'AAPL Stock Price'
},
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/28.2.3/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>
Note: To use this axis, we need to inject DateTimeCategory using
StockChart.Inject(DateTimeCategory)
method and set thevalueType
of axis toDateTimeCategory
.
Logarithmic axis
Logarithmic axis uses logarithmic scale and it is very useful in visualizing data, when it has numerical values in both lower order of magnitude (eg: 10-6) and higher order of magnitude (eg: 106). To use Logarithmic axis, set the valueType
of axis to Logarithmic
.
var stockChart = new ej.charts.StockChart({
primaryXAxis: { valueType: 'DateTime' },
series: [
{
dataSource: chartData,
type: 'Candle'
},
],
});
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/28.2.3/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>
Note: To use this axis, we need to inject Logarithmic using
StockChart.Inject(Logarithmic)
method and set thevalueType
of axis toLogarithmic
.