在C#图表点中显示值 [英] Show values in C# Chart Points

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

问题描述

大家好!



问题是当我用光标线在它上面时,是否可以显示c#图表的一个点的值。



例如:



https://www.dropbox.com/s/ruynlkah2n259id/cursor%201.png [ ^ ]



这一点在53%的比例,但我不知道他的真实价值(如果,例如从0到999)。



先谢谢你。





问候。

解决方案

好吧,如果比例已知,那么很容易计算点实际值,例如

53% on 0-999 scale is 529 int((999-0)/ 100 * 53))。


感谢CPallini,解决方案在坐标中。我发现了这个,如果它对其他人有用。



问候!

------------- -------------------------------------------------- -------------------------------------



<前lang =cs>点? prevPosition = null ;
ToolTip tooltip = new ToolTip();

void chart1_MouseMove( object sender,MouseEventArgs e)
{
var pos = e.Location;
if (prevPosition.HasValue&& pos == prevPosition.Value)
return < /跨度>;
tooltip.RemoveAll();
prevPosition = pos;
var results = chart1.HitTest(pos.X,pos.Y, false
ChartElementType.DataPoint);
foreach var 结果 in 结果)
{
if (result.ChartElementType == ChartElementType.DataPoint)
{
var prop = result。 Object as DataPoint;
if (prop!= null
{
var pointXPixel = result.ChartArea.AxisX.ValueToPixelPosition(prop.XValue);
var pointYPixel = result.ChartArea.AxisY.ValueToPixelPosition(prop.YValues [ 0 ]) ;

// 检查光标是否真的靠近点(点周围2个像素) )
if (Math.Abs​​(pos.X - pointXPixel)< 2 &&
Math.Abs​​(pos.Y - pointYPixel)< 2
{
tooltip.Show( X = + prop.XValue + ,Y = + prop.YValues [ 0 ], this .chart1,
pos.X,pos.Y - 15 );
}
}
}
}
}


Hello everyone!

The question is if it's possible to show a point's value of a c# chart when i'm with the cursor line over it.

For example this:

https://www.dropbox.com/s/ruynlkah2n259id/cursor%201.png[^]

This point is on the 53% of the scale but i don't know his real value(if, for example was from 0 to 999).

Thanks beforehead.


Regards.

解决方案

Well, if scale is known, then it is very easy to compute the point actual value, e.g.
53% on 0-999 scale is 529 (int((999-0)/100*53)).


Thanks CPallini, the solution was in the coordinates. I found this, if it's useful for anyone else.

Regards!
----------------------------------------------------------------------------------------------------

Point? prevPosition = null;
ToolTip tooltip = new ToolTip();

void chart1_MouseMove(object sender, MouseEventArgs e)
{
    var pos = e.Location;
    if (prevPosition.HasValue && pos == prevPosition.Value)
        return;
    tooltip.RemoveAll();
    prevPosition = pos;
    var results = chart1.HitTest(pos.X, pos.Y, false,
                                    ChartElementType.DataPoint);
    foreach (var result in results)
    {
        if (result.ChartElementType == ChartElementType.DataPoint)
        {
            var prop = result.Object as DataPoint;
            if (prop != null)
            {
                var pointXPixel = result.ChartArea.AxisX.ValueToPixelPosition(prop.XValue);
                var pointYPixel = result.ChartArea.AxisY.ValueToPixelPosition(prop.YValues[0]);

                // check if the cursor is really close to the point (2 pixels around the point)
                if (Math.Abs(pos.X - pointXPixel) < 2 &&
                    Math.Abs(pos.Y - pointYPixel) < 2)
                {
                    tooltip.Show("X=" + prop.XValue + ", Y=" + prop.YValues[0], this.chart1,
                                    pos.X, pos.Y - 15);
                }
            }
        }
    }
}


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

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