简体   繁体   English

MSCharts PixelPositionToValue似乎不适用于对数x轴

[英]MSCharts PixelPositionToValue doesn't seem to work for logarithmic x-axis

I am using MSCharts, and have set the x-axis IsLogarithmic to true. 我正在使用MSCharts,并将x轴IsLogarithmic设置为true。 The first problem I had was that the chart crashed when it was first displayed. 我遇到的第一个问题是图表在首次显示时崩溃了。

I found answers at: 我在以下位置找到了答案:

http://social.msdn.microsoft.com/forums/en-us/MSWinWebChart/thread/33288389-0A46-4C01-8E36-761B7BE96F0D http://social.msdn.microsoft.com/forums/zh-CN/MSWinWebChart/thread/33288389-0A46-4C01-8E36-761B7BE96F0D

and

http://social.msdn.microsoft.com/Forums/en/MSWinWebChart/thread/056aa11f-658c-48fa-9768-cde912cd2975 http://social.msdn.microsoft.com/Forums/zh-CN/MSWinWebChart/thread/056aa11f-658c-48fa-9768-cde912cd2975

So I don't set isLogarithmic at design time, I do it at runtime when I have a series with: 因此,我没有在设计时设置isLogarithmic,而是在运行时执行以下操作:

  • X-values specified with no x values <= 0 指定的x值,没有x值<= 0
  • Series.IsXValueIndexed = false Series.IsXValueIndexed = false
  • AxisX.IsStartedFromZero = false AxisX.IsStartedFromZero = false

However, I have a problem when trying to drag some points on the graph. 但是,尝试在图形上拖动某些点时遇到问题。 The MS example code for dragging points uses the PixelPositionToValue function in the MouseMove event handler. 用于拖动点的MS示例代码在MouseMove事件处理程序中使用PixelPositionToValue函数。 However, when I try this with the log axis I have to convert the value myself back to linear with code like: 但是,当我在对数轴上尝试此操作时,必须使用以下代码将自身值转换回线性值:

int GetXValue(MouseEventArgs e, Axis axis)
{
 return axis.IsLogarithmic ?
   Math.Pow(axis.LogarithmBase, axis.PixelPositionToValue(e.X)) :
   axis.PixelPositionToValue(e.X)
}

I don't think I should really have to do this, and worse, sometimes PixelPositionToValue does seem to convert the value to linear for me, so the function above gives inconsistent results. 我不认为我真的必须这样做,更糟糕的是,有时候PixelPositionToValue似乎确实将值转换为线性,因此上面的函数给出的结果不一致。

I noticed that the documentation for PixelPositionToValue says "Converts an absolute pixel position along an axis to an axis value. This method only works in paint events .", even though the MS example code for dragging points uses it in the Chart1_MouseMove event handler. 我注意到,PixelPositionToValue的文档说:“将沿轴的绝对像素位置转换为轴值。 此方法仅在绘制事件中有效 。”即使用于拖动点的MS示例代码在Chart1_MouseMove事件处理程序中也使用了该方法。

So, for probably very illogical reasons I tried calling Chart1.Refresh() after plotting my points (rather than Chart1.Invalidate() ) and the inconsistent behaviour seems to have gone away. 因此,出于非常不合逻辑的原因,我在绘制点(而不是Chart1.Invalidate() )后尝试调用Chart1.Refresh() ,并且不一致的行为似乎已经消失了。

My question is, has anyone tried a similar thing and found a proper way to get PixelPositionToValue to work consistently for a logarithmic x-axis, or found another workaround that doesn't require manually converting the point to linear and calling Chart1.Refresh() ? 我的问题是,有没有人尝试过类似的事情,并且找到了使PixelPositionToValue在对数x轴上一致工作的正确方法,或者找到了另一种不需要手动将点转换为线性并调用Chart1.Refresh()

I found the following articles: 我发现以下文章:

http://support2.dundas.com/newsletter/04-07/newsletter.htm http://support2.dundas.com/newsletter/04-07/newsletter.htm

http://support2.dundas.com/forum/tm.aspx?m=2786 http://support2.dundas.com/forum/tm.aspx?m=2786

http://support2.dundas.com/forum/tm.aspx?m=4616&mpage=1&key=ሴ http://support2.dundas.com/forum/tm.aspx?m=4616&mpage=1&key=ሴ

http://support2.dundas.com/forum/printable.aspx?m=3636 http://support2.dundas.com/forum/printable.aspx?m=3636

These indicate that for PixelPositionToValue to work outside of a paint event you need to call ReCalc() on the Chart area. 这些指示为使PixelPositionToValue在绘制事件之外工作,您需要在图表区域上调用ReCalc()。 ReCalc() doesn't exist on my version of MSChart, but there is a function RecalculateAxesScale() (see http://social.msdn.microsoft.com/Forums/en-US/MSWinWebChart/thread/da45b7df-8d2f-4598-b4ad-47964eb1505c/ ), and calling this seems to fix the inconsistent behaviour. ReCalc()在我的MSChart版本上不存在,但是有一个函数RecalculateAxesScale()(请参阅http://social.msdn.microsoft.com/Forums/en-US/MSWinWebChart/thread/da45b7df-8d2f-4598 -b4ad-47964eb1505c / ),然后调用它似乎可以解决不一致的行为。

Unfortunately I still need to convert the value to linear if the axis is logarithmic, but at least the behaviour is predictable now. 不幸的是,如果轴是对数的,我仍然需要将值转换为线性,但是至少现在行为是可以预测的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM