11-18-2008 11:42 AM
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.
11-18-2008 01:57 PM - edited 11-18-2008 01:57 PM
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
11-19-2008 04:39 AM