From 04:00 PM CDT – 08:00 PM CDT (09:00 PM UTC – 01:00 AM UTC) Tuesday, April 16, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

XY graph X-axis caption name centering

Solved!
Go to solution

Trying to make a graph vi that I can programmatically use to generate a bar plot with different colors for each variable, and centered variable names lining up with the plot tics.  Modifying code from Crabman and Ben, I've been able to kludge something together that approximates workable code.  Of note, the code allows varying numbers of input variables to be graphed.

 

The challenge has been to overlay the variable names and line them up as needed.  There is a character size conversion going on that I do not understand in terms of how formatting such as "7.62s" generates the required left-side whitespace padding to center the variable names underneath the tics.  If I subtract  the caption name length from the inter tic spacing and divide by 2 to approximate the needed whitespace padding, it does not offset the need distance.  Dividing by 3.7 is much better.  Forcing 9 into the string format, a la, "9.62s" seems to work best--but this is a bit off when adding more variables.

 

Seems like there should be a way to accomplish this in the XY graph vi itself, but I haven't figured that out.  Would appreciate help on understanding the character spacing issue for font sets that have variable character sizes--which really is't the issue here--that as a string length need to be offset appropriately in a 2D Picture control . . . to provide the correct XY Graph overlay.

 

Thanks!

0 Kudos
Message 1 of 9
(2,096 Views)

I haven't examined your code, but since you know the XY values, there's a simple way of placing text there - You can use the XY to Coords method to get the coords and then use the position of the plot area to offset it correctly. Note that these are both pane coordinates, which is why you need the offset.

 

Example_VI


___________________
Try to take over the world!
Message 2 of 9
(2,021 Views)

Dear tst:

 

Appreciate the vi.  It does move the plot area text around.  (I couldn't figure out how you got the "PlotAreaPos" Property Node, but just used position.)

 

Nonetheless, am trying to move the bar plot captions around such that they line up consistently with the tic marks.

Download All
0 Kudos
Message 3 of 9
(1,978 Views)

Ah, I didn't realize you were talking about the text labels on the scale. Since you didn't attach an actual VI (which I would suggest backsaving to allow people with older versions to open), it's much harder to understand what's going on.

 

I'm assuming you have a picture control on top of the X scale and that's where you're drawing the names. I would suggest that you could use the method I showed to get the positions for your text and also draw the tick marks.

 

One option would be to hide the X scale and draw your fake scale on top of the graph, using the front plot image, but that would make it tricky with the Y scale. The other option is to place the image over the X scale, as you did. You can use the method I used to get the pane coordinates and then use the picture control's position to translate that to the picture coordinates and you can draw the text centered. You're right that I used a private method (that's what the brown color of the property node indicates) to get the offset, but the same data exists in the Plot Area Bounds property, which isn't private.

 

Note that if you wanted to make this generic, you would have to also move and resize the picture control around, get the bottom value of the Y scale to decide where to place the X scale vertically, etc.


___________________
Try to take over the world!
Message 4 of 9
(1,951 Views)

Dear tst:

 

Appreciate the additional information.  I saved the vi in LV 2012 as a zip file.

 

Will try to extract the PlotAreaPosition from PlotAreaBounds as you suggest.

 

Apart from being able to modify the XY Graph.vi directly to show captions below the tic marks, I am also confused by the text padding formatting that is showing up in my picture overlay.  If you run the code with Divisor = 2, then 3, then force 9 into the "%9.62s", you will see what I cannot figure out.  Fixing this would solve the problem of entering names of different sizes and having the padding be inconsistent in terms of centering the captions underneath the tics.

 

Regarding the "PlotAreaPosition" PN to pull this out, should I be following the example

"Creating Property Nodes to Access Private Class Data in LabVIEW"?

https://www.youtube.com/watch?v=a9udwYUsPng

Obviously, you have mastered a number of methods to achieve this!

 

Thanks,

Bill

0 Kudos
Message 5 of 9
(1,927 Views)

Maybe the advanced plotting toolkit is something to consider. It has the option to create custom labels.

 

https://www.ni.com/nl-nl/support/downloads/tools-network/download.advanced-plotting-toolkit.html#372...

 

Message 6 of 9
(1,917 Views)

Hi Ramon:

That toolkit is impressive!

Thank you so much for suggesting this,

Bill

0 Kudos
Message 7 of 9
(1,908 Views)
Solution
Accepted by wjdwyer

I can't say I understand all of your code for calculating the width and where it could wrong, but I would say it's too complicated anyway - instead of calculating where the left should be, you could just use the alignment input on the VI, which allows you to use center justification on the text:

 

Graph_X_Names_BD.png

 

Note that this also draws the tick marks and that it's slightly off. You could move it manually, but to do it in code you would have to account for the border of the picture control.

 

You could also look at the picture plots palette, but something like the toolkit linked above would probably give you nicer results.

 

Oh, and you might want to vote for this:

https://forums.ni.com/t5/LabVIEW-Idea-Exchange/Allow-text-labels-for-graph-scales/idi-p/921601


___________________
Try to take over the world!
Message 8 of 9
(1,889 Views)

Dear tst:

Your solution helped me understand how the XY coordinates working terms of mapping.

Also, voted for the text label proposal.

Thanks!

Bill

0 Kudos
Message 9 of 9
(1,867 Views)