- Marker
- Shape
- Images
- Customization
- Customizing specific point
- Fill marker with series color
- See also
Contact Support
Data markers in EJ2 JavaScript Chart control
23 Jun 202324 minutes to read
Data markers are used to provide information about the data points in the series. You can add a shape to adorn each data point.
Marker
Markers can be added to points by enabling the visible
option of the marker property. By default, distinct markers will be enabled for each series in the chart.
var numData = [{ x: 2005, y: 28, y1: 18 }, { x: 2006, y: 25, y1: 10 },{ x: 2007, y: 26, y1: 20 }, { x: 2008, y: 47, y1: 35 },
{ x: 2009, y: 32, y1: 23 }, { x: 2010, y: 35, y1: 25 }, { x: 2011, y: 30, y1: 15 }];
var chart = new ej.charts.Chart({
series: [
{
type: 'Line',
dataSource: numData, xName: 'x', yName: 'y',
marker: {
visible: true
}
},
{
type: 'Line',
dataSource: numData, xName: 'x', yName: 'y1',
marker: {
visible: true
}
}
],
}, '#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">
<script src="https://cdn.syncfusion.com/ej2/29.1.33/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">
<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>
Shape
Markers can be assigned with different shapes such as Rectangle, Circle, Diamond, etc. using the shape
property.
var chartData = [
{ x: 'WW', y: 12, y1: 22, y2: 38.3, y3: 50 },
{ x: 'EU', y: 9.9, y1: 26, y2: 45.2, y3: 63.6 },
{ x: 'APAC', y: 4.4, y1: 9.3, y2: 18.2, y3: 20.9 },
{ x: 'LATAM', y: 6.4, y1: 28, y2: 46.7, y3: 65.1 },
{ x: 'MEA', y: 30, y1: 45.7, y2: 61.5, y3: 73 },
{ x: 'NA', y: 25.3, y1: 35.9, y2: 64, y3: 81.4 }
];
var chart = new ej.charts.Chart({
primaryXAxis: {
title: 'Countries',
valueType: 'Category', interval: 1,
labelIntersectAction : 'Rotate45'
},
primaryYAxis:
{
title: 'Penetration (%)',
labelFormat: '{value}%',
minimum: 0, maximum: 90
},
series: [
{
type: 'Line', name: 'December 2007',
dataSource: chartData, xName: 'x', yName: 'y', width: 2,
marker: {
visible: true,
width: 10, height: 10,
shape: 'Diamond'
}
}, {
type: 'Line', name: 'December 2008',
dataSource: chartData, xName: 'x', yName: 'y1', width: 2,
//Marker for chart series
marker: {
visible: true,
width: 10, height: 10,
shape: 'Pentagon'
}
}, {
type: 'Line', name: 'December 2009',
dataSource: chartData, xName: 'x', yName: 'y2', width: 2,
marker: {
visible: true,
width: 10, height: 10,
shape: 'Triangle',
}
}, {
type: 'Line', name: 'December 2010',
dataSource: chartData, xName: 'x', yName: 'y3', width: 2,
marker: {
visible: true,
width: 10, height: 10,
shape: 'Circle'
}
}
],
title: 'FB Penetration of Internet Audience'
}, '#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">
<script src="https://cdn.syncfusion.com/ej2/29.1.33/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">
<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 know more about the marker shape type refer the
shape
.
Images
Apart from the shapes, you can also add custom images to mark the data point using the imageUrl
property.
var chartData = [
{ x: "Jan", y: 60 }, { x: "Feb", y: 50 },
{ x: "Mar", y: 64 }, { x: "Apr", y: 63 },
{ x: "May", y: 81 }, { x: "Jun", y: 64 },
{ x: "Jul", y: 82 }, { x: "Aug", y: 96 },
{ x: "Sep", y: 78 }, { x: "Oct", y: 60 },
{ x: "Nov", y: 58 }, { x: "Dec", y: 56 }
];
var chart = new ej.charts.Chart({
primaryXAxis: {
title: 'Month',
valueType: 'Category'
},
primaryYAxis:
{
title: 'Temperature (Celsius)',
labelFormat: '{value}°C'
},
series: [
{
type: 'Line', name: 'India',
dataSource: chartData, xName: 'x', yName: 'y', width: 2,
//Marker shape as image
marker: {
visible: true,
width: 10, height: 10,
shape: 'Image',
imageUrl:'sun_annotation.png'
}
}
],
title: 'Temperature flow over months'
}, '#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">
<script src="https://cdn.syncfusion.com/ej2/29.1.33/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">
<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>
Customization
Marker’s color and border can be customized using fill
and border
properties.
var chartData = [
{ x: 'WW', y: 12, y1: 22, y2: 38.3, y3: 50 },
{ x: 'EU', y: 9.9, y1: 26, y2: 45.2, y3: 63.6 },
{ x: 'APAC', y: 4.4, y1: 9.3, y2: 18.2, y3: 20.9 },
{ x: 'LATAM', y: 6.4, y1: 28, y2: 46.7, y3: 65.1 },
{ x: 'MEA', y: 30, y1: 45.7, y2: 61.5, y3: 73 },
{ x: 'NA', y: 25.3, y1: 35.9, y2: 64, y3: 81.4 }
];
var chart = new ej.charts.Chart({
primaryXAxis: {
title: 'Countries',
valueType: 'Category', interval: 1,
labelIntersectAction : 'Rotate45'
},
primaryYAxis:
{
title: 'Penetration (%)',
labelFormat: '{value}%',
minimum: 0, maximum: 90
},
series: [
{
type: 'Line', name: 'December 2007',
dataSource: chartData, xName: 'x', yName: 'y', width: 2,
marker: {
visible: true,
width: 10, height: 10,
shape: 'Diamond'
}
}, {
type: 'Line', name: 'December 2008',
dataSource: chartData, xName: 'x', yName: 'y1', width: 2,
//Marker for chart series
marker: {
visible: true,
width: 10, height: 10,
shape: 'Pentagon'
}
}, {
type: 'Line', name: 'December 2009',
dataSource: chartData, xName: 'x', yName: 'y2', width: 2,
marker: {
visible: true,
width: 10, height: 10,
shape: 'Triangle',
}
}, {
type: 'Line', name: 'December 2010',
dataSource: chartData, xName: 'x', yName: 'y3', width: 2,
marker: {
visible: true,
width: 10, height: 10,
shape: 'Circle'
}
}
],
title: 'FB Penetration of Internet Audience'
}, '#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">
<script src="https://cdn.syncfusion.com/ej2/29.1.33/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">
<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>
Customizing specific point
You can also customize the specific marker and label using pointRender
event. The pointRender
event allows you to change the shape, color and border for a point.
var chartData = [
{ x: 'Jan', y: -7.1 }, { x: 'Feb', y: -3.7 },
{ x: 'Mar', y: 2 }, { x: 'Apr', y: 6.3 },
{ x: 'May', y: 13.3 }, { x: 'Jun', y: 18.0 },
{ x: 'Jul', y: 19.8 }, { x: 'Aug', y: 18.1 },
{ x: 'Sep', y: 13.1 }, { x: 'Oct', y: 4.1 },
{ x: 'Nov', y: -3.8 }, { x: 'Dec', y: -6.8 }
];
var chart = new ej.charts.Chart({
primaryXAxis: {
title: 'Months',
valueType: 'Category'
},
primaryYAxis:
{
title: 'Temperature (Celsius)',
minimum: -20, maximum: 25, interval: 5,
edgeLabelPlacement: 'Shift',
labelFormat: '{value}°C'
},
series: [
{
type: 'Line', name: 'Warmest', width: 2,
dataSource: chartData, xName: 'x', yName: 'y',
marker: {
visible: true,
height: 10, width: 10,
shape: 'Pentagon',
dataLabel: { visible: true }
}
}
],
title: 'Alaska Weather Statistics - 2016',
// pointRender event for chart
pointRender: (args) => {
if (args.point.index === 6) {
args.fill = 'red'
}
},
textRender: (args) => {
if (args.point.index === 6) {
args.text = 'Maximum Temperature';
args.color = 'red';
}
}
}, '#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">
<script src="https://cdn.syncfusion.com/ej2/29.1.33/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">
<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>
Fill marker with series color
Marker can be filled with the series color by setting the isFilled
property to true.
var chartData = [
{ x: 'WW', y: 12, y1: 22, y2: 38.3, y3: 50 },
{ x: 'EU', y: 9.9, y1: 26, y2: 45.2, y3: 63.6 },
{ x: 'APAC', y: 4.4, y1: 9.3, y2: 18.2, y3: 20.9 },
{ x: 'LATAM', y: 6.4, y1: 28, y2: 46.7, y3: 65.1 },
{ x: 'MEA', y: 30, y1: 45.7, y2: 61.5, y3: 73 },
{ x: 'NA', y: 25.3, y1: 35.9, y2: 64, y3: 81.4 },
];
var chart = new ej.charts.Chart(
{
primaryXAxis: {
title: 'Countries',
valueType: 'Category',
interval: 1,
labelIntersectAction: 'Rotate45',
},
primaryYAxis: {
title: 'Penetration (%)',
labelFormat: '{value}%',
minimum: 0,
maximum: 90,
},
series: [
{
type: 'Line',
name: 'December 2007',
dataSource: chartData,
xName: 'x',
yName: 'y',
width: 2,
marker: {
visible: true,
width: 10,
height: 10,
shape: 'Diamond',
isFilled: true,
},
},
{
type: 'Line',
name: 'December 2008',
dataSource: chartData,
xName: 'x',
yName: 'y1',
width: 2,
//Marker for chart series
marker: {
visible: true,
width: 10,
height: 10,
shape: 'Pentagon',
isFilled: true,
},
},
{
type: 'Line',
name: 'December 2009',
dataSource: chartData,
xName: 'x',
yName: 'y2',
width: 2,
marker: {
visible: true,
width: 10,
height: 10,
shape: 'Triangle',
isFilled: true,
},
},
{
type: 'Line',
name: 'December 2010',
dataSource: chartData,
xName: 'x',
yName: 'y3',
width: 2,
marker: {
visible: true,
width: 10,
height: 10,
shape: 'Circle',
isFilled: true,
},
},
],
title: 'FB Penetration of Internet Audience',
},
'#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">
<script src="https://cdn.syncfusion.com/ej2/29.1.33/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">
<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>