Mastering Grafana Pie Charts: When and How to Use Them Effectively
Learn when to choose a Pie Chart in Grafana, explore common use cases like browser market share and HTTP status codes, and follow step‑by‑step instructions—including panel options, legend, tooltip, and JSON configuration—to create clear, proportion‑focused visualizations.
Why Use a Pie Chart?
Pie charts are best for showing composition and proportion, helping viewers instantly understand which parts dominate the whole. Typical scenarios include browser market share distribution, event reasons by category, network traffic sources, and user demographics.
Tip
The core value of a pie chart is not precise comparison but intuitive display of "components" and "share".
Creating a Pie Chart in Grafana
Create the visualization.
Select the Pie Chart type.
In Panel options , set the Title and Description of the panel.
PromQL Settings
Use a PromQL query in the Metrics browser, e.g.,
sum by (status) (increase(nginx_ingress_controller_requests{host="${host}"}[1h])) > 0, and format the legend with {{status}}状态码.
Pie Chart Options
Labels : Choose the fields to display on the chart, such as Name and Percent .
Tooltip : Set the mode to show values when hovering; choose All to enable sorting options.
Legend :
Visibility: toggle on/off (default on).
Mode: display as a table.
Placement: position the legend on the right (default bottom).
Legend values: show Percent .
Standard Options
Set the number of decimal places to display, e.g., 2.
JSON Configuration Example
{
"datasource": {"uid": "${datasource}"},
// <Panel options>.Description
"description": "根据最近1小时统计结果",
"fieldConfig": {"defaults": {"decimals": 2}},
"gridPos": {"h": 9, "w": 7, "x": 0, "y": 0},
"options": {
// <Pie chart>.Labels
"displayLabels": ["percent", "name"],
"legend": {
// <Legend>.Mode
"displayMode": "table",
// <Legend>.Placement
"placement": "right",
// <Legend>.Visibility
"showLegend": true,
// <Legend>.Values
"values": ["percent"]
},
"tooltip": {
// <Tooltip>.Mode
"mode": "multi",
// <Tooltip>.Values sort order
"sort": "asc"
}
},
"targets": [{
// PromQL settings
"expr": "sum by (status) (increase(nginx_ingress_controller_requests{host=\"${host}\"}[1h])) > 0",
"legendFormat": "{{status}}状态码"
}],
// Panel title
"title": "${host}域名状态码分布情况",
// Panel type
"type": "piechart"
}Conclusion
Don’t dismiss pie charts outright; understand their strengths and apply them to scenarios that emphasize proportion and composition, such as HTTP status code distribution, to achieve clear and impactful visualizations.
Linux Ops Smart Journey
The operations journey never stops—pursuing excellence endlessly.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
