简体   繁体   English

如何使用 VB 将数组应用于 excel 中的图形数据系列

[英]How to apply an array to a graph data series in excel using VB

I am trying to create a number of small graphs on a single page and use data I have in an array.我正在尝试在单个页面上创建许多小图并使用数组中的数据。 I have created 2 vectors as Series1 & Series2 (defined as Dim Series1(366) as double ) and want to use as my data input.我创建了 2 个向量作为 Series1 和 Series2 (定义为Dim Series1(366) as double )并希望用作我的数据输入。 At the moment I write the data out to a worksheet and use the 'Range' (eg"A3:A369") to create the series.目前,我将数据写入工作表并使用“范围”(例如“A3:A369”)创建系列。 The following code below works.下面的代码有效。 I tried several alternatives with no success - examples我尝试了几种替代方案但均未成功-示例

' With.SeriesCollection(1)'

'.Values = Series1

' End With

' ActiveChart.SeriesCollection(1).Add Source:=Series1

' ActiveChart.SeriesCollection.Add Source:=series2

 If iChartObject = 5 Then
    With ActiveSheet.ChartObjects.Add(Left:=1000, Width:=200, Top:=100, Height:=200)
        .Chart.ChartType = my_charttype
        .Chart.HasTitle = True
        .Chart.ChartTitle.Text = ChartTitle
    End With
End If
ActiveSheet.ChartObjects(iChartObject).Activate
ActiveChart.ChartArea.Select
str1 = Trim(str(lg_start))
str2 = Trim(str(lg_end))
str3 = "B" + str1 + ":B" + str2
str4 = ActiveSheet.Name
str5 = ActiveChart.Name
ActiveChart.SeriesCollection.Add Source:=ActiveSheet.Range(str3)
str3 = "C" + str1 + ":C" + str2
ActiveChart.SeriesCollection.Add Source:=ActiveSheet.Range(str3)

Any help appreciated任何帮助表示赞赏

I solved this problem (almost) using the code below.我使用下面的代码(几乎)解决了这个问题。 However I am now left with ZEROs causing the following.但是,我现在只剩下零,导致以下情况。 在此处输入图像描述 I just want to see the area of the plot - ie no zeros.我只想看看 plot 的区域 - 即没有零。 Series 1 &2 are defined as 'double'系列 1 &2 被定义为“双”

For Each ch In ActiveSheet.ChartObjects
            ch.Chart.SeriesCollection.NewSeries
            ch.Chart.SeriesCollection(1).Values = Series1
            ch.Chart.SeriesCollection.NewSeries
            ch.Chart.SeriesCollection(2).Values = Series2
    Next

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

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