简体   繁体   English

如何使用二维数组 plot VBA Excel 中的图形?

[英]How do you use a two dimensional array to plot a graph in VBA Excel?

I am currently trying to create a dynamic graphing code that reads in 5 arrays and plots them on a scatter line graph.我目前正在尝试创建一个动态图形代码,该代码读取 5 arrays 并将它们绘制在散点图上。 I have made the code and read in the 5 arrays.我已经编写了代码并阅读了 5 arrays。

I do not know how to apply the data that I have to plot in Excel.我不知道如何将我拥有的数据应用到 Excel 中的 plot。 I am accomplishing this task in a function.我正在 function 中完成这项任务。 Here is what I have currently:这是我目前拥有的:

Function Graph(ByRef int1 As Variant, ByRef int2 As Variant, ByRef int3 As Variant, _
               ByRef int4 As Variant, ByRef int5 As Variant)

Dim c As Chart
Dim srs As Series
Dim xValues As Variant
Dim yValues As Variant

Set c = ActiveChart
'Set srs = cht.SeriesCollection.NewSeries

xValues = Application.Index(int1, 0, 1)
yValues = Application.Index(int1, 0, 2)

With ActiveChart.SeriesCollection
    .xValues = xValues
    .Values = yValues
End With

End Function

I am trying to use a previously existing graph.我正在尝试使用以前存在的图表。 The code needs to be able to use the currently selected graph and plot the data as indicated.代码需要能够使用当前选择的图形和 plot 所示的数据。

Let me know if you need any additional information.如果您需要任何其他信息,请告诉我。

Additional information: I am starting with a blank graph which will accept the arrays as series information (which will in turn populate the graph).附加信息:我从一个空白图表开始,它将接受 arrays 作为系列信息(依次填充图表)。 If it is easier, I could use VBA to create a chart.如果更简单,我可以使用 VBA 创建图表。 I am trying to avoid having to edit the series ranges by hand.我试图避免手动编辑系列范围。 I am trying to avoid this because Excel graphs "blank cells" controlled by an equation.我试图避免这种情况,因为 Excel 绘制由方程式控制的“空白单元格”。 I have tried making graphs with large series ranges, but Excel graphs all values.我尝试制作具有大系列范围的图表,但 Excel 绘制所有值。 Excel绘制“空白单元格”

This is even considering the check box that says do not graph blank cells.这甚至考虑了说不要绘制空白单元格的复选框。

I have a main function that reads in values and handles the main code.我有一个主要的 function 读取值并处理主要代码。 I am going to tie this macro to a button embedded in the spreadsheet.我将把这个宏绑定到电子表格中嵌入的一个按钮。

Something like this:像这样的东西:

With ActiveChart.SeriesCollection.NewSeries
    .xValues = xValues
    .Values = yValues
End With

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

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