我正在开发一个基于 Excel 的模拟器,可以运行 1000 次特定测试。每个测试的结果是两个坐标。这些坐标被写入一个范围。然后我根据该范围创建一个 XY 散点图。
我现在想做的是循环遍历图形的 1000 个点,并根据该点的 X 和 Y 坐标更改该点的颜色。具体来说,我想取 X Mod (Half Max X) 和 Y Mod (Half Max Y),以创建颜色强度会随着靠近图表中间的点而增加的效果。
我要使用的代码如下:
Temp = "'" + FirstCalcs.Name + "'!" + FirstCalcs.Cells(SOWD + 3, 2).Address + ":" + FirstCalcs.Cells(SOWD + 3, NumOfTests + 1).Address
Temp2 = "'" + FirstCalcs.Name + "'!" + FirstCalcs.Cells(SOWD + 4, 2).Address + ":" + FirstCalcs.Cells(SOWD + 4, NumOfTests + 1).Address
Set chtChart = Charts.Add
With chtChart
Do Until .SeriesCollection.Count = 1 ' remove extra series, which Excel spawns like rabbits, for some reason
.SeriesCollection(1).Delete
Loop
.Name = Institution + " summary"
.ChartType = xlXYScatter
'Link to the source data range.
'.SetSourceData Source:=FirstCalcs.Range(Temp)
.SeriesCollection(1).Values = Temp2
.SeriesCollection(1).XValues = Temp
For Each pts In .SeriesCollection(1).Points
.Format.Fill.Solid
'The next line is what I can't figure out
.MarkerBackgroundColor = RGB(XFunctionOf(.pts.XCoor), YFunctionOf(.pts.YCoor), 128)
.MarkerStyle = xlMarkerStyleDiamond
.MarkerSize = 10
End With
Next i
.HasTitle = True
.ChartTitle.Text = "Summary"
.Axes(xlCategory, xlPrimary).HasTitle = True
.Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "T"
.Axes(xlValue, xlPrimary).HasTitle = True
.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "Time before T achieved"
.HasLegend = False
End With
但是我无法找到一种方法来获取 X AND Y 值以便对它们执行必要的功能。我可以根据点本身的数量(1 到 1000)改变颜色,但这不是我想要做的 - 颜色是每个点的 X、Y 坐标的函数。值得一提的是,X 和 Y 坐标的范围都是可变的,即测试不会每次返回相同比例的结果。
任何帮助将不胜感激,并在此先感谢您。