如何通过VBA隐藏Excel箱形图(箱须图)中的内部数据点?
Excel箱形图(箱须图)隐藏内部数据点VBA解决方案
Excel箱须图的内部数据点控制属性属于箱形图系列的专属属性,宏录制器不支持捕获该类操作,直接为目标系列设置ShowInnerPoints = False即可实现隐藏需求。
以下是修改后的完整可运行代码,已新增隐藏内部数据点的逻辑:
Set shp = wksData.Shapes.AddChart2(406, xlBoxwhisker, intLeft, intTop, intGraphWidth, intGraphHeight) With shp.Chart .FullSeriesCollection(1).Name = strLegend .FullSeriesCollection(1).XValues = wksData.Range(wksData.Cells(lngRowA, xPosAxis), wksData.Cells(lngRowZ, xPosAxis)) .FullSeriesCollection(1).Format.Line.ForeColor.RGB = RGB(intR, intG, intB) .FullSeriesCollection(1).Format.Fill.ForeColor.RGB = RGB(intR, intG, intB) .FullSeriesCollection(1).Format.Fill.Transparency = 0.8 ' 新增代码:隐藏内部数据点 .FullSeriesCollection(1).ShowInnerPoints = False .ChartGroups(1).GapWidth = 20 .Parent.Name = "Chart " & strTARGET .HasLegend = True .Legend.Position = xlLegendPositionBottom .HasTitle = True .ChartTitle.Text = strTARGET .Axes(xlValue).HasTitle = True .Axes(xlValue).AxisTitle.Text = "[g/kg_fuel]" .Axes(xlValue).HasMajorGridlines = True .Axes(xlCategory).HasTitle = True .Axes(xlCategory).AxisTitle.Text = strX .Axes(xlCategory).HasMajorGridlines = True End With
你还可以根据需求调整其他箱形图显示属性:
- 隐藏离群点(超出箱须范围的孤立数据点):
FullSeriesCollection(1).ShowOutlierPoints = False - 隐藏均值标记:
FullSeriesCollection(1).ShowMeanMarkers = False - 隐藏均值连线:
FullSeriesCollection(1).ShowMeanLine = False - 隐藏中位数线:
FullSeriesCollection(1).ShowMedianLine = False
内容的提问来源于stack exchange,提问作者Mark
相关产品推荐
相关产品推荐

