提示使用C#显示在图表上的任何一点价值系列 [英] Show series value over any point on chart using tooltip c#

查看:237
本文介绍了提示使用C#显示在图表上的任何一点价值系列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我见过很多例子使用提示鼠标悬停在数据点时显示图表数据,但我希望以显示值时,我的鼠标是简单地在图表,而不一定在一个特定的数据点(即空白其他地方)。我也希望最终拥有对数据点本身的小圆圈或方形但可以晚一点。谁能告诉我如何做到这一点?我将在下面包括我当前的代码。

So I've seen lots of examples on using tooltip to show chart data when hovering over a data point, but I was hoping to show the values when my mouse is simply over the chart and not necessarily over a particular data point (i.e. the whitespace everywhere else). I would also eventually like to have a small circle or square on the data point itself but that can come later. Can anyone tell me how to do this? I will include my current code below.

 private void chData_MouseMove(object sender, MouseEventArgs e)
    {            
        HitTestResult pos = chData.HitTest(e.X, e.Y);
        if (pos.ChartElementType == ChartElementType.DataPoint)
        {
            string tipInfo;
            tipInfo = "Bat 1: " + ch1Array[pos.PointIndex].ToString("0.00") + Environment.NewLine + "Bat 2: " + ch2Array[pos.PointIndex].ToString("0.00") + Environment.NewLine;                
            tooltip.SetToolTip(chData, tipInfo);    
        }

    }



我要猜我必须改变if语句的说法,但我不知道是什么。

任何帮助是非常感谢!

I'm going to guess I have to change the if statement argument but I'm not sure to what.
Any help is greatly appreciated!

推荐答案

所以,解决办法是不使用的HitTest。相反,如果你使用它PixelPositionToValue的效果要好得多。我会包括下面的代码。

So the solution was to not use a HitTest. Instead if you use PixelPositionToValue it works much better. I'll include the code below.

private void chData_MouseMove(object sender, MouseEventArgs e)
    {
        try
        {   
            int cursorX = Convert.ToInt32(chData.ChartAreas[0].AxisX.PixelPositionToValue(e.Location.X));

            tipInfo = "Bat 1: " + ch1Array[cursorX].ToString("0.00") + Environment.NewLine + "Bat 2: " + ch2Array[cursorX].ToString("0.00") + Environment.NewLine;

            tooltip.SetToolTip(chData, tipInfo);

        }
        catch { }
    }

这篇关于提示使用C#显示在图表上的任何一点价值系列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆