|
其实您已经做得差不多了,但是UCL和LCL的误差线设定有点问题而已。
请指示观察我图表中误差线的设定就能明白了。
(辅助1和辅助2都是分别用来设定误差线的)
另:关于超出UCL和LCL范围的CL的红点表示,则是通过辅助3来完成,
说白了就是在图中加一条线,但只取超出范围的数。
超出部分的标签显示问题,因为辅助3中的数据是实际数据,而不是所想显示的1,
故通过辅助4的数据来完成显示,具体显示是通过标签替换工具来完成。
标签替换工具为一个VBA宏,具体代码如下;- Sub DataLableChange()
- Dim I%, LblCnt%, iRows%, iCols%
- Dim shnm$, sn$, Msg$
- Dim rngLbl As Range
- Select Case TypeName(Selection)
- Case "DataLabel"
- sn = Selection.Parent.Parent.Name
- Case "DataLabels"
- sn = Selection.Parent.Name
- Case "Series"
- sn = Selection.Name
- Case Else
- MsgBox "请先选中一个系列或系列数据标签再开始使用工具.", vbOKOnly, "提示:选中系列或系列数据标签"
- Exit Sub
- End Select
- Err.Clear: On Error Resume Next
- Set rngLbl = Application.InputBox("请输入标签所引用的区域,可以用鼠标选择区域.", "标签的引用区域", , , , , , 8)
- Err.Clear: On Error GoTo 0
- If rngLbl Is Nothing Then Exit Sub
- iRows = rngLbl.Rows.Count
- iCols = rngLbl.Columns.Count
- LblCnt = ActiveChart.SeriesCollection(sn).Points.Count
- shnm = rngLbl.Parent.Name
- If Application.Max(iRows, iCols) < ActiveChart.SeriesCollection(sn).Points.Count Then
- Msg = MsgBox("你所选择的引用单元格小于该系列需要的个数," & Chr(10) & " 选择""Yes""继续," & Chr(10) & " 选择""No""停止执行.", vbYesNo, "引用单元格数量不够")
- Select Case Msg
- Case vbYes
- LblCnt = Application.Max(iRows, iCols)
- Case vbNo
- Exit Sub
- End Select
- End If
- Application.ScreenUpdating = False
- On Error Resume Next
- With ActiveChart.SeriesCollection(sn)
- For I = 1 To LblCnt
- Err.Clear
- .Points(I).ApplyDataLabels
- If Err.Number = 0 Then
- If iRows > iCols Then
- .Points(I).DataLabel.Text = "='" & shnm & "'!" & rngLbl.Cells(I, 1).Resize(1, iCols).Address(ReferenceStyle:=xlR1C1)
- Else
- .Points(I).DataLabel.Text = "='" & shnm & "'!" & rngLbl.Cells(1, I).Resize(iRows, 1).Address(ReferenceStyle:=xlR1C1)
- End If
- End If
- Next
- End With
- Err.Clear: On Error GoTo 0
- Application.ScreenUpdating = True
- End Sub
复制代码 |
|