使用“Microsoft Chart Controls for .NET 3.5” 对于 WinForms,如何使用网格标记和标签标记某些日期?

发布于 2024-07-16 22:57:45 字数 313 浏览 4 评论 0原文

我正在使用 Microsoft 图表控件,并沿 X 轴显示带有日期的数据,并且希望在某些日期上使用不同颜色的网格线。

假设我沿 X 轴显示 7 个值的一周数据:

05.04.09 06.04.09 07.04.09 08.04.09 09.04.09 10.04.09 11.04.09

此外,我还收集了一些日期时间和名称事件,其中一个发生在 07.04.09,另一个发生在 10.04.09。 然后,我想在每个日期上绘制一条垂直网格线,并添加一个带有事件名称的标签。

我只是不知道我到底如何才能实现这一目标。 任何帮助表示赞赏。

I'm using the Microsoft Chart Controls, and displays data with dates along the X axis and want to have a grid line with a different color on some dates.

Let's say I display data for one week with 7 values along the X-axis:

05.04.09 06.04.09 07.04.09 08.04.09 09.04.09 10.04.09 11.04.09

In addition I have a collection of DateTimes and names for some events, where one is on 07.04.09 and another is on 10.04.09. I then want to have a vertical grid line drawn on each of these dates and a label added with the event name.

I just can't figure out how the heck I can achieve this. Any help appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(4

南风起 2024-07-23 22:57:46

我通过订阅 PostPaint 事件解决了这个问题。 在事件处理程序中,我只需自己绘制线条并在这些垂直线的顶部添加标签。

I solved this by subscribing to the PostPaint event. In the event handler I simply draw the lines myself and add the labels on top of these vertical lines.

拥抱没勇气 2024-07-23 22:57:46
chartName.Series["seriesName"].Points[index]["Color"] 
  = System.Drawing.Color.Blue;
chartName.Series["seriesName"].Points[index]["Color"] 
  = System.Drawing.Color.Blue;
余罪 2024-07-23 22:57:46

据我所知,您无法更改图表网格中特定线条的颜色。 尝试性的解决方案可能是添加一个新的 Column 类型的图表系列; 您要突出显示的日期中的系列值不为零。 这是一种解决方法,但它可能是一个起点。 至于标签,我不知道。

As far as I know you cannot change the color of specific lines in the chart grid. A tentative solution might be to add a new chart series of type Column; the series values are non-zero in the dates you want to highlight. It's a workaround, but it might be a starting point. As for the label, I have no idea.

心作怪 2024-07-23 22:57:46

到目前为止,我已经设法通过在辅助 X 轴上使用 CustomLabels 来实现它,并在该轴上使用我想要的颜色绘制刻度线。 现在的主要问题是使两个 X 轴同步,以便 CustomLabels 最终到达我想要的位置,因为它们目前最终有点分散。

So far I've managed to get it implemented by using CustomLabels on the secondary X axis, and have the tick marks on that axis drawn with the color I want. The main issue now is to get both X axes synchronized so that the CustomLabels ends up where I want them as they currently ends up a bit scattered around.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文