简体   繁体   English

MS图表控制:两个X轴,一个小时,另一个几天(或混合两个)

[英]MS Chart Control :Two X Axis, one for hours, another for days (or mixing both)

Is is possible to have an X Axis display hours (HH:MM) 可以有一个X轴显示小时(HH:MM)
and another (or the same) displaying Days (YYYY-MM-DD) 和另一个(或相同)显示天数(YYYY-MM-DD)
at different intervals so it look like 在不同的时间间隔看起来像


 |               |               |               |               |

09:00 10:00 11:00 12:00 01:00 09:00 10:00 11:00 12:00 01:00


                                                  |            
                                              2010/04/20         


Or Ideally : 或理想情况:


 |               |               |               |               |

09:00 10:00 11:00 2010/04/20 01:00 09:00 10:00 11:00 2010/04/20 01:00


Off Topic Advice 关闭主题建议
The more I use MS Chart Control the more I regret my decision switching from ZedGraph. 我使用MS Chart Control的次数越多,我对从ZedGraph切换的决定感到后悔。 I am really getting angry and frustrated I've lost long hours on meaningless details like these and circumventing through very ugly workarounds (like creating many duplicate "ghost" charts to "handle" different scaled series , -What the Heck!!?-, aligning data MANUALLY adding empty points because the default code use case is extremely unflexible). 我真的生气和沮丧我在这些无意义的细节上浪费了很长时间,并通过非常丑陋的解决方法来规避(比如制作许多重复的“幽灵”图表以“处理”不同的缩放系列, - 什么是Heck !!? - ,对齐数据手动添加空点,因为默认代码用例非常不灵活)。 It seems very fancy at first glance, but from the moment you want to tweak and do serious stuff rather than displaying an ultra basic pie chart or bar histogram you enter a World of Hell . 乍一看似乎非常花哨,但从你想要调整并做一些严肃的事情而不是显示超基本饼图或条形直方图的那一刻起,你就进入了一个地狱世界 So I basically advice NOT to use it, unless you are already stuck with it (but it's never too late to reconsider moving to something that isn't that wonky and time-consuming) 所以我基本上建议不要使用它,除非你已经坚持使用它(但是重新考虑转移到那些不那么笨且耗时的东西永远不会太晚)

EDIT : I could use "Keywords" as adviced here . 编辑:我可以在这里建议使用“关键字”。 Seems very funky and tedious though... 虽然......看起来非常时髦又乏味
Besides, this violates the separation between Logic and Presentation 此外,这违反了逻辑和演示之间的分离
(this should never happen! Sign of Poor Design...) (这应该永远不会发生!设计糟糕的标志......)

For another example of such annoying similar (clueless) issues see this post 对于这种恼人的类似(无能)问题的另一个例子,请参阅这篇文章

You can use a single X axis, and you can customize the "12:00" labels to display the "date". 您可以使用单个X轴,并可以自定义“12:00”标签以显示“日期”。 See CustomLabel and CustomLabelsCollection in namespace System.Windows.Forms.DataVisualization.Charting. 请参阅命名空间System.Windows.Forms.DataVisualization.Charting中的CustomLabel和CustomLabelsCollection。 You could use the freeware ILSpy to see what's inside MSChart dll. 您可以使用免费软件ILSpy来查看MSChart dll中的内容。

There are several constructors for CustomLabel, I used this one: CustomLabel有几个构造函数,我用过这个:

public CustomLabel(double fromPosition, double toPosition, string text, int labelRow, LabelMarkStyle markStyle, GridTickTypes gridTick)

Basically, it goes something like this: 基本上,它是这样的:

CustomLabel label1 = new CustomLabel(...);
mychart.ChartAreas[0].AxisX.CustomLabels.Add(label1);

Hope this helps. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM