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

孤人 提交于 2019-12-10 13:32:50

问题


Is is possible to have an X Axis display hours (HH:MM)
and another (or the same) displaying Days (YYYY-MM-DD)
at different intervals so it look like


 |               |               |               |               |

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


Off Topic Advice
The more I use MS Chart Control the more I regret my decision switching from 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). 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


回答1:


You can use a single X axis, and you can customize the "12:00" labels to display the "date". See CustomLabel and CustomLabelsCollection in namespace System.Windows.Forms.DataVisualization.Charting. You could use the freeware ILSpy to see what's inside MSChart dll.

There are several constructors for CustomLabel, I used this one:

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.



来源:https://stackoverflow.com/questions/5221404/ms-chart-control-two-x-axis-one-for-hours-another-for-days-or-mixing-both

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!