How to add a footer and watermark in JavaScript Charts
Use the Chart annotations collection to render custom HTML as a footer or watermark. Use point coordinates for content tied to axis values and pixel coordinates for content positioned within the Chart area.
Configure the watermark
Set coordinateUnits to Point to position the watermark with X-axis and Y-axis values. In the following example, the watermark is positioned at the Wed category and the Y value 20.
Configure the footer
Set coordinateUnits to Pixel to position the footer with pixel coordinates. Pixel coordinates are measured within the annotation region, so fixed values must be adjusted when the Chart dimensions change.
The main annotation properties used by the example are:
-
content: Specifies the HTML string or element selector rendered by the annotation. -
xandy: Specify point values or pixel coordinates according tocoordinateUnits. -
coordinateUnits: AcceptsPointorPixel. -
region: Positions the annotation relative to the Chart or series region. -
horizontalAlignmentandverticalAlignment: Align the annotation around its calculated position.
Complete example
var chart = new ej.charts.Chart({
//Initializing Primary X Axis
primaryXAxis: {
valueType: 'Category',
interval: 1, majorGridLines: { width: 0 },
labelIntersectAction: 'Rotate90'
},
//Initializing Annotations
annotations: [{ // watermark for chart
content: '<div id="chart_cloud" style="font-size:450%; opacity: 0.3;" >syncfusion</div>',
x: 'Wed', y: 20, coordinateUnits: 'Point', horizontalAlignment: 'Center'
},{ //footer for chart
content: '<div id="chart" > <a href="https://www.syncfusion.com" target="_blank">www.syncfusion.com</a></div>',
x: 400, y: 340, coordinateUnits: 'Pixel', horizontalAlignment: 'Center'
}
],
//Initializing Primary Y Axis
primaryYAxis:
{
minimum: 0,
maximum: 40,
interval: 10,
},
//Initializing Chart Series
series: [
{
type: 'Spline',
dataSource: [
{ x: 'Sun', y: 15 }, { x: 'Mon', y: 5 },{ x: 'Tue', y: 32 },
{ x: 'Wed', y: 15 },{ x: 'Thu', y: 29 }, { x: 'Fri', y: 24 },
{ x: 'Sat', y: 18 },
],
xName: 'x', width: 2, marker: {
visible: true
},
yName: 'y', name: 'Max Temp',
}
],
//Initializing Chart title
title: 'NC Weather Report - 2016',
width:'650px',
height: '350px'
}, '#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="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
<script src="https://cdn.syncfusion.com/ej2/35.2.12/dist/ej2.min.js" type="text/javascript"></script>
</head>
<body>
<div id="container">
<div id="element"></div>
</div>
<script id="Female-Material" type="text/x-template">
<div id='templateWrap'>
<table style="width:100%; border: 1px solid black;">
<tr><th colspan="2" bgcolor="#00FFFF">Female</th></tr>
<tr><td bgcolor="#00FFFF">${x}:</td><td bgcolor="#00FFFF">${y}</td></tr>
</table>
</div>
</script>
<script>
var ele = document.getElementById('container');
if(ele) {
ele.style.visibility = "visible";
}
</script>
<script src="index.js" type="text/javascript"></script>
</body></html>Troubleshooting
- If an annotation is missing, verify that the
contentselector matches an existing template element. - If the watermark is in the wrong location, verify
coordinateUnits,region,x, andy. - If the footer is clipped, adjust the pixel coordinates, Chart dimensions, or margins.
- If footer placement changes after resizing, recalculate its pixel coordinates or move the footer outside the Chart.