LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Question about plotting a graph

Hi folks,

i was messing with the "Plot" functions and the thing that i was looking to achieve was to plot an hystogram (and until here no prob) with different colors if the value matches a range (for example a blue bar if the value is below 10, yellow betwen 11-15, and green for >16).

But i found it messy when i tryed to plot a single bar after i analyzed the value for determinate the color, the function that i used was:

 

PlotY (Pnl, MainPanel_GRAPH, &data2, 1, VAL_FLOAT, VAL_VERTICAL_BAR, VAL_NO_POINT, VAL_SOLID, 1, VAL_RED);

 

and since &data2 must be an array of values according to the mighty F1 tool i setted it  with an 1 slot array, anyway when the program hits the "for" cycle (inside there are 3 if the sets the color and uses the function above) for drawing the bars seems that he plot every bar but in a X axis space that goes to -0.8 to +0.8 so the only thing that i see is a big colored mess (the last plot he does i assume) and nothing else.

For now i avoided the thing using "PlotPoint" but it isn't the thing that i was looking for.

 

Thanks for every kind of support.

0 Kudos
Message 1 of 3
(3,291 Views)

Hello,

 

I think the best method for plotting a histogram with different colored bars would be to use the PlotRectangle fuction.  This gives you explicit control over the width and color of the bars.  The implementation could potentially look something like this:

 

void plot()
{
    double data[6] = {0, 3, 17, 8, 13, 7};

    for (int i = 0; i < 6; i++)
    {
        int color = (data[i]<10)?VAL_DK_BLUE:(data[i]<15)?VAL_DK_YELLOW:VAL_DK_GREEN;
        PlotRectangle(panelHandle, PANEL_GRAPH, (double)i-.35, 0, (double)i+.35, data[i], color, color);
    }
}


which would produce a histogram like this:

 

 

 

 

NickB

National Instruments 

 

Message Edited by nickb on 11-18-2008 01:57 PM
Message 2 of 3
(3,285 Views)
Many thanks NickB your solutions suits perfectly my problem.
0 Kudos
Message 3 of 3
(3,264 Views)