LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Real Scale Graph

How can i make my graph use a real scale..?
i mean the sides x,y are 1:1 and the whole graph is in real (scaled though) dimensions..
The problem is that i'm using autoscale. so when Xaxis changes the yaxis is not, causing (e.g) a rectangle seem like a square..

Thanks in advance..
0 Kudos
Message 1 of 4
(3,374 Views)
There is no built-in function to sync x and y axis of a graph. You could possibly use GetAxisScalingMode after each plot  function and update accordingly the other axis if the min/max have changed. Or you could disable autoscaling and manually rescale the diagram while plotting depending on the plot dimensions.


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 4
(3,366 Views)

To get you started, here is some code that I have used to set a 1:1 aspect ratio for a graph:

// Reset the aspect ratio of a graph - which may have been autoscaled - to 1:1
// Assume panel handle is held in 'pMain' and the graph control is 'MAIN_GRAPH'.
{
 double xmin, xmax, ymin, ymax;
 int dum1, dum2;
 double ratio1;
 double ratio2;
 
 // Find the current axis ranges
 GetAxisScalingMode(pMain,MAIN_GRAPH,VAL_BOTTOM_XAXIS,&dum1,&xmin,&xmax);
 GetAxisScalingMode(pMain,MAIN_GRAPH,VAL_LEFT_YAXIS,&dum1,&ymin,&ymax);

 // Add a bit to the graph to ensure there is white space around the plots
 xmax+=1.0;
 ymax+=1.0;
 xmin-=1.0;
 ymin-=1.0;

 // Now work out the ratio of x axis to y axis
 ratio1 = (xmax-xmin)/(ymax-ymin);
 
 // Now find out how big the plot area of the graph is in X and Y directions
 GetCtrlAttribute(pMain,MAIN_GRAPH,ATTR_PLOT_AREA_WIDTH,&dum1);
 GetCtrlAttribute(pMain,MAIN_GRAPH,ATTR_PLOT_AREA_HEIGHT,&dum2);
 ratio2 = ((double)dum1)/((double)dum2);
 
 // Need to make ratio1 = ratio2 by adjusting ranges
 if (ratio1<ratio2)
 {
  // Need to expand X area
  double expandval = 0.5*((ratio2/ratio1)-1.0)*(xmax-xmin);
  xmin -= expandval;
  xmax += expandval;
 }
 else
 {
  // Need to expand Y area
  double expandval = 0.5*((ratio1/ratio2)-1.0)*(ymax-ymin);
  ymin -= expandval;
  ymax += expandval;
 }
 
 // Finally, set the new axis ranges
 SetAxisScalingMode(pMain,MAIN_GRAPH,VAL_BOTTOM_XAXIS,VAL_MANUAL,xmin,xmax);
 SetAxisScalingMode(pMain,MAIN_GRAPH,VAL_LEFT_YAXIS,VAL_MANUAL,ymin,ymax);
 
}

--
Martin
Certified CVI Developer
0 Kudos
Message 3 of 4
(3,357 Views)
thanks msaxon but it looks like that your routine didn't work for me as i expected.. i want to be able to use autoscale for both axis and have a 1:1 ratio.. also i've noticed that it wasn't exactly 1:1.. (maybe i have some attributes that you didn't have..) anyway i found the solution..

// Reset the aspect ratio of a graph - which may have been autoscaled - to 1:1
void autoscale(int control)
{
double xmin, xmax, ymin, ymax;
int dum1, dum2;
double ratio1;
double ratio2;

SetAxisScalingMode (panel_handle, control, VAL_XAXIS, VAL_AUTOSCALE, 1,2);//force graph to auto fit the plot.. (min,max value is random.. maybe there's a better way to do it.. it works though..)
SetAxisScalingMode (panel_handle, control, VAL_LEFT_YAXIS,VAL_AUTOSCALE, 1, 2);

// Find the current axis ranges
GetAxisRange (panel_handle, control, &dum1, &xmin, &xmax, &dum2, &ymin,&ymax);
ratio1 = (xmax-xmin)/(ymax-ymin);

// Now find out how big the plot area of the graph is in X and Y directions
GetCtrlAttribute(panel_handle,control,ATTR_PLOT_AREA_WIDTH,&dum1);
GetCtrlAttribute(panel_handle,control,ATTR_PLOT_AREA_HEIGHT,&dum2);
ratio2 = ((double)dum1)/((double)dum2);

if (ratio1>ratio2)
SetAxisScalingMode (panel_handle, control, VAL_LEFT_YAXIS, VAL_MANUAL, xmin/ratio2,xmax/ratio2); //scale Yaxis according to Xaxis..
else
SetAxisScalingMode (panel_handle, control, VAL_XAXIS, VAL_MANUAL, ymin*ratio2,ymax*ratio2);//Scale Xaxis according to Yaxis
}

Message Edited by karpa on 06-24-2008 05:31 AM
0 Kudos
Message 4 of 4
(3,338 Views)