SeriesPoint.Tag Property

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

Namespace: DevExpress.XtraCharts

Assembly: DevExpress.XtraCharts.v20.1.dll

Declaration

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

Property Value

Type Description
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).

Examples

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.
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 (CrosshairElement element in e.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;

                    }
                }
            }
        }
    }
}
See Also