Does anyone know how to use "ActiveX Microsoft Office Excel Chart" from CVI 7.0? I tried with following code but it did not draw anything.
HRESULT MakeChartInExcelActivexCtrl(void)
{
HRESULT error = 0;
char szErrMsg[256];
//
// Create a new chart with its own worksheet
// ExcelRpt_ChartNew(workbookHandle,-1,&chartsheetHandle);
//
SetWaitCursor (1);
//
// Open new Range for Worksheet
//
error = CA_VariantSetCString (&MyCellRangeV, EXCEL_ARRAY_OF_CELLS);
error = Excel_WorksheetRange (ExcelWorksheetHandle, NULL, MyCellRangeV, CA_DEFAULT_VAL, &ExcelRangeHandle);
CA_VariantClear(&MyCellRangeV);
if (error<0)
{
CA_GetAutomationErrorString(error, szErrMsg, sizeof(szErrMsg) );
goto Error;
}
error = Excel_GetProperty (excelChart, NULL, Excel_WindowActiveChart, CAVT_OBJHANDLE, &ExcelChartHandle);
if (error<0)
{
CA_GetAutomationErrorString(error, szErrMsg, sizeof(szErrMsg) );
goto Error;
}
//
// Create a XY scatter chart using the data we wrote to the worksheet as its data source.
//
error = ExcelRpt_ChartWizard(ExcelChartHandle, ExcelWorksheetHandle, EXCEL_ARRAY_OF_CELLS,
ExRConst_GalleryXYScatter, ExRConst_Columns, 0, 0, 0, 0, "Filtered Data Chart", "",
"Weather Data", NULL);
if (error<0)
{
CA_GetAutomationErrorString(error, szErrMsg, sizeof(szErrMsg) );
goto Error;
}
//
// Change the plot lines to not display markers and smooth out
// the plot lines. This is one of the plot styles available in Excel.
//
error = ExcelRpt_SetChartAttribute (ExcelChartHandle, ER_CH_ATTR_CHART_TYPE, ExRConst_XYScatterSmoothNoMarkers);
if (error<0)
{
CA_GetAutomationErrorString(status, szErrMsg, sizeof(szErrMsg) );
goto Error;
}
Error:
SetWaitCursor (0);
CA_VariantClear(&MyCellRangeV);
CA_VariantClear(&MyVariant);
ClearObjHandle (&ExcelRangeHandle);
ClearObjHandle (&ExcelChartHandle);
ClearObjHandle (&ExcelChartObjHandle);
ClearObjHandle (&ExcelChartsHandle);
if (error < 0)
ReportAppAutomationError (error);
return 0;
}