简体   繁体   English

更改图表excel VBA中的点颜色

[英]Change the Point Color in chart excel VBA

I have this chart in which if any point in graphs exceeds specific limit then its color should change. 我有这个图表,如果图表中的任何点超过特定限制,那么它的颜色应该改变。

在此输入图像描述


can anyone suggest me how to get the chart in VBA and then apply this kind of condition eg i want to change the color of highest point in the above graph . 谁能建议我如何在VBA中获取图表然后应用这种条件,例如我想要更改上图中最高点的颜色。 Any help would be highly appreciated. 任何帮助将受到高度赞赏。

Using: ActiveWorkbook.Sheets("Sheet1").ChartObjects("Chart1").Chart.SeriesCollection(1) 使用: ActiveWorkbook.Sheets("Sheet1").ChartObjects("Chart1").Chart.SeriesCollection(1)

Color of each point is .Points(PointNumber).Interior.Color 每个点的颜色是.Points(PointNumber).Interior.Color

The number of points you have to cycle though is .Points.Count 你必须循环的点数是.Points.Count

The value of each point is .Points(PointNumber).Value 每个点的值是.Points(PointNumber).Value

colors of the markers themselves (Applies only to line, scatter, and radar charts): 标记本身的颜色(仅适用于直线,散点图和雷达图):

.Points(PointNumber).MarkerBackgroundColor = RGB(0,255,0)    ' green
.Points(PointNumber).MarkerForegroundColor = RGB(255,0,0)    ' red
.Points(PointNumber).MarkerStyle = xlMarkerStyleCircle ' change the shape

Let's take another approach, which does not require any code. 让我们采取另一种方法,不需要任何代码。

Assume your data is in columns A (sequence number or time) and B value, starting in A2 and B2, since your labels are in A1 and B1. 假设您的数据位于A列(序列号或时间)和B值中,从A2和B2开始,因为您的标签位于A1和B1中。 We'll add a series to the chart that includes any deviant values from column B. This series will draw a marker in front of any deviant points so the original point will still be present, and instead of reformatting this point the new series displays a point. 我们将在图表中添加一个系列,其中包括B列中的任何偏差值。此系列将在任何偏离点前面绘制一个标记,以便原始点仍然存在,而不是重新格式化此点,新系列显示点。

In cell C1, enter "Deviant". 在单元格C1中,输入“Deviant”。

In Cell C2, enter a formula that detects a deviant point, something like: 在单元格C2中,输入检测偏离点的公式,例如:

=IF(AND(B2>upperlimit,B2 = IF(AND(B2> UPPERLIMIT,B2

This puts the value into column C if column B exceeds upper and lower limits, otherwise it puts #N/A into column C, #N/A will not result in a plotted point. 如果列B超出上限和下限,则将值放入列C,否则将#N / A置于列C中,#N / A将不会产生绘制点。

Copy the data in column C, select the chart, and Paste Special as a new series. 复制C列中的数据,选择图表,并将特殊粘贴作为新系列。 Format this series to have no line and whatever glaring marker you want to use to indicate an out of control point. 将此系列格式化为没有线条以及您想要用来指示失控点的任何明亮标记。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM