Page 1 of 1

Help on how to do a combined datasource XY-plot...

Posted: Thu Jun 21, 2007 1:16 pm
by 9793833
Hi,

I need to use two (and later on several) datasources for a combined XY plot (Steema.TeeChart.Styles.Points I assume) such that the first datasource is treated as the X' axis specifier and the second datasource as the Y' axis.

Both datasources contain a number of points (x,y) - lets call these (x1,y1) and (x2,y2). The desired chart should correlate the datasources such that all outputted points are the X' and Y' axis coordinates (y1, y2) where x1=x2. If either datasource have a point that do not "align" with the other datasource no resulting point will emerge (x1 != x2) from it, but of course all aligning points (x1=x2) will.

I have been unable to find any examples in the provided .NET tutorial files or any clues in the forums on how to accomplish this.

Below is an example of my charting needs.

Datasource 1 contains these values - this is treated as X:
X: 1 2 3 4 5 6
Y: 1 4 8 4 2 0

Datasource 2 contains these values - this is treated as Y:
X: 1 2 3 4 5 6
Y: 6 7 2 8 9 3

Now, what I want is to output a Point chart with these point coordinates in a single series, which is combined from datasource 1 and 2:

X' axis values: 0 to 8 (span of Y in datasource 1)
Y' axis values: 2 to 9 (span of Y in datasource 2)

Points to plot (combined):
X', Y':
( 1,6 ), ( 4,7 ), ( 8,2 ), ( 4,8 ), ( 2,9 ), ( 0,3 ) .

I hope the above description is clear enough, otherwise do let me know and I'll try to clarify it.

Best Regards
Michael Schøler

IT consultant
Vestas A/S, Denmark
www.vestas.com

Working minimalistic example accomplished

Posted: Thu Jun 21, 2007 1:52 pm
by 9793833
Working example with 3 correlated charts (x correlation is assumed in this example and not dealed with, only y values are considered)... I still need a solution for dealing with DataSources from a database instead of user defined double arrays as below.

Code: Select all

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Test_TestXY : System.Web.UI.Page
{
	protected void Page_Load(object sender, EventArgs e)
	{
		WebChart1.GetChartFile = "GetChart.aspx";

		Steema.TeeChart.Chart chart = WebChart1.Chart;
		chart.Series.Clear(); 
		
		Steema.TeeChart.Styles.Points sA = new Steema.TeeChart.Styles.Points();
		Steema.TeeChart.Styles.Points sB = new Steema.TeeChart.Styles.Points();
		Steema.TeeChart.Styles.Points sC = new Steema.TeeChart.Styles.Points();

		double[] aY = { 1, 4, 8, 4, 2, 0 };             // Y1
		double[] bY = { 10, 11, 13, 12, 10, 11 };       // Y2
		double[] cY = { 100, 110, 140, 120, 100, 110 }; // Y3

		double[] dY = { 2, 5, 6, 5, 4, 3 };             // X SERIES!

		for (int i = 0; i < dX.Length; i++)
		{
			sA.Add(dY[i], aY[i]);
			sB.Add(dY[i], bY[i]);
			sC.Add(dY[i], cY[i]);
		}

		Steema.TeeChart.Axis axisA = 
			new Steema.TeeChart.Axis(false, false, chart);
		axisA.Minimum = 0;
		axisA.Maximum = 8;
		axisA.Grid.Visible = false;
		axisA.Title.Caption = "A";
		sA.CustomVertAxis = axisA;
		sA.Pointer.Style = Steema.TeeChart.Styles.PointerStyles.Circle;
		chart.Axes.Custom.Add(axisA);

		Steema.TeeChart.Axis axisB =
			new Steema.TeeChart.Axis(false, false, chart);
		axisB.Minimum = 10;
		axisB.Maximum = 13;
		axisB.Grid.Visible = false;
		axisB.Title.Caption = "B";
		sB.CustomVertAxis = axisB;
		sB.Pointer.Style = Steema.TeeChart.Styles.PointerStyles.Triangle;
		axisB.RelativePosition = -20;
		chart.Axes.Custom.Add(axisB);

		Steema.TeeChart.Axis axisC =
			new Steema.TeeChart.Axis(false, false, chart);
		axisC.Minimum = 100;
		axisC.Maximum = 140;
		axisC.Grid.Visible = false;
		axisC.OtherSide = true;
		axisC.Title.Caption = "C";
		sC.CustomVertAxis = axisC;
		sC.Pointer.Style = Steema.TeeChart.Styles.PointerStyles.DiagCross;
		chart.Axes.Custom.Add(axisC);
		
		chart.Series.Add(sA);
		chart.Series.Add(sB);
		chart.Series.Add(sC);

		chart.Panel.MarginLeft = 22;
		chart.Panel.MarginRight = 10;
		chart.Legend.Alignment = Steema.TeeChart.LegendAlignments.Bottom;
	}
}

Posted: Thu Jun 21, 2007 2:21 pm
by narcis
Hello,

Reading this thread may be helpful for you.

DataSet manipulation

Posted: Thu Jun 21, 2007 7:55 pm
by 9793833
Hi again,

I'm well aware of how to access database as datasources (ADO), so the provided tutorial link did not help me in this regard. What I don't however at present time know how to do, is to manipulate a datasource in the way I describe above. Ie. two datasources should be combined (correlated).

If you have any insight I'd naturally appreciate it, and should I beat you to it I'll post my findings here as soon as I can =)

Best regards
Michael Schøler

Posted: Fri Jun 22, 2007 8:00 am
by narcis
Hi Michael,

Sorry for having overlooked your messages. I guess you could try doing something as Christopher Ireland's example here. You could assign first datasource Y values to series' XValues.DataMember and second's datasource Y values to same series YValues.DataMember.
If either datasource have a point that do not "align" with the other datasource no resulting point will emerge (x1 != x2) from it, but of course all aligning points (x1=x2) will.
TeeChart won't control that, in that case you may need to manually read the datasources before and decide which points should be added to the series or not. Again, Christopher's example should help you achieving that.

I got it

Posted: Fri Jun 22, 2007 9:24 pm
by 9793833
Here is my final working version of a correlation function as described. I hope others will find it usefull for XY-plotting two datasources as one.

Code: Select all

	public static DataTable CorrelateDataSources(DataTable xAxisTable, DataTable yAxisTable, int XColIdx, int YColIdx)
	{
		DataTable correlatedTable = new DataTable();

		DataColumn xCol = new DataColumn("X, " + xAxisTable.Columns[YColIdx].ColumnName);
		xCol.DataType = xAxisTable.Columns[YColIdx].DataType;
		xCol.Caption = xAxisTable.Columns[YColIdx].Caption;
		correlatedTable.Columns.Add(xCol);

		DataColumn yCol = new DataColumn("Y, " + yAxisTable.Columns[YColIdx].ColumnName);
		yCol.DataType = yAxisTable.Columns[YColIdx].DataType;
		yCol.Caption = yAxisTable.Columns[YColIdx].Caption;
		correlatedTable.Columns.Add(yCol);

		int rx = 0, ry = 0;
		DataRow rowx, rowy;
		string tsx, tsy;
		for (ry = 0; ry < yAxisTable.Rows.Count; ry++)
		{
			rowy = yAxisTable.Rows[ry];
			rowx = xAxisTable.Rows[rx];
			tsx = rowx.ItemArray[XColIdx].ToString();
			tsy = rowy.ItemArray[XColIdx].ToString();
			while (tsx != tsy)
			{
				if (++rx >= xAxisTable.Rows.Count) break;
				rowx = xAxisTable.Rows[rx];
				tsx = rowx.ItemArray[XColIdx].ToString();
				tsy = rowy.ItemArray[XColIdx].ToString();
			}
			if (tsx == tsy)
			{
				object[] newRow = { rowx.ItemArray[YColIdx], rowy.ItemArray[YColIdx] };
				correlatedTable.LoadDataRow(newRow, LoadOption.Upsert);
				
				rx++;
			}
			if (rx >= xAxisTable.Rows.Count) break;
		}

		return correlatedTable;
	}