- Sparkline border
- Sparkline padding
- Sparkline area customization
- Sparkline theme
Contact Support
Appearance in EJ2 TypeScript Sparkline control
18 Apr 202310 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.
import { Sparkline } from '@syncfusion/ej2-charts';
let sparkline: Sparkline = new 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]
});
sparkline.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/29.1.33/ej2-charts/styles/material.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
<script src="systemjs.config.js"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id='loader'>Loading....</div>
<div id='container' style="margin-top: 15%;">
<div class="spark" id="element" align="center" ></div>
</div>
</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.
import { Sparkline } from '@syncfusion/ej2-charts';
let sparkline: Sparkline = new 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]
});
sparkline.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/29.1.33/ej2-charts/styles/material.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
<script src="systemjs.config.js"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id='loader'>Loading....</div>
<div id='container' style="margin-top: 15%;">
<div class="spark" id="element" align="center" ></div>
</div>
</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
.
import { Sparkline } from '@syncfusion/ej2-charts';
let sparkline: Sparkline = new 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]
});
sparkline.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/29.1.33/ej2-charts/styles/material.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
<script src="systemjs.config.js"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id='loader'>Loading....</div>
<div id='container' style="margin-top: 15%;">
<div class="spark" id="element" align="center" ></div>
</div>
</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.
import { Sparkline, SparklineTooltip } from '@syncfusion/ej2-charts';
Sparkline.Inject(SparklineTooltip);
document.getElementById('container').style = 'background: #000000; margin-top: 15%;';
let sparkline: Sparkline = new 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]
});
sparkline.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/29.1.33/ej2-charts/styles/material.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
<script src="systemjs.config.js"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id='loader'>Loading....</div>
<div id='container' style="margin-top: 15%;">
<div class="spark" id="element" align="center" ></div>
</div>
</body>
</html>