跳到主要内容

如何在Excel中向图表添加水平平均线?

在Excel中,您可能经常创建一个图表来分析数据趋势。 但是有时,您需要在图表上添加一条简单的水平线,以代表绘制数据的平均线,以便可以清晰,轻松地查看数据的平均值。 在这种情况下,如何在Excel中向图表添加水平平均线?


使用助手列向图表添加水平平均线

如果要在图表上插入水平平均线,则可以先计算数据的平均值,然后再创建图表。 请这样做:

1。 用以下方法计算数据的平均值 一般 函数,例如,在“平均列C2”中,键入以下公式: =平均($ B $ 2:$ B $ 8),然后根据需要将此单元格的“自动填充”手柄拖动到该范围。 看截图:

备注:单击以了解更多有关 对整个列应用相同的公式将完全相同的公式/值应用于整个列,而不增加像元数.

2。 然后选择此范围,然后选择一种要插入的图表格式,例如“ 插页 标签。 看截图:

3。 并已创建一个图表,请单击图表中的“平均数据”列之一(红色条),右键单击并选择 更改系列图表类型 从上下文菜单中。 看截图:

4。 在弹出 更改图表类型 对话框中,单击以突出显示 组合 在左侧栏中,点击 一般,然后从下拉列表中选择一个折线图样式。 看截图:

5。 点击 OK 按钮。 现在,您有一条水平线代表图表中的平均值,请参见屏幕截图:

演示:在Excel中使用助手列向图表添加水平平均线


Kutools for Excel:超过 300 个方便的工具触手可及! 立即开始 30 天免费试用,没有任何功能限制。 立即下载!

2单击以将水平平均线添加到柱形图

如果需要在Excel的柱形图中添加水平平均线,通常需要将平均列添加到源数据,然后将平均值的数据系列添加到统计图,然后更改新添加的统计图的类型数据系列。 但是,随着 将线添加到图表 的特点 Kutools for Excel,您只需两步即可在图表中快速添加这样的平均线!


Kutools for Excel - 使用 300 多种基本工具增强 Excel 功能。 享受全功能 30 天免费试用,无需信用卡! 立即行动吧!

使用VBA代码向图表添加水平平均线

假设您已经在工作表中创建了一个带有数据的柱形图,并且下面的VBA代码也可以帮助您在图表中插入一条平均线。

1。单击图表中的数据列之一,然后将选择所有数据列,请参见屏幕截图:

2。 按住 ALT + F11 键,然后打开 Microsoft Visual Basic应用程序 窗口。

3。 点击 插页 > 模块,然后将以下代码粘贴到 模块窗口.

VBA:在图表上添加一条平均线

Sub AverageLine()
'Update 20130907
Dim ser As Series
Dim arr As Variant
Dim total As Double
Dim outArr As Variant
If VBA.TypeName(Application.Selection) <> "Series" Then Exit Sub
Set ser = Application.Selection
arr = ser.Values
total = Application.WorksheetFunction.Average(arr)
ReDim outArr(LBound(arr) To UBound(arr))
For i = LBound(outArr) To UBound(outArr)
    outArr(i) = total
Next
With ActiveChart.SeriesCollection.NewSeries
    .XValues = ser.XValues
    .Values = outArr
    .Name = "Average " & ser.Name
    .AxisGroup = ser.AxisGroup
    .MarkerStyle = xlNone
    .Border.Color = ser.Border.Color
    .ChartType = xlLine
    .Format.Line.ForeColor.ObjectThemeColor = msoThemeColorAccent6
End With
End Sub

4。 然后按 F5 键以运行此代码,并且水平平均线已插入到柱形图中。 看截图:

备注注意:仅当您插入的列格式为2-D列时,此VBA才能运行。


使用出色的工具快速添加水平平均线

这种方法将推荐一个很棒的工具, 将线添加到图表 的特点 Kutools for Excel,只需单击两次即可将水平平均线快速添加到所选柱形图中!

Kutools for Excel-包括300多个用于Excel的便捷工具。 全功能30天免费试用,无需信用卡! 立即行动吧!

假设您已经创建了一个柱状图,如下图所示,并且可以为其添加水平平均线,如下所示:
 

1。 选择柱形图,然后单击 库工具 > 图表 > 将线添加到图表 启用此功能。

2。 在向图表添加折线对话框中,请检查 一般 选项,然后单击 Ok 按钮。

现在,水平平均线立即添加到选定的柱形图中。


在Excel中的每一页上插入并打印平均值

Kutools for Excel的 数据分页统计 实用程序可以帮助您轻松地在每个打印页面中插入各种小计(例如,总和,最大,最小,乘积等)。


广告页面小计平均值3

Kutools for Excel - 使用 300 多种基本工具增强 Excel 功能。 享受全功能 30 天免费试用,无需信用卡! 立即行动吧!

相关文章:

最佳办公生产力工具

🤖 Kutools 人工智能助手:基于以下内容彻底改变数据分析: 智能执行   |  生成代码  |  创建自定义公式  |  分析数据并生成图表  |  调用 Kutools 函数...
热门特色: 查找、突出显示或识别重复项   |  删除空白行   |  合并列或单元格而不丢失数据   |   不使用公式进行四舍五入 ...
超级查询: 多条件VLookup    多值VLookup  |   跨多个工作表的 VLookup   |   模糊查询 ....
高级下拉列表: 快速创建下拉列表   |  依赖下拉列表   |  多选下拉列表 ....
列管理器: 添加特定数量的列  |  移动列  |  切换隐藏列的可见性状态  |  比较范围和列 ...
特色功能: 网格焦点   |  设计图   |   大方程式酒吧    工作簿和工作表管理器   |  资源库 (自动文本)   |  日期选择器   |  合并工作表   |  加密/解密单元格    按列表发送电子邮件   |  超级筛选   |   特殊过滤器 (过滤粗体/斜体/删除线...)...
前 15 个工具集12 文本 工具 (添加文本, 删除字符,...)   |   50+ 图表 类型 (甘特图,...)   |   40+ 实用 公式 (根据生日计算年龄,...)   |   19 插入 工具 (插入二维码, 从路径插入图片,...)   |   12 转化 工具 (小写金额转大写, 货币兑换,...)   |   7 合并与拆分 工具 (高级组合行, 分裂细胞,...)   |   ... 和更多

使用 Kutools for Excel 增强您的 Excel 技能,体验前所未有的效率。 Kutools for Excel 提供了 300 多种高级功能来提高生产力并节省时间。  单击此处获取您最需要的功能...

产品描述


Office Tab 为 Office 带来选项卡式界面,让您的工作更加轻松

  • 在Word,Excel,PowerPoint中启用选项卡式编辑和阅读,发布者,Access,Visio和Project。
  • 在同一窗口的新选项卡中而不是在新窗口中打开并创建多个文档。
  • 每天将您的工作效率提高50%,并减少数百次鼠标单击!
Comments (7)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
I don't think the VB code works for pivot tables.. anyone know how to get it working for pivots?
This comment was minimized by the moderator on the site
Is there a way to have the average line extend past the center of the first and last bars? i.e. how can i make the average line extend to all the way to the horizontal bounds of the graph?
This comment was minimized by the moderator on the site
This should help as long as you don't need to use the secondary axis for a different series. Still searching for the answer for when you do.
This comment was minimized by the moderator on the site
Dear Sir, Its good to know that you have done with a line BUT i want to start this from start till end across the table.
This comment was minimized by the moderator on the site
Tried the first method, but changes both data two lines. I made sure i selected only the red column.
This comment was minimized by the moderator on the site
Steps 1-3 don't work. The formula is carried through the rows and it calculates an average for the data for each row.
This comment was minimized by the moderator on the site
Did you check that you had locked the reference (look for the $ infront of the Cell references)
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations