Appearance in EJ2 JavaScript Sparkline control
18 Apr 202311 minutes to read
The appearance of the sparkline can be customized using margin, containerArea border, and containerArea background.
Sparkline border
The containerArea border
of the sparkline is used to render border to cover sparkline area.
The following code example shows the sparkline with overall border.
//Initialize Sparkline component
var sparklineInstance = new ej.charts.Sparkline({
// To render border around the sparkline
containerArea: {
border: { color: '#033e96', width: 2 }
},
border: { color: '#033e96', width: 1 },
height: '200px',
width: '350px',
type: 'Area',
fill: '#b2cfff',
dataSource: [3, 6, 4, 1, 3, 2, 5]
});
//Render initialized Sparkline
sparklineInstance.appendTo("#element");
<!DOCTYPE html><html lang="en"><head>
<title>Essential JS 2 for Sparkline </title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Essential JS 2 for Sparkline UI Control">
<meta name="author" content="Syncfusion">
<link href="index.css" rel="stylesheet">
<link href="https://cdn.syncfusion.com/ej2/23.1.36/ej2-charts/styles/material.css" rel="stylesheet">
<script src="https://cdn.syncfusion.com/ej2/23.1.36/dist/ej2.min.js" type="text/javascript"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id="container" style="margin-top: 15%;">
<div class="spark" id="element" align="center"></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>
Sparkline padding
Padding is used to specify padding value between container and sparkline. By default, padding value of the sparkline is 5. Sparkline padding
values are specified by the left, right, top, and bottom.
The following code example shows the sparkline with overall padding is set to 20.
//Initialize Sparkline component
var sparklineInstance = new ej.charts.Sparkline({
containerArea: {
border: { color: '#033e96', width: 2 }
},
// To render sparkline with padding
padding: { left: 20, right: 20, bottom: 20, top: 20},
border: { color: '#033e96', width: 1 },
height: '200px',
width: '350px',
type: 'Area',
fill: '#b2cfff',
dataSource: [3, 6, 4, 1, 3, 2, 5]
});
//Render initialized Sparkline
sparklineInstance.appendTo("#element");
<!DOCTYPE html><html lang="en"><head>
<title>Essential JS 2 for Sparkline </title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Essential JS 2 for Sparkline UI Control">
<meta name="author" content="Syncfusion">
<link href="index.css" rel="stylesheet">
<link href="https://cdn.syncfusion.com/ej2/23.1.36/ej2-charts/styles/material.css" rel="stylesheet">
<script src="https://cdn.syncfusion.com/ej2/23.1.36/dist/ej2.min.js" type="text/javascript"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id="container" style="margin-top: 15%;">
<div class="spark" id="element" align="center"></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>
Sparkline area customization
The background color of the sparkline area can be customized using the containerArea background
color. By default, the sparkline background color is transparent
.
//Initialize Sparkline component
var sparklineInstance = new ej.charts.Sparkline({
containerArea: {
border: { color: '#033e96', width: 2 },
// To render sparkline with background
background: '#eff1f4',
},
padding: { left: 20, right: 20, bottom: 20, top: 20},
border: { color: '#033e96', width: 2 },
height: '200px',
width: '350px',
type: 'Area',
fill: '#b2cfff',
dataSource: [3, 6, 4, 1, 3, 2, 5]
});
//Render initialized Sparkline
sparklineInstance.appendTo("#element");
<!DOCTYPE html><html lang="en"><head>
<title>Essential JS 2 for Sparkline </title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Essential JS 2 for Sparkline UI Control">
<meta name="author" content="Syncfusion">
<link href="index.css" rel="stylesheet">
<link href="https://cdn.syncfusion.com/ej2/23.1.36/ej2-charts/styles/material.css" rel="stylesheet">
<script src="https://cdn.syncfusion.com/ej2/23.1.36/dist/ej2.min.js" type="text/javascript"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id="container" style="margin-top: 15%;">
<div class="spark" id="element" align="center"></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>
Sparkline theme
Datalabel and trackline colors of the sparkline will be changed based on theme. For example, for dark theme, the color of datalabel and trackline should be white; for light theme, their value should be black. The possible values for sparkline theme are Material
, Fabric
, Bootstrap
, and Highcontrast
.
The following code example shows the color for datalabel and trackline is set to white for dark theme.
//Initialize Sparkline component
var sparklineInstance = new ej.charts.Sparkline({
// To specify theme
theme: 'Highcontrast',
dataLabelSettings: { visible: ['All']},
tooltipSettings: {
trackLineSettings: { visible: true }
},
axisSettings: {
minX: -1, maxX: 7
},
lineWidth: 3,
border: { color: 'transparent', width: 2 },
height: '200px',
width: '350px',
type: 'Line',
fill: '#007dd1',
dataSource: [3, 6, 4, 1, 3, 2, 5]
});
//Render initialized Sparkline
sparklineInstance.appendTo("#element");
<!DOCTYPE html><html lang="en"><head>
<title>Essential JS 2 for Sparkline </title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Essential JS 2 for Sparkline UI Control">
<meta name="author" content="Syncfusion">
<link href="index.css" rel="stylesheet">
<link href="https://cdn.syncfusion.com/ej2/23.1.36/ej2-charts/styles/material.css" rel="stylesheet">
<script src="https://cdn.syncfusion.com/ej2/23.1.36/dist/ej2.min.js" type="text/javascript"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id="container" style="margin-top: 15%;">
<div class="spark" id="element" align="center"></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>