Measurement Studio for VC++

cancel
Showing results for 
Search instead for 
Did you mean: 

histogram with NIGraph

Hi,

I'm looking for a way to display an histogram on a NIGraph.
I tried the XY stepping style but I'm loosing the first bar (it is invisable ) because you can see the first plot point.

Thanks
Ohad
0 Kudos
Message 1 of 12
(5,788 Views)
Ohad,

First, what version of MStudio are you using? Are you programing in VB, C++, C#, or something else? Is there anyway you could attach an example of the historgram that you are refering too that loses the first bar? I will take a look and we will go from there. Have a great day!!

Allan S.
National Instruments
0 Kudos
Message 2 of 12
(5,779 Views)
Hello,

I am having exactly the same problem. I use Measurement Studio for Visual C++.net.
When I want to display an histogram, the first bar does not appear... In fact I can see it but it is represented as a line instead of a larger bar.
I tried different way to display this histogram with CNiGraph but the result is always wrong.
I hope that you can help us.
Thanks,
Alia
0 Kudos
Message 3 of 12
(5,768 Views)
Could you please attach an example of this? Once I can see this problem I should much more effectively be able to help you trouble shoot this. Have a great day!

Allan S.
National Instruments
0 Kudos
Message 4 of 12
(5,757 Views)
Hello Allan,

I join a picture of the histogram. You can see nine bars in this histogram. I wanted 10 bars. The first bar appears, but it looks like a line.
I put also short part of the code concerning the histogram.
I hope this will make you understand the problem.
I have other examples of this problem. In fact each time I make a distribution which I want to display with an histogram, it gives wrong result.

RAHParam.NbBins = 10;
Param.HeightDistribution(&GDHParam, &RAHParam, FParam);
m_cGraphHistHeight.PlotXvsY(RAHParam.axis2, RAHParam.HistHeight2);

Thanks for your help,

Alia
0 Kudos
Message 5 of 12
(5,752 Views)
Alia,

I am having trouble reproducing this problem. Could you attach the code to reproduce this error on my computer. That will help greatly in getting to the bottom of this.
0 Kudos
Message 6 of 12
(5,729 Views)
Hi Allan,

I send you the code corresponding to the histogram computation and display. Attached with the message is the histogram I obtain with this code.
Note also that the xAxis ticks are not placed in correspondance with the histogram bars which make it difficult to read and I would say "unusable".
One point which could be important, I am working with Visual C++.net version 2002 and Measurement Studio for Visual.net version 2002. It is not the last version.
Thanks for your help,


Code placed in OnInitDialog function:

BOOL CDlgFlatnessParameters::OnInitDialog()
{
CDialog::OnInitDialog();
CNiReal64Vector PFlat;
PFlat.SetSize(RAHParam.NbMotFl); //RAHParam is a structure defined outside of the class

m_cFlatnessMax.Value = RAHParam.MaxFlat; // 4 NumEdit boxes filled with RAHParam structure parameters
m_cFlatnessMin.Value = RAHParam.MinFlat;
m_cFlatnessStdDev.Value = RAHParam.StdevFlat;
m_cFlatnessAverage.Value = RAHParam.MeanFlat;


for(int i=0; i {
PFlat[i] = RAHParam.PFlat[i]; //PFlat is the array from which we want to calculate a distribution

}

int NbBins=5; //Five bars for the histogram

CNiIntVector Hist(NbBins);
CNiReal64Vector Axis(NbBins);

double Min, Max;
unsigned int MinIndex, MaxIndex;


PFlat.MinMax(Min,MinIndex,Max,MaxIndex);
CNiMath::Histogram(PFlat,Min,Max,NbBins,Hist,Axis);

m_cFlatnessGraph.PlotXvsY(Axis,Hist); //m_cFlatnessGraph is the CNiGraph on which I want to display the histogram

return true;
}
0 Kudos
Message 7 of 12
(5,724 Views)
Hello,

I would suggest that you as well try the example program located in C:\Program Files\National Instruments\MeasurementStudio\VCNET\Examples\Math\Histogram to see the results and verify if the problem really exists.

Also, if you look at the data that is plotted in Histogram, you will find that the steps are created with the actual value on the top right of the bar. I think it is a limitation of the CWGraph in Measurement Studio that is does not present the mid value of the histogram bar. In summary, the MStudio CWGraph will present the first value as the top right value and thus will not show the full bar for that value.

As a workaround you can add another value that has X value as Xmin-XDivision and Y value as Y(Xmin). This will add another bar on the left side of the histogram.

I hope it helps,
Rajiv G
0 Kudos
Message 8 of 12
(5,674 Views)
Hello Rajiv,

Thanks for your answer.
I have tested the example. At a first glance (with their randomly generated graph), it seems to work correctly without the default for the first bar. But I have opened this project and I have replaced their random function by a simple i*i function. And then the problem appears, the same as I am having in my program. I show you a screen shot of NI example with my little modification on the attached bmp. The corresponding code is:
void CHistogramDlg::OnGenerateData()
{
CNiReal64Vector data(1000), axis(20);
CNiIntVector histogram(20);

for(int i=0; i<1000; i++)
{
double x = (double)rand() / RAND_MAX;
data[i] = i*i; //This line has been changed ((double)rand() / RAND_MAX) * (((double)rand() / RAND_MAX) * 10 - 5);
}

// create histogram
double min, max;
unsigned int minIndex, maxIndex;
data.MinMax(min, minIndex, max, maxIndex);
CNiMath::Histogram(data, min, max, 20, histogram, axis);

//Plot Data and Histogram
m_data.PlotY(data);
m_histogram.PlotXvsY(axis, histogram);
}


Concerning your advice of workaround, I don't really understand what you mean. I don't understand what is this value on the top right of the bar you are talking about... I will try to understand but if you have a few minutes to explain me better I would be pleased of it.
Thanks for your help,
ALia
0 Kudos
Message 9 of 12
(5,654 Views)
In fact it seems that this type of graph is not behaving logically.
When you calculate a distibution you need to show some bars corresponding to a Y value. Each bar should correpond to an X value.
But it is not the case. The CWGraph is behaving as if we were showing a standard y=f(x) function... Even if it looks like an histogram, the X axis is not correponding to a typical histogram X Axis. I really do not know how to deal with this problem...
0 Kudos
Message 10 of 12
(5,635 Views)