MSCharts PixelPositionToValue 似乎不适用于对数 x 轴
我正在使用 MSCharts,并将 x 轴 IsLogarithmic 设置为 true。我遇到的第一个问题是图表首次显示时崩溃了。
我在以下位置找到了答案:
和
所以我在设计时不设置 isLogarithmic,当我有一个系列时,我在运行时设置:
- X 值指定没有 x 值 <= 0
- Series.IsXValueIndexed = false
- AxisX。 IsStartedFromZero = false
但是,在尝试拖动图表上的某些点时遇到问题。用于拖动点的 MS 示例代码使用 MouseMove 事件处理程序中的 PixelPositionToValue 函数。但是,当我使用对数轴尝试此操作时,我必须使用以下代码将值自己转换回线性:
int GetXValue(MouseEventArgs e, Axis axis)
{
return axis.IsLogarithmic ?
Math.Pow(axis.LogarithmBase, axis.PixelPositionToValue(e.X)) :
axis.PixelPositionToValue(e.X)
}
我认为我实际上不必这样做,更糟糕的是,有时 PixelPositionToValue 似乎确实将值转换为线性对我来说,所以上面的函数给出了不一致的结果。
我注意到 PixelPositionToValue 的文档说“将沿轴的绝对像素位置转换为轴值。此方法仅适用于绘制事件。”,即使用于拖动点的 MS 示例代码使用它在 Chart1_MouseMove 事件处理程序中。
因此,出于可能非常不合逻辑的原因,我尝试在绘制我的点后调用 Chart1.Refresh()
(而不是 Chart1.Invalidate()
),并且不一致的行为似乎已经消失离开。
我的问题是,有没有人尝试过类似的事情并找到一种正确的方法来让 PixelPositionToValue 在对数 x 轴上一致工作,或者找到另一种解决方法,不需要手动将点转换为线性并调用 Chart1.刷新()?
I am using MSCharts, and have set the x-axis IsLogarithmic to true. The first problem I had was that the chart crashed when it was first displayed.
I found answers at:
and
http://social.msdn.microsoft.com/Forums/en/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:
- X-values specified with no x values <= 0
- Series.IsXValueIndexed = 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. 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.
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.
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.
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()
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我找到了以下文章:
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=4616&mpage=1&key=ሴ
http://support2.dundas.com/forum/printable.aspx?m=3636
这些表示 PixelPositionToValue 在绘制事件之外工作您需要在图表区域调用 ReCalc()。我的 MSChart 版本上不存在 ReCalc(),但有一个函数 RecalculateAxesScale() (请参阅 http://social.msdn.microsoft.com/Forums/en-US/MSWinWebChart/thread/da45b7df-8d2f-4598-b4ad-47964eb1505c/< /a>),调用它似乎可以修复不一致的行为。
不幸的是,如果轴是对数的,我仍然需要将值转换为线性,但至少现在的行为是可以预测的。
I found the following articles:
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=4616&mpage=1&key=ሴ
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. 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.
Unfortunately I still need to convert the value to linear if the axis is logarithmic, but at least the behaviour is predictable now.