Page 1 of 2

Creating BoxPlots Dynamicly

Posted: Mon Jul 18, 2005 1:31 am
by 9637466
Greetings,

I would think this could be done, probably can but I'm abit confused.

I want to display lots of BoxPlots on a Chart (similiar to adding a point to a series in a . I have a chart with a Bar3D and the customer wants to change it to a Whisker thing (a BoxPlot). It doesn't behave the same way with my initial implementation.

With the Bar3D.Add another bar is added to the series. With the Box.Add more data is added to the series. I want to add hundreds of Box(es) to the chart. Do I need to create a new series in the chart for each one. This doesn't seem right. Is there only one "Box" in a Box series?

What am I missing?

Thanks for any response.

Posted: Mon Jul 18, 2005 9:37 am
by narcis
Hi Randy,

Yes, you need to create a BoxPlot series in the chart for each box plot you wish to draw.

You can find an example of that at TeeChart features demo (Welcome !\Chart styles\Statistical\Box-Plot). You'll find that demo at the TeeChart program group.

Posted: Thu Feb 01, 2007 5:35 pm
by 9642919
I have a problem with adding more than one BoxPlot to the chart. I can't seem to find an attribute, which is responsible for the X axis position of the box.

If I make two series and fetch data in these, the boxes do overlay each other.

If I try:

Code: Select all

BoxXX.Add(<x_axis_position>, <value>);
or

Code: Select all

BoxXX.Add(<value>, <x_axis_position>);
the situation doesn't change a bit.

Please advise what to do!

Sincerely,
//Dmitry.

Posted: Fri Feb 02, 2007 7:26 am
by Marjan
Hi.

To control individual vertical box plot horizontal position, you can use the box plot series Position property. Something like this:

Code: Select all

boxSeries1.Position = 0;
boxSeries2.Position = 1;
or a more "universal" solution <g>:

Code: Select all

int i = 0;
foreach(Styles.Series s in tChart1.Series)
{
  if (s is Styles.Box)
  {
    (s as Styles.Box).Position = i;
    i ++;
  }
}

Posted: Fri Feb 02, 2007 9:19 am
by 9642919
Interesting, this works, of course, but with one matter:

the boxes are in proper positions, when the upper/lower limits, as well as * signs are all situated around the first box only! How can I overcome that?

Sincerely,
//Dmitry.

Posted: Fri Feb 02, 2007 1:54 pm
by Marjan
Hi, Dmitry.

Most likely you're only populating first box plot series. For each group you'll have to populate *different* series. For example:

Code: Select all

// first group points: 2,3,5
box1.Add(2);
box1.Add(3);
box1.Add(5);
// second group points: 1.5, 2.5, 3.1, 4.0
box2.Add(1.5);
box2.Add(2.5);
box2.Add(3.1);
box2.Add(4.0);
In short: each "box" represents different group i.e. series.

Posted: Wed Feb 07, 2007 11:27 am
by 9642919
I had to realize the neccessary functionality the other way, ok.

The next question is how can we get median, lower/higher quartile and whisker numerical positions? I have checked through the debug session that median and other attributes of the series object hold no data regarding these positions... How am I able to get these?

Posted: Wed Feb 07, 2007 3:11 pm
by narcis
Hi sunjun,

You can retrieve BoxPlot series values like this:

Code: Select all

						foreach (Steema.TeeChart.Styles.Box  boxPlot in tChart1.Series)
						{
							listBox1.Items.Add("Series: " + boxPlot.Title.ToString());
							listBox1.Items.Add("Median: " + boxPlot.Median.ToString());
							listBox1.Items.Add("Quartile1: " + boxPlot.Quartile1.ToString());
							listBox1.Items.Add("Quartile3: " + boxPlot.Quartile3.ToString());
							listBox1.Items.Add("InnerFence1: " + boxPlot.InnerFence1.ToString());
							listBox1.Items.Add("InnerFence3: " + boxPlot.InnerFence3.ToString());
							listBox1.Items.Add("OuterFence1: " + boxPlot.OuterFence1.ToString());
							listBox1.Items.Add("OuterFence3: " + boxPlot.OuterFence3.ToString());
							listBox1.Items.Add("AdjacentPoint1: " + boxPlot.AdjacentPoint1.ToString());
							listBox1.Items.Add("AdjacentPoint3: " + boxPlot.AdjacentPoint3.ToString());
							listBox1.Items.Add("-------------------------");
						}

Posted: Thu Feb 08, 2007 9:00 am
by 9642919
Thanks, Narcis!

But this is the exactly what I have tried - debug all the attributes you have providen here. All these attributes are equal to 0.

This means, that *after* ADDing elements to the serie and *before* requesting these attributes, I have to initialize the graph somehow?

Sincerely,
//Dmitry.

Posted: Thu Feb 08, 2007 10:08 am
by narcis
Hi Dmitry,

It works fine for me here populating series with custom values, for example:

Code: Select all

        private void Form1_Load(object sender, EventArgs e)
        {						
						Steema.TeeChart.Styles.Box box1= new Steema.TeeChart.Styles.Box(tChart1.Chart);

						box1.UseCustomValues = true;
						box1.Clear();
						
						box1.UseCustomValues = true;
						box1.Median = 38;
						box1.Quartile1 = 37.25;
						box1.Quartile3 = 40.75;
						// adjacent points are related with whisker lines
						box1.AdjacentPoint1 = 37; // lower whisker at 37
						box1.AdjacentPoint3 = 43; // upper whisker at 43
						// using this all added points will be extreme outliers
						box1.InnerFence1 = 39;
						box1.InnerFence3 = 39;
						box1.OuterFence1 = 39;
						box1.OuterFence3 = 39;
						// add outliers
						box1.Add(new float[4] { 35, 36, 44, 61 });
				

						foreach (Steema.TeeChart.Styles.Box  boxPlot in tChart1.Series)
						{
							listBox1.Items.Add("Series: " + boxPlot.Title.ToString());
							listBox1.Items.Add("Median: " + boxPlot.Median.ToString());
							listBox1.Items.Add("Quartile1: " + boxPlot.Quartile1.ToString());
							listBox1.Items.Add("Quartile3: " + boxPlot.Quartile3.ToString());
							listBox1.Items.Add("InnerFence1: " + boxPlot.InnerFence1.ToString());
							listBox1.Items.Add("InnerFence3: " + boxPlot.InnerFence3.ToString());
							listBox1.Items.Add("OuterFence1: " + boxPlot.OuterFence1.ToString());
							listBox1.Items.Add("OuterFence3: " + boxPlot.OuterFence3.ToString());
							listBox1.Items.Add("AdjacentPoint1: " + boxPlot.AdjacentPoint1.ToString());
							listBox1.Items.Add("AdjacentPoint3: " + boxPlot.AdjacentPoint3.ToString());
							listBox1.Items.Add("-------------------------");
						}
				}

Posted: Thu Feb 08, 2007 10:24 am
by 9642919
I think it is strange at least.

What I mean that when I feed the Box with the data, I get a vizual representation of the whiskers, median, quartiles, etc. So, these values obviously MUST be available somewhere in the object.

But if I have to calculate everything manually in order to have these values, why do I need the BoxPlot chart style at all? I can draw my custom chart then with no problems at all... :-/

So, the answer is that there is no way to get numerical values from the Box serie object if these were not manually written there before?

Sincerely,
//Dmitry.

Posted: Fri Feb 09, 2007 10:52 am
by narcis
Hi Dmitry,

The solution is to call box series ReconstructFromData() method. This will in effect recalculate all box plot parameters, for example:

Code: Select all

        private void Form1_Load(object sender, EventArgs e)
        {					
					Steema.TeeChart.Styles.Box box1= new Steema.TeeChart.Styles.Box(tChart1.Chart);
					box1.FillSampleValues();				

					foreach (Steema.TeeChart.Styles.Box  boxPlot in tChart1.Series)
					{
						boxPlot.ReconstructFromData();

						listBox1.Items.Add("Series: " + boxPlot.Title.ToString());
						listBox1.Items.Add("Median: " + boxPlot.Median.ToString());
						listBox1.Items.Add("Quartile1: " + boxPlot.Quartile1.ToString());
						listBox1.Items.Add("Quartile3: " + boxPlot.Quartile3.ToString());
						listBox1.Items.Add("InnerFence1: " + boxPlot.InnerFence1.ToString());
						listBox1.Items.Add("InnerFence3: " + boxPlot.InnerFence3.ToString());
						listBox1.Items.Add("OuterFence1: " + boxPlot.OuterFence1.ToString());
						listBox1.Items.Add("OuterFence3: " + boxPlot.OuterFence3.ToString());
						listBox1.Items.Add("AdjacentPoint1: " + boxPlot.AdjacentPoint1.ToString());
						listBox1.Items.Add("AdjacentPoint3: " + boxPlot.AdjacentPoint3.ToString());
						listBox1.Items.Add("-------------------------");
					}
				}

Posted: Fri Feb 09, 2007 11:39 am
by 9642919
Great! This works just fine!

Thanks a lot!

Anyway, I think that such obviously-needed functions should be somewhere in HOW-TO, FAQ or Tutorials...

//Dmitry.

box plots

Posted: Mon Jul 07, 2008 9:33 pm
by 13046874
Hi Narcis,

In my opinion, the current box plot setup where each box is a series is pretty counterintuitive and not very consistent with the other TeeChart series types.
My ideal box plot would be a series of boxes, each with an x-value and an array of y values.

Something along the lines of
MyBoxSeries.Add(X as double, Y() as double)
or
MyBoxSeries.Add(X as date, Y() as double)

Maybe something else to put on the ever-increasing wish-list?

Cheers
Francis

Posted: Tue Jul 08, 2008 7:37 am
by narcis
Hi Francis,
Maybe something else to put on the ever-increasing wish-list?


Yes, exactly :wink:. I've just added this item.

Anyway, you could also create a custom series which contains an array of boxplots.