- Scatter charts
- Binding data with series
- Series customization
- Empty points
- Events
- See also
Contact Support
Scatter Chart in EJ2 TypeScript control
19 Mar 202524 minutes to read
Scatter charts
To render a scatter series in your chart, you need to follow a few steps to configure it correctly. Here’s a concise guide on how to do this:
-
Set the series type: Define the series
type
asScatter
in your chart configuration. This indicates that the data should be displayed as individual points scattered across the chart. -
Inject the ScatterSeries module: Use the
Chart.Inject(ScatterSeries)
method to inject theScatterSeries
module into your chart. This step is essential, as it ensures that the necessary functionalities for rendering the scatter series are available in your chart.
import { Chart, ScatterSeries, Legend } from '@syncfusion/ej2-charts';
Chart.Inject(ScatterSeries, Legend);
let series1: Object[] = [];
let series2: Object[] = [];
let point1: Object;
let value: number = 80;
let value1: number = 70;
let i: number;
for (i = 1; i < 120; i++) {
if (Math.random() > 0.5) {
value += Math.random();
} else {
value -= Math.random();
}
value = value < 60 ? 60 : value > 90 ? 90 : value;
point1 = { x: 120 + (i / 2), y: value.toFixed(1) };
series1.push(point1);
}
for (i = 1; i < 120; i++) {
if (Math.random() > 0.5) {
value1 += Math.random();
} else {
value1 -= Math.random();
}
value1 = value1 < 60 ? 60 : value1 > 90 ? 90 : value1;
point1 = { x: 120 + (i / 2), y: value1.toFixed(1) };
series2.push(point1);
}
let chart: Chart = new Chart({
primaryXAxis: {
title: 'Height (cm)',
minimum: 120, maximum: 180,
edgeLabelPlacement: 'Shift',
labelFormat: '{value}cm'
},
primaryYAxis:
{
title: 'Weight (kg)',
minimum: 60, maximum: 90,
labelFormat: '{value}kg',
rangePadding: 'None'
},
series: [
{
//Series type as scatter
type: 'Scatter',
dataSource: series1, xName: 'x', yName: 'y',
name: 'Male',
marker: { width: 10, height: 10 }
},
{
type: 'Scatter',
dataSource: series2, xName: 'x', yName: 'y',
name: 'Female',
marker: { width: 10, height: 10 }
}
],
title: 'Height Vs Weight'
}, '#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://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'>
<div id='element'></div>
</div>
</body>
</html>
Binding data with series
You can bind data to the chart using the dataSource
property within the series configuration. This allows you to connect a JSON dataset or remote data to your chart. To display the data correctly, map the fields from the data to the chart series xName
and yName
properties.
import { Chart, ScatterSeries, Legend } from '@syncfusion/ej2-charts';
Chart.Inject(ScatterSeries, Legend);
let series1: Object[] = [];
let series2: Object[] = [];
let point1: Object;
let value: number = 80;
let value1: number = 70;
let i: number;
for (i = 1; i < 120; i++) {
if (Math.random() > 0.5) {
value += Math.random();
} else {
value -= Math.random();
}
value = value < 60 ? 60 : value > 90 ? 90 : value;
point1 = { x: 120 + (i / 2), y: value.toFixed(1) };
series1.push(point1);
}
for (i = 1; i < 120; i++) {
if (Math.random() > 0.5) {
value1 += Math.random();
} else {
value1 -= Math.random();
}
value1 = value1 < 60 ? 60 : value1 > 90 ? 90 : value1;
point1 = { x: 120 + (i / 2), y: value1.toFixed(1) };
series2.push(point1);
}
let chart: Chart = new Chart({
primaryXAxis: {
title: 'Height (cm)',
minimum: 120, maximum: 180,
edgeLabelPlacement: 'Shift',
labelFormat: '{value}cm'
},
primaryYAxis:
{
title: 'Weight (kg)',
minimum: 60, maximum: 90,
labelFormat: '{value}kg',
rangePadding: 'None'
},
series: [
{
//Series type as scatter
type: 'Scatter',
dataSource: series1, xName: 'x', yName: 'y',
name: 'Male',
marker: { width: 10, height: 10 }
},
{
type: 'Scatter',
dataSource: series2, xName: 'x', yName: 'y',
name: 'Female',
marker: { width: 10, height: 10 }
}
],
title: 'Height Vs Weight'
}, '#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://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'>
<div id='element'></div>
</div>
</body>
</html>
Series customization
The following properties can be used to customize the scatter
series.
Fill
The fill property determines the color applied to the series.
import { Chart, ScatterSeries, Legend } from '@syncfusion/ej2-charts';
Chart.Inject(ScatterSeries, Legend);
let series1: Object[] = [];
let series2: Object[] = [];
let point1: Object;
let value: number = 80;
let value1: number = 70;
let i: number;
for (i = 1; i < 120; i++) {
if (Math.random() > 0.5) {
value += Math.random();
} else {
value -= Math.random();
}
value = value < 60 ? 60 : value > 90 ? 90 : value;
point1 = { x: 120 + (i / 2), y: value.toFixed(1) };
series1.push(point1);
}
for (i = 1; i < 120; i++) {
if (Math.random() > 0.5) {
value1 += Math.random();
} else {
value1 -= Math.random();
}
value1 = value1 < 60 ? 60 : value1 > 90 ? 90 : value1;
point1 = { x: 120 + (i / 2), y: value1.toFixed(1) };
series2.push(point1);
}
let chart: Chart = new Chart({
primaryXAxis: {
title: 'Height (cm)',
minimum: 120,
maximum: 180,
edgeLabelPlacement: 'Shift',
labelFormat: '{value}cm'
},
primaryYAxis: {
title: 'Weight (kg)',
minimum: 60,
maximum: 90,
labelFormat: '{value}kg',
rangePadding: 'None'
},
series: [
{
type: 'Scatter',
dataSource: series1,
xName: 'x',
yName: 'y',
name: 'Male',
marker: { width: 5, height: 5 }
},
{
type: 'Scatter',
dataSource: series2,
xName: 'x',
yName: 'y',
name: 'Female',
fill: 'red',
marker: { width: 3, height: 3 }
}
],
title: 'Height Vs Weight'
}, '#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://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'>
<div id='element'></div>
</div>
</body>
</html>
Opacity
The opacity property specifies the transparency level of the fill. Adjusting this property allows you to control how opaque or transparent the fill color of the series appears.
import { Chart, ScatterSeries, Legend } from '@syncfusion/ej2-charts';
Chart.Inject(ScatterSeries, Legend);
let series1: Object[] = [];
let series2: Object[] = [];
let point1: Object;
let value: number = 80;
let value1: number = 70;
let i: number;
for (i = 1; i < 120; i++) {
if (Math.random() > 0.5) {
value += Math.random();
} else {
value -= Math.random();
}
value = value < 60 ? 60 : value > 90 ? 90 : value;
point1 = { x: 120 + (i / 2), y: value.toFixed(1) };
series1.push(point1);
}
for (i = 1; i < 120; i++) {
if (Math.random() > 0.5) {
value1 += Math.random();
} else {
value1 -= Math.random();
}
value1 = value1 < 60 ? 60 : value1 > 90 ? 90 : value1;
point1 = { x: 120 + (i / 2), y: value1.toFixed(1) };
series2.push(point1);
}
let chart: Chart = new Chart({
primaryXAxis: {
title: 'Height (cm)',
minimum: 120,
maximum: 180,
edgeLabelPlacement: 'Shift',
labelFormat: '{value}cm'
},
primaryYAxis: {
title: 'Weight (kg)',
minimum: 60,
maximum: 90,
labelFormat: '{value}kg',
rangePadding: 'None'
},
series: [
{
type: 'Scatter',
dataSource: series1,
xName: 'x',
yName: 'y',
name: 'Male',
opacity: 0.7,
marker: { width: 5, height: 5 }
},
{
type: 'Scatter',
dataSource: series2,
xName: 'x',
yName: 'y',
name: 'Female',
opacity: 0.7,
fill: 'red',
marker: { width: 3, height: 3 }
}
],
title: 'Height Vs Weight'
}, '#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://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'>
<div id='element'></div>
</div>
</body>
</html>
Shape
The shape property allows you to customize the appearance of the markers by specifying different shapes.
import { Chart, ScatterSeries, Legend } from '@syncfusion/ej2-charts';
Chart.Inject(ScatterSeries, Legend);
let series1: Object[] = [];
let series2: Object[] = [];
let point1: Object;
let value: number = 80;
let value1: number = 70;
let i: number;
for (i = 1; i < 120; i++) {
if (Math.random() > 0.5) {
value += Math.random();
} else {
value -= Math.random();
}
value = value < 60 ? 60 : value > 90 ? 90 : value;
point1 = { x: 120 + (i / 2), y: value.toFixed(1) };
series1.push(point1);
}
for (i = 1; i < 120; i++) {
if (Math.random() > 0.5) {
value1 += Math.random();
} else {
value1 -= Math.random();
}
value1 = value1 < 60 ? 60 : value1 > 90 ? 90 : value1;
point1 = { x: 120 + (i / 2), y: value1.toFixed(1) };
series2.push(point1);
}
let chart: Chart = new Chart({
primaryXAxis: {
title: 'Height (cm)',
minimum: 120,
maximum: 180,
edgeLabelPlacement: 'Shift',
labelFormat: '{value}cm'
},
primaryYAxis: {
title: 'Weight (kg)',
minimum: 60,
maximum: 90,
labelFormat: '{value}kg',
rangePadding: 'None'
},
series: [
{
type: 'Scatter',
dataSource: series1,
xName: 'x',
yName: 'y',
name: 'Male',
opacity: 0.7,
marker: { width: 5, height: 5, shape: 'Triangle' }
},
{
type: 'Scatter',
dataSource: series2,
xName: 'x',
yName: 'y',
name: 'Female',
opacity: 0.7,
fill: 'red',
marker: { width: 3, height: 3, shape: 'Square' }
}
],
title: 'Height Vs Weight'
}, '#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://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'>
<div id='element'></div>
</div>
</body>
</html>
Border
The border property allows you to customize the border of the series by defining its color, width, and dashArray.
import { Chart, ScatterSeries, Legend } from '@syncfusion/ej2-charts';
Chart.Inject(ScatterSeries, Legend);
let series1: Object[] = [];
let series2: Object[] = [];
let point1: Object;
let value: number = 80;
let value1: number = 70;
let i: number;
for (i = 1; i < 8; i++) {
if (Math.random() > 0.5) {
value += Math.random();
} else {
value -= Math.random();
}
value = value < 60 ? 60 : value > 90 ? 90 : value;
point1 = { x: 120 + (i / 2), y: value.toFixed(1) };
series1.push(point1);
}
for (i = 1; i < 8; i++) {
if (Math.random() > 0.5) {
value1 += Math.random();
} else {
value1 -= Math.random();
}
value1 = value1 < 60 ? 60 : value1 > 90 ? 90 : value1;
point1 = { x: 120 + (i / 2), y: value1.toFixed(1) };
series2.push(point1);
}
let chart: Chart = new Chart({
primaryXAxis: {
title: 'Height (cm)',
edgeLabelPlacement: 'Shift',
labelFormat: '{value}cm'
},
primaryYAxis: {
title: 'Weight (kg)',
minimum: 60,
maximum: 90,
labelFormat: '{value}kg',
rangePadding: 'None'
},
series: [
{
type: 'Scatter',
dataSource: series1,
xName: 'x',
yName: 'y',
name: 'Male',
opacity: 0.7,
border: { width: 2, color: 'red' },
marker: { width: 22, height: 22, shape: 'Circle' },
},
{
type: 'Scatter',
dataSource: series2,
xName: 'x',
yName: 'y',
name: 'Female',
opacity: 0.7,
fill: 'red',
border: { width: 2, color: 'Blue', dashArray: '15,2' },
marker: { width: 22, height: 22, shape: 'Circle' },
}
],
title: 'Height Vs Weight'
}, '#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://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'>
<div id='element'></div>
</div>
</body>
</html>
Empty points
Data points with null
or undefined
values are considered empty. Empty data points are ignored and not plotted on the chart.
Mode
Use the mode
property to define how empty or missing data points are handled in the series. The default mode for empty points is Gap
.
import { Chart, ScatterSeries, Legend } from '@syncfusion/ej2-charts';
import { scatterData } from './datasource.ts';
Chart.Inject(ScatterSeries, Legend);
let chart: Chart = new Chart({
primaryXAxis: {
minimum: 0,
maximum: 21,
interval: 3,
majorGridLines: { width: 0 },
title: 'Study Hours (Per Week)'
},
primaryYAxis:
{
title: 'Test Scores (%)',
minimum: 0,
maximum: 120,
interval: 20,
labelFormat: '{value}%'
},
series: [
{
type: 'Scatter',
dataSource: scatterData,
xName: 'x',
yName: 'y',
marker: {
visible: false,
width: 10,
height: 10,
shape: 'Circle'
},
emptyPointSettings: {
mode: 'Zero'
}
}
],
title: 'Relationship Between Study Hours and Test Scores'
}, '#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://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'>
<div id='element'></div>
</div>
</body>
</html>
export let scatterData: Object[] = [
{ x: 1, y: 15 },
{ x: 2, y: 25 },
{ x: 3, y: 35 },
{ x: 4, y: null },
{ x: 5, y: 55 },
{ x: 6, y: 60 },
{ x: 7, y: 65 },
{ x: 8, y: 70 },
{ x: 9, y: 75 },
{ x: 10, y: 80 },
{ x: 11, y: undefined },
{ x: 12, y: 90 },
{ x: 13, y: 92 },
{ x: 14, y: 94 },
{ x: 15, y: 96 },
{ x: 16, y: null },
{ x: 17, y: 98 },
{ x: 18, y: 99 },
{ x: 19, y: 100 },
{ x: 20, y: 100 }
];
Fill
Use the fill
property to customize the fill color of empty points in the series.
import { Chart, ScatterSeries, Legend } from '@syncfusion/ej2-charts';
import { scatterData } from './datasource.ts';
Chart.Inject(ScatterSeries, Legend);
let chart: Chart = new Chart({
primaryXAxis: {
minimum: 0,
maximum: 21,
interval: 3,
majorGridLines: { width: 0 },
title: 'Study Hours (Per Week)'
},
primaryYAxis:
{
title: 'Test Scores (%)',
minimum: 0,
maximum: 120,
interval: 20,
labelFormat: '{value}%'
},
series: [
{
type: 'Scatter',
dataSource: scatterData,
xName: 'x',
yName: 'y',
marker: {
visible: false,
width: 10,
height: 10,
shape: 'Circle'
},
emptyPointSettings: {
mode: 'Average',
fill: 'red'
}
}
],
title: 'Relationship Between Study Hours and Test Scores'
}, '#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://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'>
<div id='element'></div>
</div>
</body>
</html>
export let scatterData: Object[] = [
{ x: 1, y: 15 },
{ x: 2, y: 25 },
{ x: 3, y: 35 },
{ x: 4, y: null },
{ x: 5, y: 55 },
{ x: 6, y: 60 },
{ x: 7, y: 65 },
{ x: 8, y: 70 },
{ x: 9, y: 75 },
{ x: 10, y: 80 },
{ x: 11, y: undefined },
{ x: 12, y: 90 },
{ x: 13, y: 92 },
{ x: 14, y: 94 },
{ x: 15, y: 96 },
{ x: 16, y: null },
{ x: 17, y: 98 },
{ x: 18, y: 99 },
{ x: 19, y: 100 },
{ x: 20, y: 100 }
];
Border
Use the border
property to customize the width and color of the border for empty points.
import { Chart, ScatterSeries, Legend } from '@syncfusion/ej2-charts';
import { scatterData } from './datasource.ts';
Chart.Inject(ScatterSeries, Legend);
let chart: Chart = new Chart({
primaryXAxis: {
minimum: 0,
maximum: 21,
interval: 3,
majorGridLines: { width: 0 },
title: 'Study Hours (Per Week)'
},
primaryYAxis:
{
title: 'Test Scores (%)',
minimum: 0,
maximum: 120,
interval: 20,
labelFormat: '{value}%'
},
series: [
{
type: 'Scatter',
dataSource: scatterData,
xName: 'x',
yName: 'y',
marker: {
visible: false,
width: 10,
height: 10,
shape: 'Circle'
},
emptyPointSettings: {
mode: 'Average',
fill: 'red',
border: { width: 2, color: 'green' }
}
}
],
title: 'Relationship Between Study Hours and Test Scores'
}, '#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://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'>
<div id='element'></div>
</div>
</body>
</html>
export let scatterData: Object[] = [
{ x: 1, y: 15 },
{ x: 2, y: 25 },
{ x: 3, y: 35 },
{ x: 4, y: null },
{ x: 5, y: 55 },
{ x: 6, y: 60 },
{ x: 7, y: 65 },
{ x: 8, y: 70 },
{ x: 9, y: 75 },
{ x: 10, y: 80 },
{ x: 11, y: undefined },
{ x: 12, y: 90 },
{ x: 13, y: 92 },
{ x: 14, y: 94 },
{ x: 15, y: 96 },
{ x: 16, y: null },
{ x: 17, y: 98 },
{ x: 18, y: 99 },
{ x: 19, y: 100 },
{ x: 20, y: 100 }
];
Events
Series render
The seriesRender
event allows you to customize series properties, such as data, fill, and name, before they are rendered on the chart.
import { Chart, ScatterSeries, Legend, ISeriesRenderEventArgs } from '@syncfusion/ej2-charts';
import { scatterData } from './datasource.ts';
Chart.Inject(ScatterSeries, Legend);
let chart: Chart = new Chart({
primaryXAxis: {
minimum: 0,
maximum: 21,
interval: 3,
majorGridLines: { width: 0 },
title: 'Study Hours (Per Week)'
},
primaryYAxis:
{
title: 'Test Scores (%)',
minimum: 0,
maximum: 120,
interval: 20,
labelFormat: '{value}%'
},
series: [
{
type: 'Scatter',
dataSource: scatterData,
xName: 'x',
yName: 'y',
marker: {
visible: false,
width: 10,
height: 10,
shape: 'Circle'
}
}
],
title: 'Relationship Between Study Hours and Test Scores',
seriesRender: (args: ISeriesRenderEventArgs) => {
args.fill = '#ff6347';
}
}, '#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://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'>
<div id='element'></div>
</div>
</body>
</html>
export let scatterData: Object[] = [
{ x: 1, y: 15 },
{ x: 2, y: 25 },
{ x: 3, y: 35 },
{ x: 4, y: 45 },
{ x: 5, y: 55 },
{ x: 6, y: 60 },
{ x: 7, y: 65 },
{ x: 8, y: 70 },
{ x: 9, y: 75 },
{ x: 10, y: 80 },
{ x: 11, y: 85 },
{ x: 12, y: 90 },
{ x: 13, y: 92 },
{ x: 14, y: 94 },
{ x: 15, y: 96 },
{ x: 16, y: 97 },
{ x: 17, y: 98 },
{ x: 18, y: 99 },
{ x: 19, y: 100 },
{ x: 20, y: 100 }
];
Point render
The pointRender
event allows you to customize each data point before it is rendered on the chart.
import { Chart, ScatterSeries, Legend, IPointRenderEventArgs } from '@syncfusion/ej2-charts';
import { scatterData } from './datasource.ts';
Chart.Inject(ScatterSeries, Legend);
let chart: Chart = new Chart({
primaryXAxis: {
minimum: 0,
maximum: 21,
interval: 3,
majorGridLines: { width: 0 },
title: 'Study Hours (Per Week)'
},
primaryYAxis:
{
title: 'Test Scores (%)',
minimum: 0,
maximum: 120,
interval: 20,
labelFormat: '{value}%'
},
series: [
{
type: 'Scatter',
dataSource: scatterData,
xName: 'x',
yName: 'y',
marker: {
visible: false,
width: 10,
height: 10,
shape: 'Circle'
}
}
],
title: 'Relationship Between Study Hours and Test Scores',
pointRender: (args: IPointRenderEventArgs) => {
if (args.point.index % 2 !== 0) {
args.fill = '#ff6347';
}
else {
args.fill = '#009cb8';
}
}
}, '#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://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'>
<div id='element'></div>
</div>
</body>
</html>
export let scatterData: Object[] = [
{ x: 1, y: 15 },
{ x: 2, y: 25 },
{ x: 3, y: 35 },
{ x: 4, y: 45 },
{ x: 5, y: 55 },
{ x: 6, y: 60 },
{ x: 7, y: 65 },
{ x: 8, y: 70 },
{ x: 9, y: 75 },
{ x: 10, y: 80 },
{ x: 11, y: 85 },
{ x: 12, y: 90 },
{ x: 13, y: 92 },
{ x: 14, y: 94 },
{ x: 15, y: 96 },
{ x: 16, y: 97 },
{ x: 17, y: 98 },
{ x: 18, y: 99 },
{ x: 19, y: 100 },
{ x: 20, y: 100 }
];