c# - 在 LineSeries WinForms 图表中显示工具提示?

标签 c# winforms mschart

我正在开发一个仪表板系统,我在其中使用 WinForms 中的折线图。我需要在每一行显示工具提示。我试过这个

var series = new Series
                    {
                        Name = chartPoint.SetName,
                        Color = chartPoint.ChartColor,
                        ChartType = SeriesChartType.Line,
                        BorderDashStyle = chartPoint.ChartDashStyle,
                        BorderWidth = chartPoint.BorderWidth,
                        IsVisibleInLegend = !chartPoint.HideLegend,
                        ToolTip = "Hello World"
                    };

但它对我不起作用

最佳答案

您有两个选择,要么使用图表控件接受的关键字

myChart.Series[0].ToolTip = "Name #SERIESNAME : X - #VALX{F2} , Y - #VALY{F2}";

Chart 控件中,Keyword 是一个字符序列,在运行时被自动计算的值替换。有关图表控件接受的关键字的完整列表,请查找 Keyword reference

如果你想要更奇特的东西,你必须处理事件 GetToolTipText

this.myChart.GetToolTipText += new System.Windows.Forms.DataVisualization.Charting.Chart.ToolTipEventHandler(this.myChart_GetToolTipText);

现在我不确定您想在工具提示上显示什么,但您可以相应地添加逻辑。假设您要显示系列中 DataPoints 的值

private void myChart_GetToolTipText(object sender, System.Windows.Forms.DataVisualization.Charting.ToolTipEventArgs e)
{
    switch(e.HitTestResult.ChartElementType)
    {  
        case ChartElementType.DataPoint:
            e.Text = myChart.Series[0].Points[e.HitTestResult.PointIndex]).ToString()
                     + /* something for which no keyword exists */;
            break;
        case ChartElementType.Axis:
            // add logic here
        case ....
        .
        .    
        default:
            // do nothing       
    }

关于c# - 在 LineSeries WinForms 图表中显示工具提示?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17962754/

相关文章:

c# - 反向 Convert.ToBase64String(byte[] 数组)

c# - 计算通过所有点的曲线

c# - 模态对话框弹出后开始漫长的过程

c# - ASP.Net C# - 在图表中设置和显示 x 轴值

c# - 用于 MS 图表控件的鼠标滚轮滚动事件

c# - 如何对 .FindAll() 的结果执行操作

c# - 从 C# : Of structs, 字符串和 wchar_t 数组调用 C++ dll 函数

c# - Form.TopMost 有时有效

c# - 在 ListView 中更改列标题的字体样式和颜色

c# - 如何在图表底部放置标签