Back to Devexpress

Empty Points

aspnet-15959-components-chart-control-concepts-creating-charts-data-representation-empty-points.md

latest13.0 KB
Original Source

Empty Points

  • Oct 14, 2021
  • 8 minutes to read

Empty points are points with undefined Values. This document describes how the Chart Control processes empty points.

Run Demo: Empty Points

The Chart displays empty points as breaks in the Line or Area series views, and missing points or bars in other series view types.

Line View

Spline Area View

Bar View

Point View

The following table contains data for the charts above:

DatePoliticsEntertainmentTravel
01-Nov-16655645
02-Nov-16784540
03-Nov-16957056
04-Nov-161108247
05-Nov-161088038
06-Nov-16522031
07-Nov-16461027
08-Nov-167027
09-Nov-168642
10-Nov-169265
11-Nov-161084537
12-Nov-161155621
13-Nov-16751010
14-Nov-166505

To create an empty point, execute one of the following actions:

The Chart Control does not display series labels, tooltips, and the crosshair cursor label for empty points.

You can use the SeriesPoint.IsEmpty property to check whether a point is empty.

Missing points (that is the case when the data source contains missing records in arguments and points are not created) are handled as empty points if the ScaleOptionsBase.ProcessMissingPoints property is set to InsertEmptyPoints.

Tip

Define How to Handle Empty Points

Use a series view’s EmptyPointOptions property to access empty point settings. Specify the EmptyPointOptions.ProcessPoints property to select the manner in which the chart control should handle empty points.

For example, use the following code to display points with predicted values instead of empty points.

csharp
using DevExpress.XtraCharts;
using System;
using System.Collections.Generic;
using System.Drawing;
namespace SampleChart {
    public partial class WebForm1 : System.Web.UI.Page {
        protected void Page_Load(object sender, EventArgs e) {
            chartControl.DataSource = WeatherDataProvider.Data;
            Series series = new Series("Wind", ViewType.Bar);
            series.SetDataMembers("Date", "Wind");
            series.LabelsVisibility = DevExpress.Utils.DefaultBoolean.True;
            chartControl.Series.Add(series);
            chartControl.DataBind();

            BarSeriesView view = (BarSeriesView)series.View;
            view.EmptyPointOptions.ProcessPoints = ProcessEmptyPointsMode.Interpolate;
            view.EmptyPointOptions.Color = Color.FromArgb(80, 80, 80, 80);
        }
    }
    public static class WeatherDataProvider {
        static List<WeatherPoint> data;

        public static List<WeatherPoint> Data {
            get {
                if (data == null)
                    InitCollection();
                return data;
            }
        }
        static void InitCollection() {
            data = new List<WeatherPoint>();
            int lastYear = DateTime.Now.Year - 1;
            data.Add(new WeatherPoint() { Date = new DateTime(lastYear, 7, 11), Wind = 5 });
            data.Add(new WeatherPoint() { Date = new DateTime(lastYear, 7, 12), Wind = 5 });
            data.Add(new WeatherPoint() { Date = new DateTime(lastYear, 7, 13), Wind = 6 });
            data.Add(new WeatherPoint() { Date = new DateTime(lastYear, 7, 14), Wind = 3 });
            data.Add(new WeatherPoint() { Date = new DateTime(lastYear, 7, 15) });
            // ...
            // Other points.
            // ...
        }
        public class WeatherPoint {
            public DateTime Date { get; set; }
            public double? Wind { get; set; }
        }
    }
}
vb
Imports DevExpress.XtraCharts
Imports System
Imports System.Collections.Generic
Imports System.Drawing

Namespace SampleChart
    Public Partial Class WebForm1
        Inherits Web.UI.Page

        Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
            chartControl.DataSource = Data
            Dim series As Series = New Series("Wind", ViewType.Bar)
            series.SetDataMembers("Date", "Wind")
            series.LabelsVisibility = DevExpress.Utils.DefaultBoolean.[True]
            chartControl.Series.Add(series)
            chartControl.DataBind()
            Dim view As BarSeriesView = CType(series.View, BarSeriesView)
            view.EmptyPointOptions.ProcessPoints = ProcessEmptyPointsMode.Interpolate
            view.EmptyPointOptions.Color = Color.FromArgb(80, 80, 80, 80)
        End Sub
    End Class

    Public Module WeatherDataProvider
        Private dataField As List(Of WeatherPoint)

        Public ReadOnly Property Data As List(Of WeatherPoint)
            Get
                If dataField Is Nothing Then Call InitCollection()
                Return dataField
            End Get
        End Property

        Private Sub InitCollection()
            dataField = New List(Of WeatherPoint)()
            Dim lastYear As Integer = Date.Now.Year - 1
            Call dataField.Add(New WeatherPoint() With {
                .[Date] = New DateTime(lastYear, 7, 11),
                .Wind = 5
            })
            Call dataField.Add(New WeatherPoint() With {
                .[Date] = New DateTime(lastYear, 7, 12),
                .Wind = 5
            })
            Call dataField.Add(New WeatherPoint() With {
                .[Date] = New DateTime(lastYear, 7, 13),
                .Wind = 6
            })
            Call dataField.Add(New WeatherPoint() With {
                .[Date] = New DateTime(lastYear, 7, 14),
                .Wind = 3
            })
            Call dataField.Add(New WeatherPoint() With {
                .[Date] = New DateTime(lastYear, 7, 15)
            })
            ' ...
            ' Other points.
            ' ...
        End Sub

        Public Class WeatherPoint
            Public Property [Date] As Date
            Public Property Wind As Double?
        End Class
    End Module
End Namespace

Customize Appearance of Empty Points

Appearance settings of empty points depends on the series view type. Depending on the view, cast the EmptyPointOptions property value to one of the following classes and configure empty point appearance settings:

The example below configures empty point appearance for line, area, and bar series views. Empty points are painted gray:

csharp
LineSeriesView view1 = (LineSeriesView)series1.View;
view1.MarkerVisibility = DevExpress.Utils.DefaultBoolean.True;
LineEmptyPointOptions lineEmptyPointOptions = view1.EmptyPointOptions;
lineEmptyPointOptions.ProcessPoints = ProcessEmptyPointsMode.Interpolate;
lineEmptyPointOptions.Color = Color.DarkGray;
lineEmptyPointOptions.LineStyle.DashStyle = DashStyle.Dash;
lineEmptyPointOptions.LineStyle.Thickness = 2;

AreaSeriesView view2 = (AreaSeriesView)series2.View;
AreaEmptyPointOptions areaEmptyPointOptions = view2.EmptyPointOptions;
areaEmptyPointOptions.ProcessPoints = ProcessEmptyPointsMode.Interpolate;
areaEmptyPointOptions.FillStyle.FillMode = FillMode.Solid;
areaEmptyPointOptions.Color = Color.DarkGray;
areaEmptyPointOptions.Border.Color = Color.Gray;
areaEmptyPointOptions.Border.Thickness = 2;

SideBySideBarSeriesView view3 = (SideBySideBarSeriesView)series3.View;
EmptyPointOptions emptyPointOptions = view3.EmptyPointOptions;
emptyPointOptions.ProcessPoints = ProcessEmptyPointsMode.Interpolate;
emptyPointOptions.Color = Color.FromArgb(100, Color.DarkGray);
vb
Dim view1 As LineSeriesView = CType(series1.View, LineSeriesView)
view1.MarkerVisibility = DevExpress.Utils.DefaultBoolean.True
Dim lineEmptyPointOptions As LineEmptyPointOptions = view1.EmptyPointOptions
lineEmptyPointOptions.ProcessPoints = ProcessEmptyPointsMode.Interpolate
lineEmptyPointOptions.Color = Color.DarkGray
lineEmptyPointOptions.LineStyle.DashStyle = DashStyle.Dash
lineEmptyPointOptions.LineStyle.Thickness = 2

Dim view2 As AreaSeriesView = CType(series2.View, AreaSeriesView)
Dim areaEmptyPointOptions As AreaEmptyPointOptions = view2.EmptyPointOptions
areaEmptyPointOptions.ProcessPoints = ProcessEmptyPointsMode.Interpolate
areaEmptyPointOptions.FillStyle.FillMode = FillMode.Solid
areaEmptyPointOptions.Color = Color.DarkGray
areaEmptyPointOptions.Border.Color = Color.Gray
areaEmptyPointOptions.Border.Thickness = 2

Dim view3 As SideBySideBarSeriesView = CType(series3.View, SideBySideBarSeriesView)
Dim emptyPointOptions As EmptyPointOptions = view3.EmptyPointOptions
emptyPointOptions.ProcessPoints = ProcessEmptyPointsMode.Interpolate
emptyPointOptions.Color = Color.FromArgb(100, Color.DarkGray)

Show Isolated Points

The Chart does not draw a point between two empty points. To display a point in this case, enable the ShowIsolatedPoints property.

ShowIsolatedPoints = trueShowIsolatedPoints = false
csharp
LineSeriesView view = chart.Series[0].View as LineSeriesView;
view.ShowIsolatedPoints = true;
vb
Dim view As LineSeriesView = TryCast(chart.Series(0).View, LineSeriesView)
view.ShowIsolatedPoints = True