Chart for .NET / User's Guide / Chart Types / One Value Series Functionality

In This Topic
    One Value Series Functionality
    In This Topic
    All series, which require one or more value data series are derived from the NSeries class. The NSeries class is derived from the NSeriesBase class and inherits all the basic series functionality. The NSeries class extend this functionality with the following features:
     Values data series

    A data series containing double values. It is accessible through the Values property of the NSeries object.

    The following code adds several values to the Values data series:

    C#
    Copy Code
    series.Values.Add(9.52);
    series.Values.Add(8);
    series.Values.Add(16.4);
    
    Visual Basic
    Copy Code
    series.Values.Add(9.52)
    series.Values.Add(8)
    series.Values.Add(16.4)
    
     Labels data series

    A data series containing string values. It is accessible through the Labels property of the NSeries object.

    The following code adds several strings to the Labels data series:

    C#
    Copy Code
    series.Labels.Add("Europe");
    series.Labels.Add("America");
    series.Labels.Add("Asia");
    
    Visual Basic
    Copy Code
    series.Labels.Add("Europe")
    series.Labels.Add("America")
    series.Labels.Add("Asia")
    
     Fill Styles

    The default fill style for the data items is controlled through the FillStyle property of the series. You can apply individual fill styles for particular data points with the help of the FillStyles property. It exposes a NIndexedAttributeSeries collection, in which you can add fill styles for specific data point indexes.

    The following code sets the default filling to solid red color. Only data point 2 will be filled with green color:

    C#
    Copy Code
    series.FillStyle = new NColorFillStyle(Color.Red);
    series.FillStyles[2] = new NColorFillStyle(Color.Green);
    
    Visual Basic
    Copy Code
    series.FillStyle = New NColorFillStyle(Color.Red)
    series.FillStyles(2) = New NColorFillStyle(Color.Green)
    
     Stroke Styles

    The default stroke style for the data item borders is controlled through the BorderStyle property of the series. You can apply individual stroke styles for particular data points with the help of the BorderStyles property. It exposes a NIndexedAttributeSeries collection, in which you can add stroke styles for specific data point indexes.

    The following code makes the default border red. Only the border of data point 2 will be green:

    C#
    Copy Code
    series.BorderStyle = new NStrokeStyle(Color.Red);
    series.BorderStyles[2] = new NStrokeStyle(Color.Green);
    
    Visual Basic
    Copy Code
    series.BorderStyle = New NStrokeStyle(Color.Red)
    series.BorderStyles(2) = New NStrokeStyle(Color.Green)
    
     Data Labels

    The default data label style for the data items is controlled through the DataLabelStyle property of the series. You can apply individual data label styles for particular data points with the help of the DataLabelStyles property. It exposes a NIndexedAttributeSeries collection, in which you can add data label styles for specific data point indexes. See the Data Labels topic for more information.

    The following code hides all the data labels except data label 2.

    C#
    Copy Code
    NDataLabelStyle dataLabel = new NDataLabelStyle();
    dataLabel.Visible = true;
    dataLabel.Format = "<value>";
    series.DataLabelStyle.Visible = false;
    series.DataLabelStyles[2] = dataLabel;
    
    Visual Basic
    Copy Code
    Dim dataLabel As NDataLabelStyle = New NDataLabelStyle
    dataLabel.Visible = True
    dataLabel.Format = "<value>"
    series.DataLabelStyle.Visible = False
    series.DataLabelStyles(2) = dataLabel
    
     Markers

    The default marker style for the data items is controlled through the MarkerStyle property of the series. You can apply individual marker styles for particular data points with the help of the MarkerStyles property. It exposes a NIndexedAttributeSeries collection, in which you can add marker styles for specific data point indexes. See the Markers topic for more information.

    The following code makes all markers to be circles, only marker 2 is set to rectangle.

    C#
    Copy Code
    NMarkerStyle marker = new NMarkerStyle();
    marker.Visible = true;
    marker.PointShape = PointShape.Bar;
    series.MarkerStyle.Visible = true;
    series.MarkerStyle.PointShape = PointShape.Ellipse;
    series.MarkerStyles[2] = marker;
    
    Visual Basic
    Copy Code
    Dim marker As NMarkerStyle = New NMarkerStyle
    marker.Visible = True
    marker.PointShape = PointShape.Bar
    
    series.MarkerStyle.Visible = True
    series.MarkerStyle.PointShape = PointShape.Ellipse
    series.MarkerStyles(2) = marker
    
     Interactivity

    The default interactivity style for the data items is controlled through the InteractivityStyle property of the series. You can apply individual interactivity styles for particular data points with the help of the InteractivityStyles property. It exposes a NIndexedAttributeSeries collection, in which you can add interactivity styles for specific data point indexes.

    The following code set a Hand cursor as default cursor. The cursor of data point 2 is set to IBeam.

    C#
    Copy Code
    NInteractivityStyle interactivity = new NInteractivityStyle();
    interactivity.Cursor.Type = CursorType.IBeam;
    series.InteractivityStyle.Cursor.Type = CursorType.Hand;
    series.InteractivityStyles[2] = interactivity;
    
    Visual Basic
    Copy Code
    Dim interactivity As NInteractivityStyle = New NInteractivityStyle
    interactivity.Cursor.Type = CursorType.IBeam
    series.InteractivityStyle.Cursor.Type = CursorType.Hand
    series.InteractivityStyles(2) = interactivity
    
     Tags
    You can attach custom objects to chart elements like series and data points. Use the Tag property to assign an object to the series. Use the Tags property to attach objects to particular data points. The Tags property exposes a NIndexedDataSeries collection, in which you can add custom objects at specific data point indexes.
     Formatting commands

    The texts that are displayed in the data labels and the legends can contain values that are obtained from the series data. The texts are defined with the help of format strings and are generated dynamically during rendering. Format strings consist of regular text and formatting commands. Formatting commands are tags that are placed within the format strings. When the texts are generated the formatting commands are replaced by actual values.

    The NSeries class implements support for the following formatting commands:

    <value> - the current data point value (extracted from the Values data series)
    <label> - the current data point label (extracted from the Labels data series)
    <total> - represents the total sum of the values contained in the Values series
    <percent> - represents the percentage of the current data point value to the total value
    <cumulative> - represents the cumulative sum accumulated up to this data point
    <index> - represents the index of the current data point

    Format strings are specified through the Format properties of the NDataLabelStyle and NSeriesLegend objects.

    For example if you want to display the value and label of a bar data point in its data label you will have to write the following code:

    C#
    Copy Code
    series.DataLabelStyle.Format = "<value> <label>";
    
    Visual Basic
    Copy Code
    series.DataLabelStyle.Format = "<value> <label>"
    

    Similarly you can instruct a legend to show the percent and total in the legend texts with the following code:

    C#
    Copy Code
    series.Legend.Format = "<percent> <total>";
    
    Visual Basic
    Copy Code
    series.Legend.Format = "<percent> <total>"
    
     Data Point Origin Index

    The series object has a property called DataPointOriginIndex, which allows you to specify which index in the storage is considered the first one. The default value of this property is 0. The DataPointOriginIndex property is useful when you create a series that by design has a predefined maximum number of data points. For example consider a line chart that displays the value of a real time measurment. In this case you need to limit the number of displayed previous measurements as otherwise the chart will accumulate a lot of data points. Typically the code to do is as follows:

    C#
    Copy Code
    someSeries.Values.Add(newValue);
    if (someSeries.Values.Count > maxCount)
    {
    someSeries.Values.RemoveAt(0);
    }

    The problem with this code is that it results in a memory shift, which is computationally expensive.

    In such cases when you add new data point(s) you can use the DataPointOriginIndex property:

    C#
    Copy Code
    if (someSeries.Values.Count < maxCount)
    {
    someSeries.Values.Add(newValue);
    }
    else
    { // store the new value
    someSeries.Values[someSeries.DataPointOriginIndex] = newValue;

    // shift the origin
    someSeries.DataPointOriginIndex++;

    // if the orgin exceeds the maximum number go back to the beginning
    if (someSeries.DataPointOriginIndex >= maxCount)
    {
    someSeries.DataPointOriginIndex = 0;
    }
    }
    This code does not result in memory shift and is therefore more efficient.
    See Also