请问如何在CVI中设定excel图表的横坐标
时间:12-13
整理:3721RD
点击:
我在CVI中用activex控制excel。
先传递数据,然后用这些数据画一个xy图。
现在的问题是能够将图画出来,但是图的横坐标是缺省的行数,不是我想要得
一个区域里的数据,用什么函数将一个区域的数据设为x轴的数据?
下面是相关的程序。
谢谢!
// Open new Range for Worksheet
error = CA_VariantSetCString (&MyCellRangeV, EXCEL_ARRAY_OF_CELLS1);
error = Excel_WorksheetRange (ExcelWorksheetHandle, NULL, MyCellRangeV, CA_DEFAULT_VAL, &ExcelRangeHandle);
CA_VariantClear(&MyCellRangeV);
if (error<0) goto Error;
// Open new Range for Worksheet
error = CA_VariantSetCString (&MyCellRangeV2, EXCEL_ARRAY_OF_CELLS2);
error = Excel_WorksheetRange (ExcelWorksheetHandle, NULL, MyCellRangeV2, CA_DEFAULT_VAL, &ExcelRangeHandle2);
CA_VariantClear(&MyCellRangeV2);
if (error<0) goto Error;
// Open new Chart Collection for Worksheet
status = Excel_WorksheetChartObjects (ExcelWorksheetHandle, NULL, CA_DEFAULT_VAL, &ExcelChartsHandle);
if (status<0) goto Error;
// Create new chart
status = Excel_ChartObjectsAdd (ExcelChartsHandle, NULL, 175.0, 175.0,
300.0, 200.0, &ExcelChartObjHandle);
if (status<0) goto Error;
status = Excel_GetProperty (ExcelChartObjHandle, NULL, Excel_ChartObjectChart, CAVT_OBJHANDLE, &ExcelChartHandle);
if (status<0) goto Error;
// Use Chart Wizard to setup Chart
status = CA_VariantSetCString (&MyVariant, "Chart #1");
status = CA_GetDispatchFromObjHandle (ExcelRangeHandle, &MyDispatch); // Get dispatch for range
status = Excel_ChartChartWizard (ExcelChartHandle, &ErrorInfo,
CA_VariantDispatch (MyDispatch),
CA_VariantLong(ExcelConst_xlXYScatter),
CA_VariantInt(2),
CA_VariantInt(ExcelConst_xlColumns),
CA_DEFAULT_VAL,
CA_DEFAULT_VAL,
CA_DEFAULT_VAL,
MyVariant,
CA_DEFAULT_VAL,
CA_DEFAULT_VAL,
CA_DEFAULT_VAL);
status =Excel_ChartSetChartType (ExcelChartHandle,&ErrorInfo,ExcelConst_xlXYScatterLinesNoMarkers);
.135
先传递数据,然后用这些数据画一个xy图。
现在的问题是能够将图画出来,但是图的横坐标是缺省的行数,不是我想要得
一个区域里的数据,用什么函数将一个区域的数据设为x轴的数据?
下面是相关的程序。
谢谢!
// Open new Range for Worksheet
error = CA_VariantSetCString (&MyCellRangeV, EXCEL_ARRAY_OF_CELLS1);
error = Excel_WorksheetRange (ExcelWorksheetHandle, NULL, MyCellRangeV, CA_DEFAULT_VAL, &ExcelRangeHandle);
CA_VariantClear(&MyCellRangeV);
if (error<0) goto Error;
// Open new Range for Worksheet
error = CA_VariantSetCString (&MyCellRangeV2, EXCEL_ARRAY_OF_CELLS2);
error = Excel_WorksheetRange (ExcelWorksheetHandle, NULL, MyCellRangeV2, CA_DEFAULT_VAL, &ExcelRangeHandle2);
CA_VariantClear(&MyCellRangeV2);
if (error<0) goto Error;
// Open new Chart Collection for Worksheet
status = Excel_WorksheetChartObjects (ExcelWorksheetHandle, NULL, CA_DEFAULT_VAL, &ExcelChartsHandle);
if (status<0) goto Error;
// Create new chart
status = Excel_ChartObjectsAdd (ExcelChartsHandle, NULL, 175.0, 175.0,
300.0, 200.0, &ExcelChartObjHandle);
if (status<0) goto Error;
status = Excel_GetProperty (ExcelChartObjHandle, NULL, Excel_ChartObjectChart, CAVT_OBJHANDLE, &ExcelChartHandle);
if (status<0) goto Error;
// Use Chart Wizard to setup Chart
status = CA_VariantSetCString (&MyVariant, "Chart #1");
status = CA_GetDispatchFromObjHandle (ExcelRangeHandle, &MyDispatch); // Get dispatch for range
status = Excel_ChartChartWizard (ExcelChartHandle, &ErrorInfo,
CA_VariantDispatch (MyDispatch),
CA_VariantLong(ExcelConst_xlXYScatter),
CA_VariantInt(2),
CA_VariantInt(ExcelConst_xlColumns),
CA_DEFAULT_VAL,
CA_DEFAULT_VAL,
CA_DEFAULT_VAL,
MyVariant,
CA_DEFAULT_VAL,
CA_DEFAULT_VAL,
CA_DEFAULT_VAL);
status =Excel_ChartSetChartType (ExcelChartHandle,&ErrorInfo,ExcelConst_xlXYScatterLinesNoMarkers);
.135