Back to Devexpress

SeriesPoint.Tag Property

corelibraries-devexpress-dot-xtracharts-dot-seriespoint-5b0eaa85.md

latest10.4 KB
Original Source

SeriesPoint.Tag Property

Gets or sets the object that contains data related to this series point.

Namespace : DevExpress.XtraCharts

Assembly : DevExpress.XtraCharts.v25.2.dll

NuGet Package : DevExpress.Charts

Declaration

csharp
public object Tag { get; set; }
vb
Public Property Tag As Object

Property Value

TypeDescription
Object

A Object that contains data about the series point.

|

Remarks

Any type derived from the Object class can be assigned to this property. Use it to store data associated with a particular series point.

Note

If a chart is bound to data, the Tag property is automatically assigned to the underlying object used to create this series point (e.g. to the corresponding DataRowView object, if a chart is bound to a DataTable ).

Example

This example demonstrates how to display custom information from the underlying data source in a crosshair cursor tooltip for every series point.

For this example to work correctly, do the following.

  1. Start MS Visual Studio.
  2. Create a new Windows Forms Application , or open an existing one.
  3. Drop the ChartControl onto the form.
  4. Add a single Bar Series to the chart, then bind it to the Products table from the nwind.mdb database (see Lesson 3 - Bind Chart Series to Data to learn how to do this).
  5. Set the series’ SeriesBase.ArgumentDataMember property to ProductName and its SeriesBase.ValueDataMembers .Value property to UnitPrice.
  6. Then handle the ChartControl.CustomDrawCrosshair event, as shown in the code below.
csharp
using System;
using System.Data;
using System.Windows.Forms;
using DevExpress.XtraCharts;

namespace CustomInfoInTooltips {
    public partial class Form1 : Form {
        public Form1() {
            InitializeComponent();
            }
        private void Form1_Load(object sender, EventArgs e) {
            // This line of code loads data into the 'nwindDataSet.Products' table. You can move, or remove it, as needed.
            this.productsTableAdapter.Fill(this.nwindDataSet.Products);
        }
        private void chartControl1_CustomDrawCrosshair(object sender, CustomDrawCrosshairEventArgs e) {
            foreach (CrosshairElementGroup group in e.CrosshairElementGroups) {
                foreach (CrosshairElement element in group.CrosshairElements) {
                    SeriesPoint currentPoint = element.SeriesPoint;
                    if (currentPoint.Tag.GetType() == typeof(DataRowView)) {
                        DataRowView rowView = (DataRowView)currentPoint.Tag;
                        string s = "Unit price = " + rowView["UnitPrice"].ToString() +
                            "\r\nUnits in stock = " + rowView["UnitsInStock"].ToString() +
                            "\r\nQuantity per unit = " + rowView["QuantityPerUnit"].ToString();
                        element.LabelElement.Text = s;
                    }
                }
            }
        }
    }
}
vb
Imports Microsoft.VisualBasic
Imports System
Imports System.Data
Imports System.Windows.Forms
Imports DevExpress.XtraCharts

Namespace CustomInfoInTooltips
    Partial Public Class Form1
        Inherits Form
        Public Sub New()
            InitializeComponent()
        End Sub
        Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load
            ' This line of code loads data into the 'nwindDataSet.Products' table. You can move, or remove it, as needed.
            Me.productsTableAdapter.Fill(Me.nwindDataSet.Products)
        End Sub
        Private Sub chartControl1_CustomDrawCrosshair(ByVal sender As Object, ByVal e As CustomDrawCrosshairEventArgs) Handles chartControl1.CustomDrawCrosshair
            For Each group As CrosshairElementGroup In e.CrosshairElementGroups
                For Each element As CrosshairElement In group.CrosshairElements
                    Dim currentPoint As SeriesPoint = element.SeriesPoint
                    If currentPoint.Tag.GetType() Is GetType(DataRowView) Then
                        Dim rowView As DataRowView = CType(currentPoint.Tag, DataRowView)
                        Dim s As String = "Unit price = " & rowView("UnitPrice").ToString() & Constants.vbCrLf & "Units in stock = " & rowView("UnitsInStock").ToString() & Constants.vbCrLf & "Quantity per unit = " & rowView("QuantityPerUnit").ToString()
                        element.LabelElement.Text = s
                    End If
                Next element
            Next group
        End Sub
    End Class
End Namespace

The following code snippets (auto-collected from DevExpress Examples) contain references to the Tag property.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

winforms-dashboard-custom-items/CS/TutorialsCustomItems/CustomItems/FunnelItemControlProvider.cs#L66

csharp
{
    DashboardFlatDataSourceRow row = e.SeriesPoint.Tag as DashboardFlatDataSourceRow;
    string formattedValue = flatData.GetDisplayText(dashboardItem.Metadata.Value.UniqueId, row);

winforms-dashboard-custom-items-extension/CS/CustomItemExtension/CustomItems/Funnel/FunnelItemControlProvider.cs#L61

csharp
void CustomDrawSeriesPoint(object sender, CustomDrawSeriesPointEventArgs e) {
    DashboardFlatDataSourceRow row = e.SeriesPoint.Tag as DashboardFlatDataSourceRow;
    string formattedValue = flatData.GetDisplayText(dashboardItem.Metadata.Value.UniqueId, row);

winforms-highlight-pivot-cells-that-correspond-to-a-series-point-on-hover/CS/WindowsApplication53/Form1.cs#L40

csharp
} else {
    PivotChartDataSourceRowItem coordinates = point.Tag as PivotChartDataSourceRowItem;

winforms-charts-create-a-side-by-side-stacked-bars/CS/SideBySideStackedBarChart/Form1.cs#L48

csharp
if (series.Points.Count > 0) {
    DataRowView row = series.Points[0].Tag as DataRowView;
    ((ISupportStackedGroup)series.View).StackedGroup = row["Group"];

winforms-dashboard-custom-items/VB/TutorialsCustomItems/CustomItems/FunnelItemControlProvider.vb#L66

vb
Private Sub CustomDrawSeriesPoint(ByVal sender As Object, ByVal e As CustomDrawSeriesPointEventArgs)
    Dim row As DashboardFlatDataSourceRow = TryCast(e.SeriesPoint.Tag, DashboardFlatDataSourceRow)
    Dim formattedValue As String = flatData.GetDisplayText(dashboardItem.Metadata.Value.UniqueId, row)

winforms-dashboard-custom-items-extension/VB/CustomItemExtension/CustomItems/Funnel/FunnelItemControlProvider.vb#L67

vb
Private Sub CustomDrawSeriesPoint(ByVal sender As Object, ByVal e As CustomDrawSeriesPointEventArgs)
    Dim row As DashboardFlatDataSourceRow = TryCast(e.SeriesPoint.Tag, DashboardFlatDataSourceRow)
    Dim formattedValue As String = flatData.GetDisplayText(dashboardItem.Metadata.Value.UniqueId, row)

winforms-highlight-pivot-cells-that-correspond-to-a-series-point-on-hover/VB/WindowsApplication53/Form1.vb#L46

vb
Else
    Dim coordinates As PivotChartDataSourceRowItem = TryCast(point.Tag, PivotChartDataSourceRowItem)
    InvalidateCell(pivotGridControl1, hotTrackPoint)

winforms-charts-create-a-side-by-side-stacked-bars/VB/SideBySideStackedBarChart/Form1.vb#L47

vb
If series.Points.Count > 0 Then
    Dim row As DataRowView = TryCast(series.Points(0).Tag, DataRowView)
    CType(series.View, ISupportStackedGroup).StackedGroup = row("Group")

See Also

SeriesPoint Class

SeriesPoint Members

DevExpress.XtraCharts Namespace