From 04:00 PM CDT – 08:00 PM CDT (09:00 PM UTC – 01:00 AM UTC) Tuesday, April 16, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

Problem drawing Histogram data

Hello everyone,

I wonder if anyone can help me?


I am working in C# 2005 writing Windows Forms, using MCC Measurement Studio version 8.0.1.334

I am trying to draw a histogram.  After a lot of searching, I found that I could get a reasonable plot using a ScatterPlot.

My code generates the correct data but the scatterplot appears to invent additional values.

My code:

namespace TestScatterGraph

{

public partial class Form1 : Form

{

private double Lower = 0;

private double Upper = 0;

private double[] Data = new double[] { 1, 3, 2, 3, 3, 3, 8, 2, 2 };

private double[] CentreValues;

private double[] dHistData;

int[] HistData;

public Form1()

{

InitializeComponent();

}

private void button1_Click(object sender, EventArgs e)

{

ArrayOperation.MaxMin1D(Data,out Upper,out Lower);

HistData = Statistics.Histogram(Data, Lower, Upper, 10, out CentreValues);

dHistData = (double[])DataConverter.Convert(HistData, typeof(double[]));

scatterPlot1.PlotXY(CentreValues , dHistData);

}

}

}

My graph

The lines don't align very well with the X Axis, but the main problem is that whilst there are only 4 values in the original data, and in CentreValues and dHist, there are 6 values displayed on the graph.

 

So, the obvious question is; what am I doing wrong?

 

As a secondary question, has there been a new version of MCC MStudio, in line with the new NI version?

Many thanks
John822179
Live long, prosper and understand Measurement Studio?

0 Kudos
Message 1 of 2
(3,568 Views)
Hello everyone,
 
Sorry to bother you with this.
 
I have discovered my error. 
 
I don't profess to uderstand why, but the value ( 10 ) used for
histogramIntervals
The number of elements in the histogram and in the centerValues output array
in the line
HistData = Statistics.Histogram(Data, Lower, Upper, 10, out CentreValues);
 
was too small. 
 

 I have found be experimentation, that this value needs to be at least 10 times the number of points in the source data set.

Many thanks
John822179
Live long, prosper and understand Measurement Studio?

0 Kudos
Message 2 of 2
(3,555 Views)