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.
Solved! Go to Solution.
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.
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.
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.
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"?
Obviously, you have mastered a number of methods to achieve this!
Maybe the advanced plotting toolkit is something to consider. It has the option to create custom labels.
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:
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:
Your solution helped me understand how the XY coordinates working terms of mapping.
Also, voted for the text label proposal.