Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c#

mschart

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

like image 249
Mehdi LAMRANI Avatar asked Mar 07 '11 15:03

Mehdi LAMRANI


1 Answers

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.

like image 105
scrat.squirrel Avatar answered Sep 30 '22 15:09

scrat.squirrel