|
在作趋势图时会遇到0的情况
有时0值经常就表示没有的情况,如果显示在图表上会引起误解
下面的附件采用VBA对折线图优化使数据出现0的情况时不显示该数据点
Sub 图表数据点美化()
'xunwening 记录
'数据点为“0”或Null值图形不显示
'
'=============================
Dim Ser As Series
Dim i As Long
Dim k As Long
Set Ser = ActiveChart.SeriesCollection(1)
Debug.Print Ser.Points.Count
With Ser.Border
.ColorIndex = 55
.Weight = xlThin
.LineStyle = xlContinuous
End With
With Ser
.MarkerBackgroundColorIndex = 3 '前景颜色
.MarkerForegroundColorIndex = 55 '背景颜色
.MarkerStyle = xlDiamond '样式
.Smooth = False
.MarkerSize = 4 '大小
.Shadow = False '阴影
End With
For i = 1 To Ser.Points.Count
k = i + 1
'判断图表上数据点的值为“0”或Null值
'如果第i点值为空那么必须清除第i点和第i+1点的数据系列格式
If Ser.Values(i) = 0 Then
'清除第i点的:数据系列格式—图案—线型
With Ser.Points(i).Border
.Weight = xlHairline
.LineStyle = xlNone
End With
'清除第i点的:数据系列格式—图案—数据标记
With Ser.Points(i)
'.MarkerBackgroundColorIndex = 3 '前景颜色
'.MarkerForegroundColorIndex = xlAutomatic '背景颜色
.MarkerStyle = xlNone 'xlDiamond '样式
.MarkerSize = 5 '大小
'.Shadow = False
End With
If k = Ser.Points.Count Then Exit For
'清除第i+1点的:数据系列格式—图案—线型
With Ser.Points(k).Border
.Weight = xlHairline
.LineStyle = xlNone
End With
End If
Next i
'=============================
End Sub
折线图美化.rar
(12.82 KB, 下载次数: 137)
[ 本帖最后由 xuwenning 于 2010-5-28 16:33 编辑 ] |
评分
-
1
查看全部评分
-
|