无法通过代码清除 Silverlight 图表工具包轴

发布于 2024-11-28 08:18:21 字数 601 浏览 1 评论 0原文

我试图拥有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

入怼 2024-12-05 08:18:21

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. The ActualAxes 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 though Axes is now 0. The ActualAxes (an instance of SeriesHostAxesCollection) will not allow the removal of an axis which is in use be an existing Series. Hence the ActualAxes collection holds on to the originals. You then add 2 others to the persistent Axes collection so those 2 new ones are also added to the ActualAxes, 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 the ActualAxes collection.

神经大条 2024-12-05 08:18:21

以下代码应该可以工作

var xAxis = chart_name.ActualAxes.OfType<LinearAxis>().FirstOrDefault(ax => ax.Orientation == AxisOrientation.X);
if (xAxis != null) 
{
   xAxis.Title = "The Title";
}

Following code should work

var xAxis = chart_name.ActualAxes.OfType<LinearAxis>().FirstOrDefault(ax => ax.Orientation == AxisOrientation.X);
if (xAxis != null) 
{
   xAxis.Title = "The Title";
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文