Textual independent axis plot not what expected

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
Glenn F. Henriksen
Newbie
Newbie
Posts: 52
Joined: Tue Mar 04, 2003 5:00 am

Textual independent axis plot not what expected

Post by Glenn F. Henriksen » Tue Aug 16, 2005 11:22 pm

I'm trying to generate a plot from a dataview where more than one row may have the same independent axis value in text format. e.g.

name age
Jack 15
Jack 22
Jack 13
Jane 4
Jane 6
Roger 21

Now if i draw this using a Points series and set series.LabelMember = "name"; then it draws each row for "Jack" at a different horizontal position and not all of them vertically one over the other. This is completely different than if i did it as a number format entry. E.g. if I had a numeric value for name such as

name age
1 15
1 22
1 13
2 4
2 6
3 21

and set series.XValues.DataMember = "name" then the values 15,22,13 are drawn vertically one over the other.

Is there any way I can have text entries show up as the numeric entries i.e. vertically? Thanks.

Jamshed Rahman
Intel Corporation
jamshidur.rahman<at>intel.com

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Post by Narcís » Wed Aug 17, 2005 11:15 am

Hi Jamshed,

To achieve what you request you'll need a XValues and YValues DataMember and a LabelMember as shown in the code below:

Code: Select all

		private DataTable CreateDataSet() 
		{ 
			DataTable result=null;
			
			DataTable Employee = new DataTable("Employee"); 
			DataColumn XValues = new DataColumn("XValues", Type.GetType("System.Int32")); 
			DataColumn YValues = new DataColumn("YValues", Type.GetType("System.Int32")); 
			DataColumn Label = new DataColumn("Label", Type.GetType("System.String")); 

			Employee.Columns.Add(XValues); 
			Employee.Columns.Add(YValues); 
			Employee.Columns.Add(Label); 		

			DataRow dataRow; 
			dataRow = Employee.NewRow(); 
			dataRow[XValues] = 1;
			dataRow[YValues] = 15; 
			dataRow[Label] = "Jack"; 
			Employee.Rows.Add(dataRow); 

			dataRow = Employee.NewRow(); 
			dataRow[XValues] = 1;
			dataRow[YValues] = 22; 
			dataRow[Label] = "Jack"; 
			Employee.Rows.Add(dataRow); 

			dataRow = Employee.NewRow(); 
			dataRow[XValues] = 1;
			dataRow[YValues] = 13; 
			dataRow[Label] = "Jack"; 
			Employee.Rows.Add(dataRow); 

			dataRow = Employee.NewRow(); 
			dataRow[XValues] = 2;
			dataRow[YValues] = 4; 
			dataRow[Label] = "Jane"; 
			Employee.Rows.Add(dataRow); 
			
			dataRow = Employee.NewRow(); 
			dataRow[XValues] = 2;
			dataRow[YValues] = 6; 
			dataRow[Label] = "Jane"; 
			Employee.Rows.Add(dataRow); 
			
			dataRow = Employee.NewRow(); 
			dataRow[XValues] = 3;
			dataRow[YValues] = 21; 
			dataRow[Label] = "Roger"; 
			Employee.Rows.Add(dataRow); 

			result = Employee;
			
			return result;
		}  

		private void Form1_Load(object sender, System.EventArgs e) 
		{       
			Steema.TeeChart.Styles.Points points1 = new Steema.TeeChart.Styles.Points(tChart1.Chart);
			points1.Clear(); 
			points1.DataSource = CreateDataSet();
			points1.XValues.DataMember = "XValues"; 
			points1.YValues.DataMember = "YValues"; 
			points1.LabelMember = "Label"; 
			points1.CheckDataSource();

			commander1.Chart = tChart1;
		}
Best Regards,
Narcís Calvet / 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

Glenn F. Henriksen
Newbie
Newbie
Posts: 52
Joined: Tue Mar 04, 2003 5:00 am

Post by Glenn F. Henriksen » Wed Aug 17, 2005 6:59 pm

Narcis,
thank you very much for your solution. this was actually the solution i was thinking of too but unfortunately it doesn't work for more than one series drawn on the same chart. i have more than one points series drawn on the same chart whose x values have to line up together with the labels. if i do it your way with labels:

series 1:
name nameindex age
jack 1 22
jack 1 15
jane 2 4
jane 2 9

series 2:
name nameindex age
jack 1 59
jack 1 45
narcis 3 44
narcis 3 23

then if i make
xvalues.datamember = "nameindex";
labelmember = "name";

then although the chart will draw right the labels will only show up for the second series OR will overlap one another. what i'd like is for tchart to know by itself what "jack" or "jane" means just like it knows the values 1 and 2.
So is there something i can do to make this work for multiple series drawn on the same chart which reference multiple views of a datatable?

Thanks,
Jamshed
Intel Corp.

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Post by Narcís » Fri Aug 19, 2005 11:12 am

Hi Jack,

Yes, this is a known problem and is already listed in our defect list to be fixed for future releases.

In the meantime you could set labels in the GetAxisLabel event as shown in the example below. This is a very particular case for the example data you posted but you'll be able to make it generic.

Code: Select all

		private DataTable CreateDataSet1() 
		{ 
			DataTable result=null;
			
			DataTable Employee = new DataTable("Employee"); 
			DataColumn XValues = new DataColumn("XValues", Type.GetType("System.Int32")); 
			DataColumn YValues = new DataColumn("YValues", Type.GetType("System.Int32")); 
			DataColumn Label = new DataColumn("Label", Type.GetType("System.String")); 

			Employee.Columns.Add(XValues); 
			Employee.Columns.Add(YValues); 
			Employee.Columns.Add(Label); 		

			DataRow dataRow; 
			dataRow = Employee.NewRow(); 
			dataRow[XValues] = 1;
			dataRow[YValues] = 15; 
			dataRow[Label] = "Jack"; 
			Employee.Rows.Add(dataRow); 

			dataRow = Employee.NewRow(); 
			dataRow[XValues] = 1;
			dataRow[YValues] = 22; 
			dataRow[Label] = "Jack"; 
			Employee.Rows.Add(dataRow); 

			dataRow = Employee.NewRow(); 
			dataRow[XValues] = 2;
			dataRow[YValues] = 4; 
			dataRow[Label] = "Jane"; 
			Employee.Rows.Add(dataRow); 
			
			dataRow = Employee.NewRow(); 
			dataRow[XValues] = 2;
			dataRow[YValues] = 9; 
			dataRow[Label] = "Jane"; 
			Employee.Rows.Add(dataRow); 

			result = Employee;
			
			return result;
		}  

		private DataTable CreateDataSet2() 
		{ 
			DataTable result=null;
			
			DataTable Employee = new DataTable("Employee"); 
			DataColumn XValues = new DataColumn("XValues", Type.GetType("System.Int32")); 
			DataColumn YValues = new DataColumn("YValues", Type.GetType("System.Int32")); 
			DataColumn Label = new DataColumn("Label", Type.GetType("System.String")); 

			Employee.Columns.Add(XValues); 
			Employee.Columns.Add(YValues); 
			Employee.Columns.Add(Label); 		

			DataRow dataRow; 
			dataRow = Employee.NewRow(); 
			dataRow[XValues] = 1;
			dataRow[YValues] = 59; 
			dataRow[Label] = "Jack"; 
			Employee.Rows.Add(dataRow); 

			dataRow = Employee.NewRow(); 
			dataRow[XValues] = 1;
			dataRow[YValues] = 45; 
			dataRow[Label] = "Jack"; 
			Employee.Rows.Add(dataRow); 

			dataRow = Employee.NewRow(); 
			dataRow[XValues] = 3;
			dataRow[YValues] = 44; 
			dataRow[Label] = "Narcis"; 
			Employee.Rows.Add(dataRow); 
			
			dataRow = Employee.NewRow(); 
			dataRow[XValues] = 3;
			dataRow[YValues] = 23; 
			dataRow[Label] = "Narcis"; 
			Employee.Rows.Add(dataRow); 

			result = Employee;
			
			return result;
		}  

		private Steema.TeeChart.Styles.Points points1;
		private Steema.TeeChart.Styles.Points points2;

		private void Form1_Load(object sender, System.EventArgs e) 
		{       
			points1 = new Steema.TeeChart.Styles.Points(tChart1.Chart);
			points1.Clear(); 
			points1.DataSource = CreateDataSet1();
			points1.XValues.DataMember = "XValues"; 
			points1.YValues.DataMember = "YValues"; 
			//points1.LabelMember = "Label"; 
			points1.CheckDataSource();

			points2 = new Steema.TeeChart.Styles.Points(tChart1.Chart);
			points2.Clear(); 
			points2.DataSource = CreateDataSet2();
			points2.XValues.DataMember = "XValues"; 
			points2.YValues.DataMember = "YValues"; 
			//points2.LabelMember = "Label"; 
			points2.CheckDataSource();

			commander1.Chart = tChart1;
		}

		private void tChart1_GetAxisLabel(object sender, Steema.TeeChart.GetAxisLabelEventArgs e)
		{
			DataTable table;
			DataRow r;

			if(sender.Equals(tChart1.Axes.Bottom))
			{

				switch(e.LabelText) 
				{
					case "1":
						table = (points1.DataSource as  DataTable);
						r = table.Rows[Convert.ToInt32(e.LabelText)];
						e.LabelText = (string)r[2];
					
						break;

					case "2":
						table = (points1.DataSource as  DataTable);
						r = table.Rows[Convert.ToInt32(e.LabelText)];
						e.LabelText = (string)r[2];
						break;

					case "3":
						table = (points2.DataSource as  DataTable);
						r = table.Rows[Convert.ToInt32(e.LabelText)];
						e.LabelText = (string)r[2];
						break;
				}
			}
		}
Another option would be using custom labels. You'll find more information on how to use custom labels at TeeChart's features demo available at the TeeChart program group.
Best Regards,
Narcís Calvet / 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