3

When I graph data in AWS CloudWatch Log insights, bar graphs are ordered Most Recent to Oldest (left to right) while Line Graphs are ordered Oldest to Most recent (left to right) this seems to occur despite setting sort values. Here is an example query:

fields @timestamp, link_count
| sort @timestamp desc
| filter ispresent(link_count)
| stats avg(link_count) as Links by bin(1d)

I would like the x-axis on my bar graph to follow the same order as the line graph. It doesn't really matter which direction as long as both go in the same direction. Is this possible?

Observe the x-axis values in each of these graphs:

Line Graph Visualization Line Graph Visualization

Bar Graph Visualization Bar Graph Visualization

Mike Dalrymple
  • 993
  • 12
  • 23

1 Answers1

5

I came into the same issue, and solved it. But I was using other functions instead of avg(). So maybe this could work for you as well:

The trick is to give bar a name, and then sort the name

...
| stats avg(data) by bin(1d) as data_name
| sort data_name
KokoJa
  • 66
  • 4
  • This worked for me. I made a couple changes so it's `sort by` and I was able to retain my `avg(data)` label (`DataName`) separate from the date label (`sort_name`). – Mike Dalrymple Jan 03 '21 at 00:32
  • @MikeDalrymple - Can you provide your final code? I was hoping to get the bar graph shown with the timstamps in the same format as the line graph (e.g. MM-DD-YYYY...). When it starts with year, it's often cutoff. – Avery Michelle Dawn Jan 15 '21 at 02:39