LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

color coded bar chart

Hello All, I need help in generating a color coded bar chart.

I have two 1D arrays with the same dimension. I need to plot their values against their index in a bar chart style. However, the bars should be connecting the two values from each array at their index. The color of the bars should be determined by the condition if the value from array1 is greater or less than the value from array2. I tried using property nodes of the xy chart in a for loop, but didn't succeed. Plus this method will creat a chart of multiple plots (can be hundredes or thousands if the array is large, thus slow down the plotting process). I also want to control the bar width in addition to their colors in the chart.

I would appreciate if someone can suggest a solution.

Many thanks!
Bryan
0 Kudos
Message 1 of 7
(2,869 Views)
Sorry, I couldn't find a simple way of connecting two values using a bar type chart/graph : the "fill base line to plot n" function is not available for bar plots.
I may miss something here, but, if as you said, you may have hundreds of points, a bar plot would be of very little interest, and a curve plot could also do the trick.
A possible solution could be to divide the data into 2 differents sets : one when Y1>= Y2, the other when Y2>Y1, and to plot the 4 arrays as curves, using the "fill base line" function to distinguish the 2 sets, as in the attached vi.
This does not work as it with bar plots, since bars are always filled to zero. The only way of approching a solution would be to plot the smaller set as BLACK bars OVER the larger set, if they have the same sign, or in the same color otherwise. Accordingly, a more complicated work around, that answers more closely your question, would be to create 4 differents sets, the 2 previous sets being divided in 2 subsets, depending on the relative sign of the Y values. One drawback however, is that the grid lines would be hidden by the black bars...

Hope this helps.

CC
Chilly Charly    (aka CC)

         E-List Master - Kudos glutton - Press the yellow button on the left...
        
Message 2 of 7
(2,858 Views)
Hello CC/All,

Thank you so much for the suggestions. That is exactly what I have been thinking after posting the message. It may work for me if I can get rid of the grid line and use the same color for the minor bars and the background. I have derived some code for the idea but didnt get it work yet, would appreciate any comments on the problem. Thanks for sending your code, but I am using LV6.1 and cant open yours. Do you have anything that is good for my version? Thanks again.

Bryan.
0 Kudos
Message 3 of 7
(2,840 Views)
You were very close to a working solution. I used a different approach, with a waveform graph instead of an XY graph, and some play with NaN, to populate asymetrically array elements.
Have a look at the attached jpegs, on 2 different posts (pbs with files over 26K)

CC
Chilly Charly    (aka CC)

         E-List Master - Kudos glutton - Press the yellow button on the left...
        
0 Kudos
Message 4 of 7
(2,815 Views)
missed !..
Chilly Charly    (aka CC)

         E-List Master - Kudos glutton - Press the yellow button on the left...
        
0 Kudos
Message 5 of 7
(2,814 Views)
This is my front panel. Plot the black bars (smaller data) as (i-1)th plot where i = index of the corresponding colored plot bar.

CC
Chilly Charly    (aka CC)

         E-List Master - Kudos glutton - Press the yellow button on the left...
        
0 Kudos
Message 6 of 7
(2,811 Views)
Thanks CC,

I got it working by filling the other inactive index positions with "zeros" in both case structures. Never used NaN before, i guess that is a more professional approach. Nice to learn from your codes.

This worked beautifully, thanks again.

Bryan.
0 Kudos
Message 7 of 7
(2,797 Views)