Dashboards & Visualizations

How to customize X Axis in time chart?

kell_cena
Explorer

Hi All,

I want chart to be created in the below way. The x-axis needs to have date and time like that.

kell_cena_0-1679412889656.png

the chart i am able to create is .

kell_cena_1-1679412932257.png


i tried to do eval strftime to _time but not getting the desired result.

The 1st query I tried - 

index=unix (source=cpu sourcetype=cpu) OR (sourcetype=vmstat) host IN (usaws135000)
| fields _time cpu_load_percent memUsedPct swapUsedPct host
| timechart span=1h eval(round(avg(cpu_load_percent),2)) as CPUAvg eval(round(avg(memUsedPct),2)) as MemoryAvg eval(round(avg(swapUsedPct),2)) as SwapAvg by host useother=t limit=0


The 2nd query i tried - 

index=unix (source=cpu sourcetype=cpu) OR (sourcetype=vmstat) host IN (usaws1350)
| fields _time cpu_load_percent memUsedPct swapUsedPct host
| bin span=1h _time
| eval _time=strftime(_time,"%a %b %d %Y %H:%M:%S")
| stats avg(cpu_load_percent) as CPUAvg avg(memUsedPct) as MemoryAvg avg(swapUsedPct) as SwapAvg by _time

Labels (1)
0 Karma
1 Solution

richgalloway
SplunkTrust
SplunkTrust

Once you've created the chart, click on the Format icon then switch to the X-Axis tab where you specify the label rotation.  Or you can do so in Simple XML

<option name="charting.axisLabelsX.majorLabelStyle.rotation">-90</option>

You may be able to change the time format using the fieldformat command.

index=unix (source=cpu sourcetype=cpu) OR (sourcetype=vmstat) host IN (usaws135000)
| fields _time cpu_load_percent memUsedPct swapUsedPct host
| timechart span=1h eval(round(avg(cpu_load_percent),2)) as CPUAvg eval(round(avg(memUsedPct),2)) as MemoryAvg eval(round(avg(swapUsedPct),2)) as SwapAvg by host useother=t limit=0
| fieldformat _time=strftime(_time, "%m/%d/%Y %H:%M:%S")

I'm not sure if it's possible to display as many labels as in your example, but this might do it.

<option name="charting.axisLabelsX.majorLabelVisibility">show</option>

The default of "auto" selectively hides labels to improve readability.

See https://docs.splunk.com/Documentation/Splunk/9.0.4/Viz/ChartConfigurationReference#Area.2C_Bubble.2C... for more

 

---
If this reply helps you, Karma would be appreciated.

View solution in original post

richgalloway
SplunkTrust
SplunkTrust

Once you've created the chart, click on the Format icon then switch to the X-Axis tab where you specify the label rotation.  Or you can do so in Simple XML

<option name="charting.axisLabelsX.majorLabelStyle.rotation">-90</option>

You may be able to change the time format using the fieldformat command.

index=unix (source=cpu sourcetype=cpu) OR (sourcetype=vmstat) host IN (usaws135000)
| fields _time cpu_load_percent memUsedPct swapUsedPct host
| timechart span=1h eval(round(avg(cpu_load_percent),2)) as CPUAvg eval(round(avg(memUsedPct),2)) as MemoryAvg eval(round(avg(swapUsedPct),2)) as SwapAvg by host useother=t limit=0
| fieldformat _time=strftime(_time, "%m/%d/%Y %H:%M:%S")

I'm not sure if it's possible to display as many labels as in your example, but this might do it.

<option name="charting.axisLabelsX.majorLabelVisibility">show</option>

The default of "auto" selectively hides labels to improve readability.

See https://docs.splunk.com/Documentation/Splunk/9.0.4/Viz/ChartConfigurationReference#Area.2C_Bubble.2C... for more

 

---
If this reply helps you, Karma would be appreciated.

kell_cena
Explorer

Thank you @richgalloway for your answer and the reference link. Much appreciated .

Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

Can’t Make It to Boston? Stream .conf25 and Learn with Haya Husain

Boston may be buzzing this September with Splunk University and .conf25, but you don’t have to pack a bag to ...

Splunk Lantern’s Guide to The Most Popular .conf25 Sessions

Splunk Lantern is a Splunk customer success center that provides advice from Splunk experts on valuable data ...

Unlock What’s Next: The Splunk Cloud Platform at .conf25

In just a few days, Boston will be buzzing as the Splunk team and thousands of community members come together ...