Getting Data In

Specify timestamp display format for timechart axis labels

chendry
Explorer

Hi everyone,

I want the timestamps for the X-axis labels of a timechart to have the following format:

MM-DD HH:mm

where HH:mm is in 24-h format, M designates month, m designates minute.

Example: "February 14th, 1PM" should look like "02-14 13:00"

Does anyone now how & where this can be configured?

Thanks!

Tags (1)

chendry
Explorer

Thanks for your replies -

The proposed method worked:

... | timechart span=1m sum(HTTP_5xx) | fillnull value=0 | rename _time AS Time | eval Time=strftime(Time, "%m-%d %H:%M")

However, using the above search command, the labels on the X-Axis disappear.

This is how chart labels looked before ("bad" timestamp formatting, but proper labels):

alt text

This is how chart labels look now (proper timestamp formatting, but labels not shown):

alt text

I use the following chart formatting option the force label visibility:

          <param name="charting.primaryAxisLabels.majorLabelVisibility">show</param>

However, with the reformatted timestamps, the labels only partly appear (i.e. they are still cut off) when stretching the chart horizontally to ~ 2000 pixels...

chendry
Explorer

I guess the cause for this is that after using strftime(), the chart values on the X-Axis are not anymore of type TIME, but CATEGORY. Unfortunately, I think that it is not possible to properly space the major labels for a CATEGORY axis because the param "charting.axisLabelsX.majorUnit" does not seem to exist for category axis type. Does anyone know how to space category labels?

Ron_Naken
Splunk Employee
Splunk Employee

You can use chart to do the same as timechart:

... | eval Time = strftime(_time, "%m/%d %H:%M") | chart count as Total by Time

And it's easy to format a chart...

EDIT:

Based on gkanapathy's comment, it might be better to implement it like this to ensure proper sorting of the time values:

... | eval Time = _time | chart count as Total by Time span=1h | eval Time=strftime(Time, "%m/%d %H:%M") 

gkanapathy
Splunk Employee
Splunk Employee

You should do the chart/timechart, then apply a rename and eval afterwards to solve these issues.

gkanapathy
Splunk Employee
Splunk Employee

That won't quite work, as the Time field will not necessarily be sorted in the right order, and furthermore if the data isn't distributed evenly, your time axis won't be even over time. You can use the makecontinuous command to try to overcome the second problem.

0 Karma
Get Updates on the Splunk Community!

Stay Connected: Your Guide to May Tech Talks, Office Hours, and Webinars!

Take a look below to explore our upcoming Community Office Hours, Tech Talks, and Webinars this month. This ...

They're back! Join the SplunkTrust and MVP at .conf24

With our highly anticipated annual conference, .conf, comes the fez-wearers you can trust! The SplunkTrust, as ...

Enterprise Security Content Update (ESCU) | New Releases

Last month, the Splunk Threat Research Team had two releases of new security content via the Enterprise ...