Histogram Newbie

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
Eden
Newbie
Newbie
Posts: 13
Joined: Fri Apr 13, 2012 12:00 am

Histogram Newbie

Post by Eden » Thu Oct 04, 2012 12:15 am

Dear Steema,

I'm trying to add values to a histogram where the vertical axis is the count and the horizontal axis are slices from 1 to 360 (which represents degrees of planetary positions in a circle)
But when I try and add values to the histogram line type I can't seem to accomplish this:
As an experiment I did this:

For intCnt = 1 To 1000
If intCnt Mod 2 = 0 Then
Me.tChartGeo360.Series(0).Add(120)
Else
Me.tChartGeo360.Series(0).Add( CInt(Int((360 * Rnd()) + 1)))
End If
Next

This should have 500 counts for the 120 degree slice and the rest of the slices random but it doesn't.

In the examples and documentation you use the FillSampleValues method so not sure what to pass in.

I know this is probably a dumb question but how do i do this?

Thanks so much!

Joseph
Attachments
histogram.jpg
Histogram Example
histogram.jpg (52.37 KiB) Viewed 16854 times

Sandra
Site Admin
Site Admin
Posts: 3132
Joined: Fri Nov 07, 2008 12:00 am

Re: Histogram Newbie

Post by Sandra » Fri Oct 05, 2012 11:46 am

Hello Joseph,

Using your indications I have used two different ways to get an histogram.
The first options is using a Histogram Series as do in next code:

Code: Select all

 Steema.TeeChart.Styles.Histogram histogramSeries1; 
        private void InitializeChart()
        {
            tChart1.Aspect.View3D = false;
            histogramSeries1 = new Steema.TeeChart.Styles.Histogram(tChart1.Chart);
            Random rnd = new Random();
            histogramSeries1.LinePen.Visible = false;
            for (int i = 0; i < 360; i++)
            {
                if (i % 2 == 0)
                {   
                    histogramSeries1.Add(120, "", Color.Blue);
                }
                else
                {
                    histogramSeries1.Add(((rnd.NextDouble() + 1) * 360), "", Color.Red);

                }
                tChart1.Axes.Left.AutomaticMinimum = false;
                tChart1.Axes.Left.Minimum = 0;
            }

        }
With previous code I could get next result:
histogramSeries.jpg
histogramSeries.jpg (104.58 KiB) Viewed 16787 times
The second, way is use Histogram functions instead of Histogram Series, as do in next sample code:

Code: Select all

 Steema.TeeChart.Functions.HistogramFunction histogram1;
        Steema.TeeChart.Styles.Line line1;
        Steema.TeeChart.Styles.Bar bar1;
        private void InitializeSeries()
        {
            tChart1.Series.Clear();
            tChart1.Clear();

            tChart1.Aspect.View3D = false;
            line1 = new Steema.TeeChart.Styles.Line(tChart1.Chart);
            bar1 = new Steema.TeeChart.Styles.Bar(tChart1.Chart);
            histogram1 = new Steema.TeeChart.Functions.HistogramFunction();
            Random rnd = new Random();
            bar1.Pen.Visible = false;
            bar1.Marks.Visible = false;
            for (int i = 0; i < 360; i++)
            {
                if (i % 2 == 0)
                {  
                    line1.Add(120, "", Color.Blue);
                }
                else
                {
                    line1.Add(((rnd.NextDouble() + 1) * 360), "", Color.Red);

                }
            }
            bar1.DataSource = line1;
            bar1.RefreshSeries();
            line1.Active = false;
            bar1.Function = histogram1;
            for (int i = 0; i < bar1.Count; i++)
            {
                if (i < bar1.Count / 2)
                {
                    bar1[i].Color = Color.Red;
                }
                else
                {
                    bar1[i].Color = Color.Blue;
                }
            }

        }
With previous code I could get next results:
HistogramFunction.jpg
HistogramFunction.jpg (75 KiB) Viewed 16779 times
Can you please, check if my codes work in your end? If the codes don't work as you want, please can you explain exactly what are you want the chart is drawn?

I hope will helps.

Thanks,
Best Regards,
Sandra Pazos / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Anurag Chaudhari
Newbie
Newbie
Posts: 4
Joined: Wed Oct 10, 2012 12:00 am

Histogram Plotting like Matlab Histogram Plot.

Post by Anurag Chaudhari » Wed Dec 12, 2012 12:20 pm

Dear Steema,

I am plotting histogram using code :

Steema.TeeChart.Styles.Bar bar1 = new Steema.TeeChart.Styles.Bar(this.currentTeeChart.Chart);
Steema.TeeChart.Functions.HistogramFunction histogram1 = new Steema.TeeChart.Functions.HistogramFunction(this.currentTeeChart.Chart);

bar1.Function = histogram1;
bar1.DataSource = this.frequency;//list of double values.
bar1.Marks.Visible = false;
histogram1.NumBins = 50;
histogram1.Recalculate();
this.currentTeeChart.Axes.Bottom.SetMinMax(500, 1000);

But as data is large, it shows dense histogram whereas same data is plotted using Matlab software it shows clean and easily readable graph.

Signal data and histogram plot from matlab generated using 'hist(S,50);' command is attached.
Sample matlab code
S=dlmread('SignalData.txt'); %Read signal Data
hist(S,50); %Plot histogram

We need sample code for TeeChart .Net (C#)which can plot similar graph as 'hist(S,50);' does in Matlab.

Sandra
Site Admin
Site Admin
Posts: 3132
Joined: Fri Nov 07, 2008 12:00 am

Re: Histogram Newbie

Post by Sandra » Wed Dec 12, 2012 2:24 pm

Hello Anurag,

Could you please send us your code entirely, because we can reproduce exactly your Histogram and try to suggest you a solution? On the other hand, I recommend you taking a look in the examples of Demo project, concretely in All features\Welcome !\Functions\Statistical\Histograms.

Thanks,
Best Regards,
Sandra Pazos / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Anurag Chaudhari
Newbie
Newbie
Posts: 4
Joined: Wed Oct 10, 2012 12:00 am

Re: Histogram Newbie

Post by Anurag Chaudhari » Thu Dec 13, 2012 7:24 am

Dear Steema,

I regret you as we are not supposed to share/post any code.

I already gave a exact sample code nothing different logic is used. I also saw your suggested example in Demo project but that gives me same dense plot as I have attached you which is not what we want as matlab does.Are you able to run the matlab hist function?,that script may give you some clue, as same data is passed for matlab also.

So could you give me the solution for this.

Thanks,
Anurag

Sandra
Site Admin
Site Admin
Posts: 3132
Joined: Fri Nov 07, 2008 12:00 am

Re: Histogram Newbie

Post by Sandra » Thu Dec 13, 2012 3:00 pm

Hello Newbie,

I have made a simple example that I think works in your end.
TestVisualStudio2010.zip
(31.14 KiB) Downloaded 789 times
Could you please test my attached project and check if create a Histogram as you want.

Thanks,
Best Regards,
Sandra Pazos / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Anurag Chaudhari
Newbie
Newbie
Posts: 4
Joined: Wed Oct 10, 2012 12:00 am

Re: Histogram Newbie

Post by Anurag Chaudhari » Fri Dec 14, 2012 7:04 am

Dear Sandra,

I really like your solution,thats what we want but there is one more thing we require and that is on tee chart X-axis it shows actual data values while on Y-axis it show number of same data values count.

See I have aatched one image in which at the top 4 text boxes are placed which shows min and max value of the data(here signal data),so we want to allow user to display the histogram and let him to enter min and max data value from the groups available.

Here we kept min=0; but max=signalData.Max();(here max=7666.015625) in signal data available with you only one count is present of this value and it is difficultly visible.It is perfect if Y-axis will show the signal data actual value range and X-axis the number of counts (exactly reverse keeping the histogram display same asof now).So with this user can know histogram has max value of 7666.015625 from the height of bar and he will choose that value.

I have tried at my end to interchange the axis values but it shows the same result,coluld you please help to do this.

Thanks,
Anurag

Sandra
Site Admin
Site Admin
Posts: 3132
Joined: Fri Nov 07, 2008 12:00 am

Re: Histogram Newbie

Post by Sandra » Fri Dec 14, 2012 11:42 am

Hello Anurag,

Well. I have modified my project because allow you Set Min or Max depending to TextBox values using SetMinMax() method of Axes.
TestVisualStudio20101.2.zip
(54.44 KiB) Downloaded 757 times
Please, check if previous code works in your end. If you have any problems, please let me know.
Best Regards,
Sandra Pazos / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Anurag Chaudhari
Newbie
Newbie
Posts: 4
Joined: Wed Oct 10, 2012 12:00 am

Re: Histogram Newbie

Post by Anurag Chaudhari » Fri Dec 14, 2012 2:14 pm

Dear Sandra,

You got my point wrong,I don't want any text box display from you that was already done by me.What I am saying that let's say for example I have signal data =10,10,10,20,20,20,40,40,40,40,40,40,50.

count of 10=3,count of 20=3,count of 40=5 and count of 50=1 ,so while ploting histogram I want count on X-axis and actual signal value range on Y-axis that will show what is maximum value from the longest bar(s).

So Y-axis will be {0,10,20,30,40,50,60,70,...,100} and X-axis will be counts {3,3,5,1,...}.

Your current solution Y-axis shows count of signal data and x-axis shows actual signal value(exactly reverse).So In above example I have max=50 and its count =1,and this value bar should be longest among all other.With solution you provided longest bar is not visible clearly as its count is 1 and Max value is what I shown in text box i.e.'7666.015625'.

So now you got my point,I have attached an image for your reference.

Best Regards,
Anurag

Sandra
Site Admin
Site Admin
Posts: 3132
Joined: Fri Nov 07, 2008 12:00 am

Re: Histogram Newbie

Post by Sandra » Mon Dec 17, 2012 3:14 pm

Hello Anuarg,

Ok. I have modified the InitializeChart method, adding an addicional series because can be swapped the values of Axis and the project works in your end.

Code: Select all

 private Steema.TeeChart.Styles.FastLine Series1;
        private Steema.TeeChart.Styles.Bar Series2,Series3;
        private Steema.TeeChart.Functions.HistogramFunction hist;
        private void InitializeChart()
        {
            tChart1.Aspect.View3D = false;
            //Auxiliar series. 
            Series1 = new Steema.TeeChart.Styles.FastLine();
            Series2 = new Steema.TeeChart.Styles.Bar();
            hist = new Steema.TeeChart.Functions.HistogramFunction(tChart1.Chart);
            //Series Bar. 
            Series3 = new Steema.TeeChart.Styles.Bar(tChart1.Chart);
            
            //Read Text File
            Steema.TeeChart.Data.TextSource ts = new Steema.TeeChart.Data.TextSource(@"J:\Sandra\Projects\TestVisualStudio2010\TestVisualStudio2010\SignalData.txt");
            ts.HeaderLines = 1;
            ts.DecimalSeparator = '.';
            ts.Separator = ' ';
            ts.Fields.Add(0, "Y");
            //Assign Text File to Series1;
            Series1.DataSource = ts;
            Series1.XValues.DataMember = "X";
            Series1.YValues.DataMember = "Y";
            tChart1.Export.Data.Text.IncludeHeader = true;
           
            Series1.YValues.Order = Steema.TeeChart.Styles.ValueListOrder.Ascending;
            
            ////  Apply Histogram function to Series1 
            Series2.Marks.Visible = false;
            Series2.DataSource = Series1;
            Series2.Function = hist;
            hist.Period = 2;
            hist.NumBins = 50;
            hist.Recalculate();
    
            //Swap values of Axes X and Y. 
            Series3.XValues.Count = Series2.Count;
            Series3.YValues.Count = Series2.Count;
            Series3.YValues.Value= Series2.XValues.Value;
            Series3.XValues.Value = Series2.YValues.Value;
            Series3.Marks.Visible = false;
            tChart1.DoubleClick += new EventHandler(tChart1_DoubleClick);
        }
Could you confirm us if previous code works in your end?

Thanks,
Best Regards,
Sandra Pazos / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Post Reply