You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Jasper iReport的每个柱状图上方显示计数值?

给柱状图添加顶部计数值的操作方法

1. Excel/Google Sheets

  • 选中你的柱状图,右键点击图表区域,选择「添加数据标签」
  • 右键点击数据标签,选择「设置数据标签格式」
  • 在弹出面板里勾选「值」,把标签位置调整到「数据标签外」(即柱子上方)
  • 可按需调整字体大小、颜色,让标签更清晰

2. Python Matplotlib

  • 绘制柱状图后,遍历每个柱子,用text()方法在顶部插入数值:
import matplotlib.pyplot as plt

# 示例数据
categories = ["A", "B", "C", "D"]
values = [12, 25, 18, 30]

# 绘制柱状图
bars = plt.bar(categories, values)

# 添加顶部数值标签
for bar in bars:
    height = bar.get_height()
    plt.text(bar.get_x() + bar.get_width()/2., height,
             f'{height}',
             ha='center', va='bottom')

plt.show()
  • ha='center'让标签水平居中,va='bottom'确保标签贴在柱子顶部上方

3. Python Seaborn

  • 基于Matplotlib的操作逻辑,先画柱状图再添加标签:
import seaborn as sns
import matplotlib.pyplot as plt

# 示例数据
data = {"category": ["A", "B", "C", "D"], "value": [12, 25, 18, 30]}

# 绘制柱状图
ax = sns.barplot(x="category", y="value", data=data)

# 添加顶部数值标签
for p in ax.patches:
    height = p.get_height()
    ax.text(p.get_x() + p.get_width()/2., height,
            f'{height}',
            ha='center', va='bottom')

plt.show()

4. Tableau

  • 拖入维度和度量生成柱状图
  • 在「标记」卡中点击「添加标签」,默认会显示度量值
  • 右键点击标签,选择「设置标签」,把位置调整为「顶部」,按需设置字体样式

内容的提问来源于stack exchange,提问作者Naim NSCO

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.18 20:52:32