formatting-insight-axes
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseFormatting insight axes
格式化 insight 轴
PostHog renders insights with a built-in axis formatter. Use it instead of
contorting the query or a literal prefix/postfix to fake units.
The two insight kinds configure it in different places:
- TrendsQuery — (this page, below)
trendsFilter.aggregationAxisFormat - SQL insights () — per-column
DataVisualizationNode(see SQL insights)settings.formatting
PostHog 使用内置的轴格式化器渲染 insights。请使用它,而不是通过扭曲查询或使用字面前缀/后缀来伪造单位。
两种 insight 类型在不同位置配置:
- TrendsQuery — (本页下方)
trendsFilter.aggregationAxisFormat - SQL insights()— 按列的
DataVisualizationNode(参见 SQL insights)settings.formatting
The anti-pattern
反模式
If you are reaching for any of these, stop and pick a format below first:
- with
formula: "A / 60"— manual seconds -> minutesaggregationAxisPostfix: " mins" - with
formula: "A / 1000"— manual ms -> secondsaggregationAxisPostfix: " s" - with
formula: "A * 100"— manual ratio -> percentaggregationAxisPostfix: "%" - /
aggregationAxisPostfix: "ms"/"s"/"min"on raw values"hr"
These freeze the unit at one scale. The built-in formatter picks a friendly
unit per value (1.5s, 2m 12s, 1h 4m) and keeps the underlying series numerically
correct for further math, breakdowns, and alerts.
如果你准备使用以下任何一种,请停止并先选择下面的格式:
- 搭配
formula: "A / 60"— 手动将秒转换为分钟aggregationAxisPostfix: " mins" - 搭配
formula: "A / 1000"— 手动将毫秒转换为秒aggregationAxisPostfix: " s" - 搭配
formula: "A * 100"— 手动将比率转换为百分比aggregationAxisPostfix: "%" - 在原始值上使用 /
aggregationAxisPostfix: "ms"/"s"/"min""hr"
这些做法将单位固定在一个刻度上。内置格式化器会根据每个值选择友好的单位(1.5s、2m 12s、1h 4m),并保持底层序列在数值上正确,以便后续计算、下钻和告警。
Available formats
可用格式
Set on the TrendsQuery:
trendsFilter.aggregationAxisFormat| Value | Use when the series is... | Renders as |
|---|---|---|
| a plain count | |
| seconds (any scale) | |
| milliseconds | |
| already 0-100 | |
| a ratio 0-1 | |
| money in the project's base currency | |
| large counts you want compacted | |
Companion fields on :
trendsFilter- — literal prefix (e.g.
aggregationAxisPrefix) when you need a symbol pinned to a specific currency or unit, regardless of project settings"$" - — literal suffix; reserve for genuine units the format can't express (e.g.
aggregationAxisPostfix," req"), never for" events"/"mins"/"s"— the percentage formats already append the"%"sign, so a%postfix renders"%"50%% - — cap decimals (1 or 2 is usually right for currency / ratios)
decimalPlaces
在 TrendsQuery 上设置 :
trendsFilter.aggregationAxisFormat| 值 | 当序列是... | 渲染为 |
|---|---|---|
| 普通计数 | |
| 秒(任意量级) | |
| 毫秒 | |
| 已经是 0-100 | |
| 0-1 的比率 | |
| 项目基础货币中的金额 | |
| 需要紧凑显示的大数字 | |
trendsFilter- — 字面前缀(例如
aggregationAxisPrefix),当你需要固定符号到特定货币或单位时使用,无论项目设置如何"$" - — 字面后缀;留给格式无法表达的真实单位(例如
aggregationAxisPostfix、" req"),切勿用于" events"/"mins"/"s"— 百分比格式已经附加了"%"符号,所以%后缀会渲染为"%"50%% - — 限制小数位数(货币/比率通常 1 或 2 位即可)
decimalPlaces
Currency — pick format
or prefix
carefully
formatprefix货币 — 谨慎选择 format
或 prefix
formatprefixaggregationAxisFormat: "currency"If the values are pinned to a specific currency regardless of project (e.g.
is always USD, even on a EUR-base project), use
+ so the symbol matches the
data. Using here would render USD values with on a
EUR project.
$ai_total_cost_usdaggregationAxisPrefix: "$"decimalPlaces: 2format: "currency"€aggregationAxisFormat: "currency"如果值与项目设置无关地固定为特定货币(例如 即使在 EUR 基础货币项目中也始终是 USD),请使用 + ,使符号与数据匹配。在这种情况下使用 会在 EUR 项目上以 渲染 USD 值。
$ai_total_cost_usdaggregationAxisPrefix: "$"decimalPlaces: 2format: "currency"€When the series is in seconds
当序列以秒为单位时
If the series is in seconds (latency, session length, time-to-first-event,
processing time, page load, etc.), silently default to
. Do not stop to ask — the formatter is
non-destructive (the underlying values stay in seconds either way, only the
labels change), so picking it is always at least as good as raw seconds.
aggregationAxisFormat: "duration"Only confirm with the user when they have explicitly named a fixed unit
they want pinned ("show this in minutes", "graph the average in hours"):
"I can pin the y-axis to minutes by dividing the series by 60, or use PostHog'sformatter which auto-picks seconds / minutes / hours per value —durationrenders as90sand1m 30sas5400s. Which would you prefer?"1h 30m
In one-shot MCP contexts where no user is in the loop, just pick
and move on.
duration如果序列以秒为单位(延迟、会话时长、首次事件时间、处理时间、页面加载等),请静默地默认使用 。不要停下来询问——格式化器是非破坏性的(底层值无论哪种方式都保持秒,只是标签变化),所以选择它至少与原始秒值一样好。
aggregationAxisFormat: "duration"只有当用户明确指定了想要固定的单位(“以分钟显示”、“以小时绘制平均值”)时才需要与用户确认:
“我可以通过将序列除以 60 将 y 轴固定为分钟,或使用 PostHog 的格式化器自动为每个值选择秒 / 分钟 / 小时 —duration渲染为90s,1m 30s渲染为5400s。您更倾向于哪种?”1h 30m
在没有用户参与的 MCP 单次上下文中,直接选择 并继续。
durationExamples
示例
Latency — duration in milliseconds
延迟 — 毫秒持续时间
json
{
"kind": "TrendsQuery",
"series": [
{
"kind": "EventsNode",
"event": "$pageview",
"math": "p95",
"math_property": "$performance_page_loaded"
}
],
"trendsFilter": {
"aggregationAxisFormat": "duration_ms"
}
}json
{
"kind": "TrendsQuery",
"series": [
{
"kind": "EventsNode",
"event": "$pageview",
"math": "p95",
"math_property": "$performance_page_loaded"
}
],
"trendsFilter": {
"aggregationAxisFormat": "duration_ms"
}
}Average session length — duration in seconds
平均会话时长 — 秒持续时间
json
{
"kind": "TrendsQuery",
"series": [
{
"kind": "EventsNode",
"event": "$pageleave",
"math": "avg",
"math_property": "$session_duration"
}
],
"trendsFilter": {
"aggregationAxisFormat": "duration"
}
}json
{
"kind": "TrendsQuery",
"series": [
{
"kind": "EventsNode",
"event": "$pageleave",
"math": "avg",
"math_property": "$session_duration"
}
],
"trendsFilter": {
"aggregationAxisFormat": "duration"
}
}Revenue — currency in the project's base currency
收入 — 项目基础货币
json
{
"trendsFilter": {
"aggregationAxisFormat": "currency",
"decimalPlaces": 2
}
}json
{
"trendsFilter": {
"aggregationAxisFormat": "currency",
"decimalPlaces": 2
}
}Fixed-currency value (e.g. LLM cost in USD) — pin the symbol
固定货币值(例如 LLM 成本以 USD 为单位)— 固定符号
json
{
"trendsFilter": {
"aggregationAxisPrefix": "$",
"decimalPlaces": 2
}
}json
{
"trendsFilter": {
"aggregationAxisPrefix": "$",
"decimalPlaces": 2
}
}Conversion rate — percentage from a 0-1 formula
转化率 — 从 0-1 公式得到百分比
json
{
"kind": "TrendsQuery",
"series": [
{
"kind": "EventsNode",
"event": "checkout_completed",
"math": "dau"
},
{
"kind": "EventsNode",
"event": "checkout_started",
"math": "dau"
}
],
"trendsFilter": {
"formula": "A / B",
"aggregationAxisFormat": "percentage_scaled",
"decimalPlaces": 1
}
}json
{
"kind": "TrendsQuery",
"series": [
{
"kind": "EventsNode",
"event": "checkout_completed",
"math": "dau"
},
{
"kind": "EventsNode",
"event": "checkout_started",
"math": "dau"
}
],
"trendsFilter": {
"formula": "A / B",
"aggregationAxisFormat": "percentage_scaled",
"decimalPlaces": 1
}
}SQL insights (DataVisualizationNode)
SQL insights (DataVisualizationNode)
SQL insights have no .
Formatting is per column, on for a chart and top-level for a table.
trendsFilterchartSettings.yAxis[].settings.formattingtableSettings.columns[].settings.formattingjson
{
"kind": "DataVisualizationNode",
"source": { "kind": "HogQLQuery", "query": "SELECT week, conversion_rate FROM ..." },
"display": "ActionsLineGraph",
"chartSettings": {
"xAxis": { "column": "week" },
"yAxis": [
{
"column": "conversion_rate",
"settings": { "formatting": { "style": "percent", "decimalPlaces": 1 } }
}
]
}
}stylenonenumbershortpercentdurationcurrencyprefixsuffixpercent%percentage_scaledsuffix| SQL returns | | Renders |
|---|---|---|
a 0-1 ratio ( | | |
0-100 ( | | |
A mix renders broken: plus a suffix gives , and on an already-scaled 0-100 column gives .
Prefer the ratio form — it keeps the out of the query, so the stored column stays a plain ratio for anything else that reads it.
style: "percent""%"47.3%%percent4730%100.0 *SQL insights 没有 。
格式化是按列的,在 中用于图表,在 中用于表格。
trendsFilterchartSettings.yAxis[].settings.formattingtableSettings.columns[].settings.formattingjson
{
"kind": "DataVisualizationNode",
"source": { "kind": "HogQLQuery", "query": "SELECT week, conversion_rate FROM ..." },
"display": "ActionsLineGraph",
"chartSettings": {
"xAxis": { "column": "week" },
"yAxis": [
{
"column": "conversion_rate",
"settings": { "formatting": { "style": "percent", "decimalPlaces": 1 } }
}
]
}
}stylenonenumbershortpercentdurationcurrencyprefixsuffixpercent%percentage_scaledsuffix| SQL 返回 | | 渲染 |
|---|---|---|
0-1 比率( | | |
0-100( | | |
混用会渲染错误: 加上 后缀会产生 ,而在已经是 0-100 的列上使用 会产生 。
优先采用比率形式 — 它可以将 移出查询,使存储的列保持为纯比率,供其他读取使用。
style: "percent""%"47.3%%percent4730%100.0 *Updating an existing insight
更新现有 insight
If an insight you are already editing uses one of these anti-patterns — a
trends / pair, or a SQL column with both
and a suffix — fix it in the same call: drop the
divide-by-N or and the literal , and let the format own the unit.
Values stay the same, only labels change. Do not scan unrelated insights — fix
only the ones you are already touching.
formulapostfixstyle: "percent""%"posthog:insight-update100.0 *%如果你正在编辑的 insight 使用了这些反模式之一 — trends 的 / 配对,或 SQL 列同时具有 和 后缀 — 在相同的 调用中一并修复:删除除以 N 或 以及字面 ,让格式本身拥有单位。值保持不变,仅标签变化。不要扫描不相关的 insights — 只修复你正在触达的那些。
formulapostfixstyle: "percent""%"posthog:insight-update100.0 *%