如何在 Application Insights Analytics 中对图表/数据桶进行零填充

问题描述 投票:0回答:1

我正在尝试在 Application Insights 中绘制一个总和/计数指标随时间变化的面积图:

customEvents
| where timestamp > ago(7d)
| summarize count() by bin(timestamp, 1h)
| render areachart  

我看到的是,如果某些桶中没有数据,那么图表不会下降到 0。相反,两个点相连,并且人们认为有一些数据,但实际上没有。

问题-如何获得零填充面积图(对应红墨水图)?

azure azure-application-insights
1个回答
23
投票

有多种方法可以实现这一目标。

make-series运算符允许为不存在聚合数据的时间段设置默认值:

customEvents
| where timestamp > ago(10m)
| make-series count() default=0 on timestamp in range(ago(10m), now(), 1m)
| render areachart

这将生成零填充的数据数组,并且

| render
将相应地构建图表。

如果首选

| summarize
,您可以使用 range 运算符自行创建零填充范围:

let defaultValue = 0;
range timestamp from floor(ago(10m),1m) to floor(now() + 10m,1m) step 1m
| join kind=leftouter
(
    customEvents
    | where timestamp > floor(ago(10m),1m) and timestamp < floor(now(),1m)
    | summarize Value=count() by bin(timestamp, 1m)
) on timestamp
| project timestamp, value = iff(isnotempty(Value), Value, defaultValue)
| render areachart

确保使用

join kind=leftouter
使连接左侧的所有时间戳都出现在输出中。

© www.soinside.com 2019 - 2024. All rights reserved.