Search code examples
aws-cloudwatch-log-insights

Change bar graph x-axis direction in CloudWatch Log Insights


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


Solution

  • 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