azurekqlazure-monitoring

How can I stack data correctly using kusto into a columnchart


I have the following kusto query:

AACHttpRequest
| where StatusCode != 200
| summarize ErrorCount=count() by bin(TimeGenerated, 1d), StatusCode

This gives me data like this:

enter image description here

Now I want to render this in a stacked columnchart, but if I add the render columnchart it does this: enter image description here

This is not what I want, I want the graph to stack the errorCount, with different colors and then display the StatusCode in the legend, so you would get something like this (picture taken from internet blog):

enter image description here

What do I need to to do to get to this result? Any help is very much appreciated.

In case it matters, the data is from Azure Monitor.


Solution

  • You probably need to specify more properties for the column chart for this to look how you want it.

    let T = datatable(TimeGenerated:datetime, StatusCode:int, ErrorCount:int) [
    datetime("2024-03-26"), 304, 3,
    datetime("2024-03-26"), 404, 5,
    datetime("2024-03-27"), 304, 10,
    datetime("2024-03-27"), 404, 2,
    datetime("2024-03-27"), 405, 1,
    datetime("2024-03-28"), 404, 1,
    datetime("2024-03-28"), 301, 2
    ];
    T
    | extend StatusCode = tostring(StatusCode)
    | render columnchart with (kind=stacked, series=StatusCode)
    

    enter image description here

    Edit: Sorry noticed you said Azure Monitor, we need to do something slightly different, see the updated code above for Log Analytics functional.