CodeCentralShow Me

在 DevExpress Code Central 数据库中可以找到完整的示例项目,网址是 http://www.devexpress.com/example=E2483。 取决于目标平台类型 (ASP.NET、WinForms 等),可以在线运行本示例,或者下载自动可执行的示例。

这个示例展示了如何使图表只为热跟踪点显示 系列点标签

为了完成此任务,在 ChartControl.CustomDrawSeriesPoint 事件处理程序中,把一个空字符串指派到每个系列点的 CustomDrawSeriesPointEventArgs.LabelText 属性。 然后,把点的取值指派到 ChartControl.ObjectHotTracked 事件处理程序中获得的热跟踪点。

C#CopyCode image复制代码
 (Form1.cs)
using System;
using System.Windows.Forms;
using DevExpress.XtraCharts;
// ...

SeriesPoint m_HotTrackedPoint;

void chartControl1_ObjectHotTracked(object sender, HotTrackEventArgs e) {
    SeriesPoint point = e.AdditionalObject as SeriesPoint;
    if (!Object.ReferenceEquals(point, m_HotTrackedPoint)) {
        m_HotTrackedPoint = point;
        chartControl1.Refresh();
    }
}

void chartControl1_CustomDrawSeriesPoint(object sender, CustomDrawSeriesPointEventArgs e) {
    e.LabelText = "";
    if (e.SeriesPoint == m_HotTrackedPoint) {
        e.LabelText = e.SeriesPoint.Values[0].ToString();
    }
}
Visual BasicCopyCode image复制代码
 (Form1.vb)
Imports System
Imports System.Windows.Forms
Imports DevExpress.XtraCharts
' ...

Private m_HotTrackedPoint As SeriesPoint

Private Sub chartControl1_ObjectHotTracked(ByVal sender As Object, _ 
ByVal e As HotTrackEventArgs) Handles chartControl1.ObjectHotTracked
    Dim point As SeriesPoint = TryCast(e.AdditionalObject, SeriesPoint)
    If (Not Object.ReferenceEquals(point, m_HotTrackedPoint)) Then
        m_HotTrackedPoint = point
        chartControl1.Refresh()
    End If
End Sub

Private Sub chartControl1_CustomDrawSeriesPoint(ByVal sender As Object, _ 
ByVal e As CustomDrawSeriesPointEventArgs) Handles chartControl1.CustomDrawSeriesPoint
    e.LabelText = ""
    If e.SeriesPoint Is m_HotTrackedPoint Then
        e.LabelText = e.SeriesPoint.Values(0).ToString()
    End If
End Sub

在下面的插图中显示了结果。

Expand image参阅