Contents
- Size for Container
- Size for Stock Chart
Having trouble getting help?
Contact Support
Contact Support
Chart dimensions in EJ2 JavaScript Stock chart control
8 May 20236 minutes to read
Size for Container
Stock Chart can render to its container size. You can set the size via inline or CSS as demonstrated below.
var stockChart = new ej.charts.StockChart({
series: [
{
dataSource: chartData,
type: 'Candle'
},
],
width: '650', height: '350'
});
stockChart.appendTo('#element');
<!DOCTYPE html><html lang="en"><head>
<title>Chart dimension</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="./material.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>
Size for Stock Chart
You can also set size for chart directly through width
and height
properties.
In Pixel
You can set the size of chart in pixel as demonstrated below.
var stockChart = new ej.charts.StockChart({
series: [
{
dataSource: chartData,
type: 'Candle'
},
],
// Width and height for stock chart in pixel
width: '650', height: '350'
});
stockChart.appendTo('#element');
<!DOCTYPE html><html lang="en"><head>
<title>Chart dimension</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="./material.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>
In Percentage
By setting value in percentage, Stock Chart gets its dimension with respect to its container. For example, when the height is ‘50%’, Stock Chart renders to half of the container height.
var stockChart = new ej.charts.StockChart({
series: [
{
dataSource: chartData,
type: 'Candle'
},
],
// Width and height for stock chart in percentage
width: '80%', height: '90%'
});
stockChart.appendTo('#element');
<!DOCTYPE html><html lang="en"><head>
<title>Chart dimension</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="./material.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: When you do not specify the size, it takes
450px
as the height and window size as its width.