LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to use excell template with line chart

I have created an Excell template with a line chart . I want to pass x,y data to this chart where the number of xy data points varies from run to run. When creating the chart the source data points to a specific number of rows for every execution. How can I set this up so that the number of rows of xy data plotted is equal to that which is loaded to the spreadsheet? I am using the Excell functions via LabView 7.1
0 Kudos
Message 1 of 5
(3,631 Views)
Here is the code to change the data source of a graph in Excel using VBA:

' range is in the format: A2:C30
' the chart title will be different
' the sheet name can be fixed or passed in as a parameter
'
Sub SetChart()
ActiveSheet.ChartObjects("Chart 1").Activate
ActiveChart.ChartType = xlLineMarkers
ActiveChart.SetSourceData Source:=Sheets("Sheet1").Range("C15:D18"), PlotBy:= _
xlColumns
End Sub

Modify to your needs and put it in the template excel sheet. Call the macro in labview (I believe the command is RUN), give the macro name and any parameters.

-Joe
0 Kudos
Message 2 of 5
(3,621 Views)
Joe,
Sorry I am late on getting to this but have been trying hard to get it to work. I have no VB experience so am have some problems. Perhaps you can help. So far I have created an excel file (file.xls) that contains a chart that I want to pass data to from my LabView app. I have created a macro (In this excel file) following your example That looks like this:
Sub ChartData()
ActiveSheet.ChartObjects("Sheet1").Activate
ActiveChart.ChartType=xlLineMarkers
ActiveChart.SetSourceData Source:=Sheets("Sheet1").Range("F3:L12"),PlotBy:=x1Columns
End Sub
I use the Report Generation vi's to send the data table and other frills and run the macro the same way. I keep getting the error "run time error '1004' Unable to get the ChartObjects property of the worksheet class"
What I am hoping to eventually do is pass arguments for the source data ranges as the amount of data will vary with each instance. I don't know how this is done either so if you could please comment on that also.
Thanks
Fran
0 Kudos
Message 3 of 5
(3,587 Views)
Fran, first of all, it is "Chart 1" and not "Sheet 1". "Chart 1" is the name for the first chart on a worksheet. Secondly, the parameter for "PlotBy" is "xlColumns" (l is the lowercase L and not digit 1).

I've included an example below, you may need to make some modification to fit your needs.

-Joe
0 Kudos
Message 4 of 5
(3,578 Views)
Thanks Joe!!
Very specific and clear. Your effort is very much appreciated. All works well.
There is a minor detail that perhaps you could comment on that I'm sure that better understanding of the chart structure would solve. I pass a multi-column array to the excel template for display purposes. Col 1 are x-axis labels and col 7 are the y data points. I pass a source range which includes this displayed table and use the xlLineMarkers chart type. This chart displays all of the data where all I want is col 1 as the x-axis labels and col 7 as the data. The source data popup on the chart shows 7 series where I only want one of them to display. I can't seem to set the VBA right to do this.
Many Thanks Again,
Fran
0 Kudos
Message 5 of 5
(3,563 Views)