无法通过代码清除 Silverlight 图表工具包轴
我试图拥有一个 Silverlight 图表(Windows Phone 7),用户可以通过更改某些设置来修改它。
清除图表轴并读取新轴后,我最终得到 chart.ActualAxes.Count 报告的双轴
有谁知道如何完全清除和删除 silverlight 图表上的所有轴并添加新的?我是否打算在添加后调用某些内容来更新 ActualAxes 列表?
提前感谢
代码示例(调用此两次,您的图表最终将有 4 个轴而不是两个):
chart.Axes.Clear();
chart.Axes.Add(new LinearAxis()
{
Orientation = AxisOrientation.Y,
Location = AxisLocation.Left,
Minimum = 0
});
chart.Axes.Add(new DateTimeAxis()
{
Orientation = AxisOrientation.X,
Location = AxisLocation.Bottom,
IntervalType = DateTimeIntervalType.Days
});
I am attempting to have a Silverlight chart (windows phone 7) that a user can modify by changing some settings.
Upon clearing the charts axes and readding new axes, i end up with double axes being being reported by chart.ActualAxes.Count
does anyone know how to fully clear and delete all the axes on a silverlight chart and add new ones? Am i meant to call something to update the ActualAxes list after adding?
thanks in advance
code sample (call this twice and your chart will end up with 4 axes instead of two):
chart.Axes.Clear();
chart.Axes.Add(new LinearAxis()
{
Orientation = AxisOrientation.Y,
Location = AxisLocation.Left,
Minimum = 0
});
chart.Axes.Add(new DateTimeAxis()
{
Orientation = AxisOrientation.X,
Location = AxisLocation.Bottom,
IntervalType = DateTimeIntervalType.Days
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Chart
Axes
集合表示图表中的持久Axes,即使图表中没有系列,也会呈现这些持久Axes。ActualAxes
表示持久轴和图表中系列使用的轴的组合。当您清除集合并测试
ActualAxes.Count
时,您会发现它仍然显示 2,即使Axes
现在为 0。ActualAxes
(一个实例SeriesHostAxesCollection
)将不允许删除现有系列中正在使用的轴。因此,ActualAxes 集合保留了原始集合。然后,您将另外 2 个添加到持久Axes
集合中,这样这 2 个新的 Axes 也会添加到ActualAxes
中,最终得到 4。再次运行您的代码(第三个时间),您应该看到
ActualAxes
计数仍为 4。那是因为您在第二次调用中添加的 2 个轴未被任何系列使用,因此可以将它们从ActualAxes
集合。The Chart
Axes
collection represents the persistentAxes in the chart that will be rendered even if there are no series in the chart. TheActualAxes
represents a combination of both the persistent Axes and those in use by the series in the chart.When you Clear the collection and test
ActualAxes.Count
you will find it still says 2 even thoughAxes
is now 0. TheActualAxes
(an instance ofSeriesHostAxesCollection
) will not allow the removal of an axis which is in use be an existing Series. Hence theActualAxes
collection holds on to the originals. You then add 2 others to the persistentAxes
collection so those 2 new ones are also added to theActualAxes
, you end up with 4.Run your code yet again (a third time) and you should see the
ActualAxes
count remains 4. Thats because the 2 Axis you added in the second call are not being used by any series so they can be removed from theActualAxes
collection.以下代码应该可以工作
Following code should work