- Scatter
- Binding data with series
- Series customization
- Empty points
- Events
- See Also
Contact Support
Scatter in ASP.NET CORE Charts Component
8 Oct 202424 minutes to read
Scatter
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
as Scatter in your chart configuration. This indicates that the data should be displayed as individual points scattered across the chart.
<ejs-chart id="container" load="window.onload">
<e-series-collection>
<e-series xName="x" yName="y" name="India" type="@Syncfusion.EJ2.Charts.ChartSeriesType.Scatter"></e-series>
<e-series xName="x" yName="y" name="India" type="@Syncfusion.EJ2.Charts.ChartSeriesType.Scatter"></e-series>
</e-series-collection>
</ejs-chart>
</div>
<script>
window.onload = function (args) {
var series1 = [];
var series2 = [];
var point1;
var value = 80;
var value1 = 70;
var i;
for (i = 1; i < 50; 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 < 50; 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);
}
args.chart.series[0].dataSource = series1;
args.chart.series[1].dataSource = series2;
}
</script>
public IActionResult Index(){
return View();
}
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.
<ejs-chart id="container" load="window.onload">
<e-series-collection>
<e-series xName="x" yName="y" name="India" type="@Syncfusion.EJ2.Charts.ChartSeriesType.Scatter"></e-series>
<e-series xName="x" yName="y" name="India" type="@Syncfusion.EJ2.Charts.ChartSeriesType.Scatter"></e-series>
</e-series-collection>
</ejs-chart>
</div>
<script>
window.onload = function (args) {
var series1 = [];
var series2 = [];
var point1;
var value = 80;
var value1 = 70;
var i;
for (i = 1; i < 50; 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 < 50; 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);
}
args.chart.series[0].dataSource = series1;
args.chart.series[1].dataSource = series2;
}
</script>
public IActionResult Index(){
return View();
}
Series customization
The following properties can be used to customize the scatter
series.
Fill
The fill
property determines the color applied to the series.
<ejs-chart id="container" load="window.onload">
<e-series-collection>
<e-series xName="x" yName="y" name="India" fill="red" type="@Syncfusion.EJ2.Charts.ChartSeriesType.Scatter"></e-series>
<e-series xName="x" yName="y" name="India" fill="blue" type="@Syncfusion.EJ2.Charts.ChartSeriesType.Scatter"></e-series>
</e-series-collection>
</ejs-chart>
<script>
window.onload = function (args) {
var series1 = [];
var series2 = [];
var point1;
var value = 80;
var value1 = 70;
var i;
for (i = 1; i < 50; 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 < 50; 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);
}
args.chart.series[0].dataSource = series1;
args.chart.series[1].dataSource = series2;
}
</script>
public IActionResult Index(){
return View();
}
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.
<ejs-chart id="container" load="window.onload">
<e-series-collection>
<e-series xName="x" yName="y" name="India" opacity="0.7" type="@Syncfusion.EJ2.Charts.ChartSeriesType.Scatter"></e-series>
<e-series xName="x" yName="y" name="India" opacity="0.5" type="@Syncfusion.EJ2.Charts.ChartSeriesType.Scatter"></e-series>
</e-series-collection>
</ejs-chart>
<script>
window.onload = function (args) {
var series1 = [];
var series2 = [];
var point1;
var value = 80;
var value1 = 70;
var i;
for (i = 1; i < 50; 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 < 50; 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);
}
args.chart.series[0].dataSource = series1;
args.chart.series[1].dataSource = series2;
}
</script>
public IActionResult Index(){
return View();
}
Shape
The shape
property allows you to customize the appearance of the markers by specifying different shapes.
<ejs-chart id="container" load="window.onload">
<e-series-collection>
<e-series xName="x" yName="y" name="India" type="@Syncfusion.EJ2.Charts.ChartSeriesType.Scatter">
<e-series-marker shape="Diamond" Height="7" Width="7"></e-series-marker>
</e-series>
<e-series xName="x" yName="y" name="India" type="@Syncfusion.EJ2.Charts.ChartSeriesType.Scatter">
<e-series-marker shape="Pentagon" Height="7" Width="7"></e-series-marker>
</e-series>
</e-series-collection>
</ejs-chart>
<script>
window.onload = function (args) {
var series1 = [];
var series2 = [];
var point1;
var value = 80;
var value1 = 70;
var i;
for (i = 1; i < 50; 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 < 50; 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);
}
args.chart.series[0].dataSource = series1;
args.chart.series[1].dataSource = series2;
}
</script>
public IActionResult Index(){
return View();
}
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.
<ejs-chart id="container">
<e-series-collection>
<e-series xName="x" yName="y" name="India" dataSource="ViewBag.dataSource" type="@Syncfusion.EJ2.Charts.ChartSeriesType.Scatter">
<e-series-marker shape="Diamond" Height="7" Width="7"></e-series-marker>
<e-series-emptypointsettings mode="Syncfusion.EJ2.Charts.EmptyPointMode.Zero"></e-series-emptypointsettings>
</e-series>
</e-series-collection>
</ejs-chart>
public ActionResult Index()
{
List<AxisLabelData> chartData = new List<AxisLabelData>
{
new AxisLabelData { x = 1, y = 15 },
new AxisLabelData { x = 2, y = 25 },
new AxisLabelData { x = 3, y = 35 },
new AxisLabelData { x = 4, y = null },
new AxisLabelData { x = 5, y = 55 },
new AxisLabelData { x = 6, y = 60 },
new AxisLabelData { x = 7, y = 65 },
new AxisLabelData { x = 8, y = 70 },
new AxisLabelData { x = 9, y = 75 },
new AxisLabelData { x = 10, y = 80 },
new AxisLabelData { x = 11, y = null },
new AxisLabelData { x = 12, y = 90 },
new AxisLabelData { x = 13, y = 92 },
new AxisLabelData { x = 14, y = 94 },
new AxisLabelData { x = 15, y = 96 },
new AxisLabelData { x = 16, y = null },
new AxisLabelData { x = 17, y = 98 },
new AxisLabelData { x = 18, y = 99 },
new AxisLabelData { x = 19, y = 100 },
new AxisLabelData { x = 20, y = 100 }
};
ViewBag.dataSource = chartData;
return View();
}
public class AxisLabelData
{
public double x;
public double? y;
}
Fill
Use the fill
property to customize the fill color of empty points in the series.
<ejs-chart id="container">
<e-series-collection>
<e-series xName="x" yName="y" name="India" dataSource="ViewBag.dataSource" type="@Syncfusion.EJ2.Charts.ChartSeriesType.Scatter">
<e-series-marker shape="Diamond" Height="7" Width="7"></e-series-marker>
<e-series-emptypointsettings mode="Syncfusion.EJ2.Charts.EmptyPointMode.Zero" fill="red"></e-series-emptypointsettings>
</e-series>
</e-series-collection>
</ejs-chart>
public ActionResult Index()
{
List<AxisLabelData> chartData = new List<AxisLabelData>
{
new AxisLabelData { x = 1, y = 15 },
new AxisLabelData { x = 2, y = 25 },
new AxisLabelData { x = 3, y = 35 },
new AxisLabelData { x = 4, y = null },
new AxisLabelData { x = 5, y = 55 },
new AxisLabelData { x = 6, y = 60 },
new AxisLabelData { x = 7, y = 65 },
new AxisLabelData { x = 8, y = 70 },
new AxisLabelData { x = 9, y = 75 },
new AxisLabelData { x = 10, y = 80 },
new AxisLabelData { x = 11, y = null },
new AxisLabelData { x = 12, y = 90 },
new AxisLabelData { x = 13, y = 92 },
new AxisLabelData { x = 14, y = 94 },
new AxisLabelData { x = 15, y = 96 },
new AxisLabelData { x = 16, y = null },
new AxisLabelData { x = 17, y = 98 },
new AxisLabelData { x = 18, y = 99 },
new AxisLabelData { x = 19, y = 100 },
new AxisLabelData { x = 20, y = 100 }
};
ViewBag.dataSource = chartData;
return View();
}
public class AxisLabelData
{
public double x;
public double? y;
}
Border
Use the border
property to customize the width and color of the border for empty points.
<ejs-chart id="container">
<e-series-collection>
<e-series xName="x" yName="y" name="India" dataSource="ViewBag.dataSource" type="@Syncfusion.EJ2.Charts.ChartSeriesType.Scatter">
<e-series-marker shape="Diamond" Height="7" Width="7"></e-series-marker>
<e-series-emptypointsettings mode="Syncfusion.EJ2.Charts.EmptyPointMode.Zero">
<e-emptypointsettings-border width="2" color="red"></e-emptypointsettings-border>
</e-series-emptypointsettings>
</e-series>
</e-series-collection>
</ejs-chart>
public ActionResult Index()
{
List<AxisLabelData> chartData = new List<AxisLabelData>
{
new AxisLabelData { x = 1, y = 15 },
new AxisLabelData { x = 2, y = 25 },
new AxisLabelData { x = 3, y = 35 },
new AxisLabelData { x = 4, y = null },
new AxisLabelData { x = 5, y = 55 },
new AxisLabelData { x = 6, y = 60 },
new AxisLabelData { x = 7, y = 65 },
new AxisLabelData { x = 8, y = 70 },
new AxisLabelData { x = 9, y = 75 },
new AxisLabelData { x = 10, y = 80 },
new AxisLabelData { x = 11, y = null },
new AxisLabelData { x = 12, y = 90 },
new AxisLabelData { x = 13, y = 92 },
new AxisLabelData { x = 14, y = 94 },
new AxisLabelData { x = 15, y = 96 },
new AxisLabelData { x = 16, y = null },
new AxisLabelData { x = 17, y = 98 },
new AxisLabelData { x = 18, y = 99 },
new AxisLabelData { x = 19, y = 100 },
new AxisLabelData { x = 20, y = 100 }
};
ViewBag.dataSource = chartData;
return View();
}
public class AxisLabelData
{
public double x;
public double? y;
}
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.
<ejs-chart id="container" seriesRender="changeColor">
<e-series-collection>
<e-series xName="x" yName="y" name="India" dataSource="ViewBag.dataSource" type="@Syncfusion.EJ2.Charts.ChartSeriesType.Scatter">
</e-series>
</e-series-collection>
</ejs-chart>
<script>
function changeColor(args) {
args.fill = "#ff6347";
}
</script>
public ActionResult Index()
{
List<AxisLabelData> chartData = new List<AxisLabelData>
{
new AxisLabelData { x = 1, y = 15 },
new AxisLabelData { x = 2, y = 25 },
new AxisLabelData { x = 3, y = 35 },
new AxisLabelData { x = 4, y = 40 },
new AxisLabelData { x = 5, y = 55 },
new AxisLabelData { x = 6, y = 60 },
new AxisLabelData { x = 7, y = 65 },
new AxisLabelData { x = 8, y = 70 },
new AxisLabelData { x = 9, y = 75 },
new AxisLabelData { x = 10, y = 80 },
new AxisLabelData { x = 11, y = 85 },
new AxisLabelData { x = 12, y = 90 },
new AxisLabelData { x = 13, y = 92 },
new AxisLabelData { x = 14, y = 94 },
new AxisLabelData { x = 15, y = 96 },
new AxisLabelData { x = 16, y = 30 },
new AxisLabelData { x = 17, y = 98 },
new AxisLabelData { x = 18, y = 99 },
new AxisLabelData { x = 19, y = 100 },
new AxisLabelData { x = 20, y = 100 }
};
ViewBag.dataSource = chartData;
return View();
}
public class AxisLabelData
{
public double x;
public double? y;
}
Point render
The pointRender
event allows you to customize each data point before it is rendered on the chart.
<ejs-chart id="container" pointRender="changeColor">
<e-series-collection>
<e-series xName="x" yName="y" name="India" dataSource="ViewBag.dataSource" type="@Syncfusion.EJ2.Charts.ChartSeriesType.Scatter">
<e-series-marker width="10" height="10"></e-series-marker>
</e-series>
</e-series-collection>
</ejs-chart>
<script>
function changeColor(args) {
if (args.point.index % 2 !== 0) {
args.fill = '#ff6347';
}
else {
args.fill = '#009cb8';
}
}
</script>
public ActionResult Index()
{
List<AxisLabelData> chartData = new List<AxisLabelData>
{
new AxisLabelData { x = 1, y = 15 },
new AxisLabelData { x = 2, y = 25 },
new AxisLabelData { x = 3, y = 35 },
new AxisLabelData { x = 4, y = 40 },
new AxisLabelData { x = 5, y = 55 },
new AxisLabelData { x = 6, y = 60 },
new AxisLabelData { x = 7, y = 65 },
new AxisLabelData { x = 8, y = 70 },
new AxisLabelData { x = 9, y = 75 },
new AxisLabelData { x = 10, y = 80 },
new AxisLabelData { x = 11, y = 85 },
new AxisLabelData { x = 12, y = 90 },
new AxisLabelData { x = 13, y = 92 },
new AxisLabelData { x = 14, y = 94 },
new AxisLabelData { x = 15, y = 96 },
new AxisLabelData { x = 16, y = 30 },
new AxisLabelData { x = 17, y = 98 },
new AxisLabelData { x = 18, y = 99 },
new AxisLabelData { x = 19, y = 100 },
new AxisLabelData { x = 20, y = 100 }
};
ViewBag.dataSource = chartData;
return View();
}
public class AxisLabelData
{
public double x;
public double? y;
}