06-13-2019 04:32 PM
I'm trying to PlotXY in CVI. I have a graph on the second tab page of my panel, the graph have constant name "GRAPH_SPECTRUM". Here is the test code:
int plotHandle;
double x[100], y[100];
for (i = 0; i < 100; i++)
{
x[i] = 1.00 * i;
y[i] = 0.1 * i * i; // let's try a simple parabola
}
GetPanelHandleFromTabPage (panelHandle, PANEL_TAB, PAGE_TWO, &Tab2PanelHandle);
plotHandle = PlotXY (Tab2PanelHandle, TABPANEL_2_GRAPH_SPECTRUM, x, y, 100, VAL_DOUBLE, VAL_DOUBLE, VAL_FAT_LINE, VAL_EMPTY_SQUARE, VAL_SOLID, 1, VAL_RED);
I'm getting an error "Function PlotXY: The control is not the type expected by the function"
Could anyone help please?
Solved! Go to Solution.
06-13-2019 06:47 PM
I think the problem is in the controlID. If I create the graph by NewCtrl and use the return value as the controlID for the PlotXY then it works. But if I use a controlID of the graph defined in the GUI .h then it does not work and gives that error. Looks like a bug?
06-14-2019 01:59 AM
A problem could be the value of PAGE_TWO macro: GetPanelHandleFromTabPage wants a zero-based index of the page to address, so unless PAGE_TWO = 1 you are getting the handle of the wrong tab page; you get the error since you are addressing a control which appears not to be a graph.
In which page does the dynamically created graph appear?
06-14-2019 06:44 AM
Thanks for the help, Roberto. I have other controls on the second page and they work fine:
SetCtrlVal(Tab2PanelHandle, TABPANEL_2_SCAN_NUMBER, 0);
Anyway, I did a workaround by creating the graph programmatically and it now works fine:
GetPanelHandleFromTabPage (panelHandle, PANEL_TAB, PAGE_TWO, &Tab2PanelHandle);
graphCtrl = NewCtrl (Tab2PanelHandle, CTRL_GRAPH_LS, "", 10, 200);
SetCtrlAttribute (Tab2PanelHandle, graphCtrl, ATTR_HEIGHT, 550);
and so on…………..