LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

CVI PlotY: How to center the X-axis at zero?

Solved!
Go to solution

Dear colleagues,

I have a simple (maybe stupid) question about graphs in NI CVI.

My graph is “symmetrical” (it’s a simple PlotY graph where the X-axis is shifted by an offset), and I would prefer to have zero displayed in the middle.

Which attribute can I use to adjust this:

graph.PNG

I tried adding a cursor at the zero position and played around with the attributes all morning, but that didn’t help.

Any idea how I can fix this and make it look perfect (in generic way, the range could be differ from run to run)?

zero.gif

Thank you in advance.

0 Kudos
Message 1 of 6
(599 Views)

It appears as if your graph is in autoscale mode in the X-Axis. If this is true, then you could try setting it to manual mode, calculate the appropriate range and set it to the axis before plotting the values.



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?
0 Kudos
Message 2 of 6
(568 Views)

Looking at your first picture, I suppose the value of 2 in the middle depends on some rounding on actual values. You could probably fix it with this code:

// Calculate actual range
MaxMin1D (array, nElements, &maxVal, &maxIdx, &minVal, &minIdx);

// Round to the next group of ten
max = Max (ABS_VAL (minVal), maxVal);
max = (ceil (max / 10.0)) * 10.0;

// Apply the range to the graph X-axis
SetAxisScalingMode (panelHandle, PANEL_GRAPH, VAL_BOTTOM_XAXIS, VAL_MANUAL, -max, max);

 

Max and ABS_VAL macros are part of the Programmer's Toolbox, defined in toolbox.h.



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?
0 Kudos
Message 3 of 6
(501 Views)

@RobertoBozzolo wrote:

Looking at your first picture, I suppose the value of 2 in the middle depends on some rounding on actual values. You could probably fix it with this code:

// Calculate actual range
MaxMin1D (array, nElements, &maxVal, &maxIdx, &minVal, &minIdx);

// Round to the next group of ten
max = Max (ABS_VAL (minVal), maxVal);
max = (ceil (max / 10.0)) * 10.0;

// Apply the range to the graph X-axis
SetAxisScalingMode (panelHandle, PANEL_GRAPH, VAL_BOTTOM_XAXIS, VAL_MANUAL, -max, max);

 

Max and ABS_VAL macros are part of the Programmer's Toolbox, defined in toolbox.h.


Yes, I've already tried rounding to the next multiple of ten, and sometimes it works (though not always; I think I've seen the same behavior even with rounding). I'll check a few different scenarios.
0 Kudos
Message 4 of 6
(491 Views)
Solution
Accepted by topic author Andrey_Dmitriev

I asked google AI how to set the x markers 

void InitializeSymmetricGraph(int panel, int control, double n) {
    SetAxisScalingMode (panel, control, VAL_BOTTOM_XAXIS, VAL_MANUAL, -n, n);
    // 10 Intervals create 11 ticks, 6th tick is at 0.0
    SetCtrlAttribute (panel, control, ATTR_XDIVISIONS, 10); 
}

Disclaimer: I have no LabWindwos/CVI installation, so I can not verifiy if this will work or if these parameters are real. I had to ask AI if ATTR_XNUM_DIVISIONS is correct, which obviously is not.

At least there is a help entry for ATTR_XDIVISIONS: https://www.ni.com/docs/de-DE/bundle/labwindows-cvi/page/cvi/uiref/cviattrxdivisions.htm 

Message 5 of 6
(469 Views)

@UliB wrote:

I asked google AI how to set the x markers 

void InitializeSymmetricGraph(int panel, int control, double n) {
    SetAxisScalingMode (panel, control, VAL_BOTTOM_XAXIS, VAL_MANUAL, -n, n);
    // 10 Intervals create 11 ticks, 6th tick is at 0.0
    SetCtrlAttribute (panel, control, ATTR_XDIVISIONS, 10); 
}

Disclaimer: I have no LabWindwos/CVI installation, so I can not verifiy if this will work or if these parameters are real. I had to ask AI if ATTR_XNUM_DIVISIONS is correct, which obviously is not.

At least there is a help entry for ATTR_XDIVISIONS: https://www.ni.com/docs/de-DE/bundle/labwindows-cvi/page/cvi/uiref/cviattrxdivisions.htm 


Yes, thank you, that does the job. It is exactly the attribute I was looking for. I was sure something like it existed for the scale, but I overlooked the Divisions setting. Sometimes I can't see the forest for the trees:

 

graph.gif

0 Kudos
Message 6 of 6
(434 Views)