我确定这个问题有一个我不知道的简单解决方案,但是我还是要问。我有以下代码:
HorizontalLineAnnotation h = new HorizontalLineAnnotation();
h.AnchorX = startOfNewGraph;
h.Width = newGraphWidth;
h.AxisX = resultGraph.ChartAreas[0].AxisX;
h.AxisY = resultGraph.ChartAreas[0].AxisY;
h.IsSizeAlwaysRelative = false;
h.ClipToChartArea = resultGraph.ChartAreas[0].Name;
originalHLAAnchors.Add(h.AnchorX);
originalHLAWidths.Add(h.Width);
resultGraph.Annotations.Add(h);
我的问题是,当我的图形视图缩放到其AnchorX在视图外部时,注释会消失。我想继续使用它,以便即使注释的两端都没有出现在视图中,我仍然可以看到它们之间的线。这是我尝试解决的方法:
private void resultGraph_AxisViewChanged(object sender, ViewEventArgs e)
{
if (e.Axis == resultGraph.ChartAreas[0].AxisX)
{
ResizeHorizontalAnnotations();
}
}
private void ResizeHorizontalAnnotations()
{
int count = 0;
for (int i = 0; i < resultGraph.Annotations.Count; i++)
{
if (resultGraph.Annotations[i] is HorizontalLineAnnotation)
{
if (originalHLAAnchors[count] < resultGraph.ChartAreas[0].AxisX.ScaleView.ViewMinimum)
{
resultGraph.Annotations[i].AnchorX = resultGraph.ChartAreas[0].AxisX.ScaleView.ViewMinimum + 0.0005;
if ((originalHLAAnchors[count] + originalHLAWidths[count]) >= resultGraph.ChartAreas[0].AxisX.ScaleView.ViewMaximum)
{
resultGraph.Annotations[i].Width = resultGraph.ChartAreas[0].AxisX.ScaleView.ViewMaximum - resultGraph.ChartAreas[0].AxisX.ScaleView.ViewMinimum;
}
else
{
resultGraph.Annotations[i].Width -= resultGraph.ChartAreas[0].AxisX.ScaleView.ViewMinimum - originalHLAAnchors[count];
}
}
else
{
resultGraph.Annotations[i].AnchorX = originalHLAAnchors[count];
resultGraph.Annotations[i].Width = originalHLAWidths[count];
}
resultGraph.Annotations[i].Visible = true;
count++;
}
}
resultGraph.UpdateAnnotations();
}
但是,此代码似乎也不起作用。第一次尝试时未显示注释,因此我在AnchorX中添加了0.005,以查看它是否必须超出视图最小值。这也不起作用。当我检查注释的本地值时,数字是正确的。批注只是无法正确显示或根本没有显示。UpdateAnnotations()缩小视图并禁用我的注释。
有任何想法吗?
看起来像是通过属性Annotations
直接将其锚定到某个位置,或者一旦该锚不再位于视标中,则AnchorX
通过使用AnchorDataPoint
消失将其锚定到某个位置。
不确定这是错误还是功能,但是您可以通过直接设置位置来解决。
因此,您应该使用h.Width
和h.X
属性一起来确定和定位Annotation
:
h.X = startOfNewGraph;
h.Width = newGraphWidth;
您没有向我们展示如何Annoation
垂直放置。也许锚定到一个DataPoint
?还是通过设置Y
属性?两者现在都应该可以放大到x轴。
请注意,Annotation.X
和和Annotation.AnchorX
的默认值均为double.NaN
,在chart-lingo中通常表示“自动”;在这种情况下,我想这意味着“不适用”。
如果您同时设置了这两个属性,那么我认为这是成功的Annotation.X
。因此,将其重新设置为double.NaN
会Annotation.AnchorX
再次激活。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句