03-08-2007 09:14 AM
03-09-2007 08:47 AM
03-11-2007 01:22 AM
Hi,
I don't want to insert data to a worksheet and then make a chart- there is no problem in that.
I want to write the numbers(data) in cvi and see the chart in excel by using MakeChart function.
There is no example in the cvi samples for that.
I did it manualy by using Series in the chart wizard, I need to know how to do this in Cvi.
03-14-2007 07:02 PM - edited 03-14-2007 07:02 PM
Charts("Chart1").SeriesCollection(1).Values = _
Array(1, 3, 5, 7, 11, 13, 17, 19)
Lets break it down. This is all in the Excel VBA help which ships with Excel.
Charts("Chart1") <- get handle to chart object
.SeriesCollection(1) <- use chart handle and call its method "SeriesCollection" passing it an index of one. Since this is a collection, 1 is used to index the items in its collection. This returns a Series object.
.Values = _
Array(1, 3, 5, 7, 11, 13, 17, 19)
<- Array creates a VB array which is basically a safearray. The Values property (member of the Series object) takes a variant, so VB does the converting for you in the background.
Now lets map that to CVI using the Excel Report toolkit ( C:\Program Files\National Instruments\CVI81\toolslib\activex\excel ) and the Excel 9.0 Wrappers that are included with CVI. I tested this with Excel 2003, which is Excel 11.0. The wrappers work with newer excel versions.
Charts("Chart1")"
.SeriesCollection(1)
sets the Values property
Message Edited by bilalD on 03-14-2007 07:04 PM
03-15-2007 08:01 AM
HI,
Thank you so much for your help, I'm feeling I'm so close but it's still doesn't work .
I'm Getting ERROR in the Excel_ChartSeriesCollection command.
I opened excel and got workbook and worksheet handle like you told me but no luck ,
I'm getting blanck chart inside the Excel.
I think there is a problem with the ExcelRpt_GetEmbeddedChartFromIndex command because there is
ExcelRpt_ChartAddtoWorksheet command to add a chart into excel and get is handle.
I'm using Excel 9.0.
double data[]={5,8,9,12,15};
LPSAFEARRAY safearray;
VARIANT safearrayv;
CAObjHandle Series,chartHandle;
error = CA_Array1DToSafeArray(data,CAVT_DOUBLE,5,&safearray);
error = CA_VariantSetSafeArray(&safearrayv,CAVT_DOUBLE,safearray);
error = ExcelRpt_GetEmbeddedChartFromIndex(worksheet,1,&chartHandle);
error = Excel_ChartSeriesCollection (chartHandle, NULL, CA_VariantInt(1), &Series);
error = Excel_SetProperty(Series,NULL,Excel_SeriesValues,CAVT_VARIANT,safearrayv);
Please Help me........
03-16-2007 01:33 PM
03-18-2007 03:10 PM
Hi patrik,
Thank you so much for your help , it worked.
But I Still have a small problem with the array , if I insert array bigger then 90 I'm getting Error.
Here is the code that i wrote:
double data[100]={
1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0,10.0,11.0,12.0,13.0,14.0,15.0,16.0,17.0,18.0,19.0,20.0,
11.0,12.0,13.0,14.0,15.0,16.0,17.0,18.0,19.0,20.0,21.0,22.0,23.0,24.0,25.0,26.0,27.0,28.0,29.0,30.0,
1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0,10.0,11.0,12.0,13.0,14.0,15.0,16.0,17.0,18.0,19.0,20.0,
1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0,10.0,11.0,12.0,13.0,14.0,15.0,16.0,17.0,18.0,19.0,20.0,
1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0,10.0,11.0,12.0,13.0,14.0,15.0,16.0,17.0,18.0,19.0,20.0};
long dataX[100]={
10,12,14,16,18,10,12,14,16,18,10,12,14,16,18,10,12,14,16,18,
10,12,14,16,18,10,12,14,16,18,10,12,14,16,18,10,12,14,16,18,
10,12,14,16,18,10,12,14,16,18,10,12,14,16,18,10,12,14,16,18,
10,12,14,16,18,10,12,14,16,18,10,12,14,16,18,10,12,14,16,18,
10,12,14,16,18,10,12,14,16,18,10,12,14,16,18,10,12,14,16,18};
LPSAFEARRAY safearray,safearrayX;
VARIANT safearrayv,safearrayXX;
//data array
error = CA_Array1DToSafeArray(data,CAVT_DOUBLE,90,&safearray);
error = CA_VariantSetSafeArray(&safearrayv,CAVT_DOUBLE,safearray);
if (error < 0) goto Error;
//X array
error = CA_Array1DToSafeArray(dataX,CAVT_LONG,90,&safearrayX);
error = CA_VariantSetSafeArray(&safearrayXX,CAVT_LONG,safearrayX);
if (error < 0) goto Error;
//open chart
error = ExcelRpt_ChartAddtoWorksheet (worksheet, 300, 60, 400, 250,&chart);
if (error < 0) goto Error;
//Open Series
error = Excel_ChartSeriesCollection (chart, NULL, CA_DEFAULT_VAL,&Series);
if (error < 0) goto Error;
//Get Series Handle
error = Excel_SeriesCollectionNewSeries(Series,NULL,&SerisHandle);
if (error < 0) goto Error;
//Set data Array
error = Excel_SetProperty(SerisHandle,NULL,Excel_SeriesValues,CAVT_VARIANT,safearrayv);
if (error < 0) goto Error;
//Set X array
error = Excel_SetProperty (SerisHandle, NULL, Excel_SeriesXValues,CAVT_VARIANT, safearrayXX);
if (error < 0) goto Error;
//Set chart Type to line.
error = Excel_SetProperty (chart, NULL, Excel_SeriesChartType,CAVT_LONG, ExcelConst_xlLineMarkers);
if (error < 0) goto Error;
Error:
if (error < 0)
MessagePopup (APP_AUTOMATION_ERR, LAUNCHERR);
return ;
Help , Help , Help
Sruli
03-19-2007 12:48 PM
03-20-2007 02:20 AM
I entered array of 90 to the chart series and then I added more data manualy and it worked.
I think the problem is through Cvi function..
Please see if i am right...
03-20-2007 07:32 AM
I'm sorry, you were right , it is excel problem - i'm loosing it......................
I can't follow your advise because It's alot of graphs and it will take me forever.
I have idea but I need your help.
maybe I will use the Microsoft Graph Chart with the insert object command but i dont know how to insert
and change the graph properties.
what do you think?..do you have a better idea?..
if you agree with mine , It will be great if you send me example..
I realy need to finish this work and the graphs are making me crazy....Please help.....