How to show a label for xaxis

I am using the TGraph class to plot some metrics changing in time.
In the array that I associate to the TGraph object I insert values in seconds but I would like to plot a string with day.month.year.min.sec on the xaxis. For every value of the x there will be a string that I would like to plot on the graph.
Is there a way to do this?
Thank you



and also: … time-units

I am trying to use SetBinLabel to set the label of the x axis. The problem is that I need to assign to each value of the x that for instance can be 13684646919 in seconds a string with hour:min:sec that is a string changing. SetBinLabel accepts a const char*. How can I address this problem?

If you need time axis you should use the recipes given in: … time-units
… not SetBinLabel

If I understood well SetTimeDisplay sets the x axis as it is the current time.
I am actually gathering the time from a file which has all the timestamps of the values that I am plotting. These timestamps can be also in the past. I take these timestamps (which are in the form of the return values of C++ function time(0)) and convert them in a string which has the format hour.min.sec. I would like to plot these converted timestamps on the plot, but maintain the real timestamp in the array X to have a proper spacing between one value and the other.

The “time offset” allows to define time from the past also. see the “How To” page I sent you.

I am continuing to use SetBinLabel because even if I use the offset I cannot obtain what I want. By using SetBinLabel by changing the string that I assign to every value of the x axis I obtain the behavior shown in the macro attached. The label is set in the wrong position and desappears every time.
In this example I use the current time but in reality I have to use timestamps that are completely unrelated to the real time passing.
macro_ex.C (1.13 KB)

ok I’ll check that.

I see you do the Draw() in the loop. That is not needed , See my previous macro. You can do it only once before the loop. That does not fixe the problem btw. I’ll let you know.

Attached is a new version of your macro. See the comments inside.
macro_ex.C (1.53 KB)