LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

How to create Excel chart with series?

Hi all,
I'm trying to create a chart with series (multiple values for each chart column). I've managed to do so, only when the input parameters are read from an array in the memory. However, I want to create the chart with input from the same excel file (It can be done when using the Excel application) , with reference to the desired cells.
I'm using the code below, the basic idea was taken from previous post in this forum. I think I should be changing the last line in the code to create reference to cells within the same file.
I already tried with no success to copy the range as appeared in the Excel application when creating charts - "Sheet1!$A$1:$A$10" , then placing it in the VARIANT with the CA_VariantSetCString function.
 
 
 
Code:
-----------------------------------------
double data[] = {1,2,3,4,5,6};
LPSAFEARRAY safearray;
VARIANT     safearrayV;
CAObjHandle Series;
ExcelObj_Series SeriesHandle;
EXCEL_APPLICATION_t ptr;
HRESULT ExecutionResult;
CAObjHandle Chart_Handle;
ERRORINFO ErrorInfo;
.
.
.
 
CA_Array1DToSafeArray (data, CAVT_DOUBLE, 6, &safearray);
CA_VariantSetSafeArray (&safearrayV, CAVT_DOUBLE, safearray);

ExecutionResult = ExcelRpt_ChartNew (ptr.ExcelWorkbookHandle, -1, &Chart_Handle);
ExecutionResult = Excel_ChartSeriesCollection(Chart_Handle,NULL,CA_DEFAULT_VAL,&Series);
ExecutionResult = Excel_SeriesCollectionNewSeries (Series, NULL, &SeriesHandle);
// This is where I put the series values:
ExecutionResult = Excel_SetProperty (SeriesHandle, &ErrorInfo, Excel_SeriesValues, CAVT_VARIANT, safearrayV);

 
0 Kudos
Message 1 of 3
(3,380 Views)

Hi IdoZoe,

I never tried using series and references in Excel, but looking at your code I noticed that you used 1DArray excel functions. Since I have faced a problem with 1D arrays I suggest you read this discussion since you may possibly be facing the same or similar problem. Briefly: does your code work if instead of using a 1D array you use a 2D array with 1 as the second dimension (that is: a matrix n rows x 1 column) ?



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
Message 2 of 3
(3,372 Views)

Did you ever discover a way to do this?

0 Kudos
Message 3 of 3
(2,681 Views)