MS图表注释拒绝对准鼠标位置 [英] MS Charting Annotations refuse to align to mouse position

查看:209
本文介绍了MS图表注释拒绝对准鼠标位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谁能告诉我,为什么下面的发生吗?红线表示,其中标注的的(沿X轴)进行定位,但它永远是正确的呈现在左边......我没有在谷歌的几个搜索和SO,并找到答案哪些意味着 PixelPositionToValue(Mouse.X)将对其进行排序,但即使使用此正是它结束了一样。

 私人小组AssignNewDownTime()
    昏暗SSTR作为字符串=输入框(请输入停机的原因)
    昏暗ANNOT作为新Charting.RectangleAnnotation()    annot.ClipToChartArea =Chart1
    annot.BackColor = Color.DarkRed
    annot.ForeColor = Color.White
    annot.AllowMoving = TRUE
    annot.AllowAnchorMoving =假
    annot.AllowSelecting =假
    annot.IsMultiline =假
    annot.AllowTextEditing =假
    annot.IsSizeAlwaysRelative =假
    annot.X = Chart1.ChartAreas(0).AxisX.PixelPositionToValue(StartMousePoint.X)
    annot.Y = 10
    annot.Width = 25    annot.Text = SSTR&安培; / X:与& annot.X&安培; Y:&放大器; annot.Y    Chart1.Annotations.Add(ANNOT)
    Chart1.Invalidate()
结束小组


解决方案

尔加!这总是发生......我拉我的头发了几个小时,岗上SO,5分钟我已经固定它之内。总之,为子孙后代也可以拉自己的头发了,这里的解决方案:

注解X和Y不设置为图表,因此而图表将范围从0.0到1.0,注释默认范围为0到100的噩梦!有一对夫妇的办法解决这个,我选择了:

annot.AxisX = Chart1.ChartAreas(0).AxisX

这台标注的X轴,以模仿您的图表。因此,价值观和限制是正确的。当我这样做,它的工作瞬间。当然你也可以设置注释的AxisY为好,但要注意,在图表的Y是底部到顶部。更多信息可以在这里找到:<一href=\"http://msdn.microsoft.com/en-us/library/system.windows.forms.datavisualization.charting.annotation(v=vs.110).aspx\" rel=\"nofollow\">http://msdn.microsoft.com/en-us/library/system.windows.forms.datavisualization.charting.annotation(v=vs.110).aspx - 特别是(我的希望我读到第一... ...):


  

注释通常用于评论或阐述图表元素,如数据点。注释也可以用来绘制自定义形状。
  默认情况下,注释是使用位于相对坐标,用(0,0)再presenting的左上角,和(100,100)再presenting图表图像的右下角。另外,也可以从该相对坐标系统切换到使用轴的值的系统。与轴坐标系中,X和Y,从而重新present注释的左上角的位置,使用X轴和Y轴的值集,代替从0到100的范围内的值。
  有两种方法使用轴值当您指定注释的位置和大小:
  设置这些注释属性为ChartArea对象的AxisX和AxisY属性值的AxisX,AxisY或两者兼而有之。
  使用AnchorDataPoint属性来注释锚固到一个数据点。在这种情况下,它的定位是自动计算的。
  所有注释从注释类,它可以用来共同属性设置为所有注释的对象,如颜色,位置导出,锚固等等。


不管怎样,希望这有助于民间出去。

Can anyone tell me why the below is happening please? The red line signifies where the annotation should be positioned (along X axis), but it's always rendered right on the left edge... I did a few searches in Google and SO, and found an answer which implies that PixelPositionToValue(Mouse.X) would sort it, but even using this it ends up exactly the same.

Private Sub AssignNewDownTime()
    Dim sStr As String = InputBox("Please enter downtime reason")
    Dim annot As New Charting.RectangleAnnotation()

    annot.ClipToChartArea = "Chart1"
    annot.BackColor = Color.DarkRed
    annot.ForeColor = Color.White
    annot.AllowMoving = True
    annot.AllowAnchorMoving = False
    annot.AllowSelecting = False
    annot.IsMultiline = False
    annot.AllowTextEditing = False
    annot.IsSizeAlwaysRelative = False
    annot.X = Chart1.ChartAreas(0).AxisX.PixelPositionToValue(StartMousePoint.X)
    annot.Y = 10
    annot.Width = 25

    annot.Text = sStr & " /X: " & annot.X & "Y:" & annot.Y

    Chart1.Annotations.Add(annot)
    Chart1.Invalidate()
End Sub

解决方案

Gah! This always happens... I pull my hair out for hours, post on SO and within 5 minutes I've fixed it. Anyway, for future generations that may also pull their hair out, here's the solution:

Annotations X and Y aren't set to that of the chart, so whereas the chart will range from 0.0 to 1.0, annotations default range is 0 to 100. Nightmare! There are a couple of ways around this, I chose:

annot.AxisX = Chart1.ChartAreas(0).AxisX

Which sets the X axis of the annotation to mimic that of your chart. Thus the values and limits will be correct. As soon as I did this it worked instantly. You can of course set the AxisY of the annotation as well, but beware that in charting the Y is bottom to top. More information can be found here: http://msdn.microsoft.com/en-us/library/system.windows.forms.datavisualization.charting.annotation(v=vs.110).aspx - specifically (which I wish I'd read first...):

Annotations are commonly used to comment or elaborate on chart elements such as data points. Annotations can also be used to draw custom shapes. By default, annotations are positioned using relative coordinates, with (0,0) representing the top-left corner, and (100,100) representing the bottom-right corner of the chart image. It is also possible to switch from this relative coordinate system to a system that uses axis values. With an axis coordinate system, X and Y, which represent the position of the top-left corner of an annotation, are set using X axis and Y axis values, instead of values that range from 0-100. There are two ways to use axis values when you specify the position and size of an annotation: Set the AxisX, AxisY or both of these annotation properties to the AxisX and AxisY property values of a ChartArea object. Use the AnchorDataPoint property to anchor the annotation to a data point. In this case, its positioning is automatically calculated. All annotations are derived from the Annotation class, which can be used to set attributes common to all Annotation objects, such as color, position, anchoring and so forth.

Anyway, hope this helps folk out.

这篇关于MS图表注释拒绝对准鼠标位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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