DateTime on x axis of colorgrid

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
skruegel
Newbie
Newbie
Posts: 4
Joined: Wed Dec 05, 2007 12:00 am
Contact:

DateTime on x axis of colorgrid

Post by skruegel » Tue Jan 06, 2009 8:29 pm

I have a requirement for a colorgrid with DataTime on the x axis. What's the best way for this to be done?

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 Jan 07, 2009 9:46 am

Hi skruegel,

You can do something like this:

Code: Select all

		public Form1()
		{
			InitializeComponent();
			InitializeChart();
		}

		private void InitializeChart()
		{
			tChart1.Aspect.View3D = false;
			tChart1.Axes.Bottom.Labels.Angle = 90;

			Steema.TeeChart.Styles.ColorGrid colorGrid1 = new Steema.TeeChart.Styles.ColorGrid(tChart1.Chart);
			colorGrid1.XValues.DateTime = true;

			Random y = new Random();

			for (int x = 0; x < 10; x++)
			{
				for (int z = 0; z < 10; z++)
				{
					colorGrid1.Add(DateTime.Now.AddDays(x).ToOADate(), y.Next(), z);
				}
			}
		}
Hope this helps!
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

skruegel
Newbie
Newbie
Posts: 4
Joined: Wed Dec 05, 2007 12:00 am
Contact:

Post by skruegel » Thu Jan 22, 2009 7:03 pm

Narcis-

Here's what I'm trying to do:

Code: Select all

        public Form1()
        {
            InitializeComponent();
            InitializeChart();
        }

        private void InitializeChart()
        {
            tChart1.Aspect.View3D = false;
            tChart1.Axes.Bottom.Labels.Angle = 90;

            Steema.TeeChart.Styles.ColorGrid colorGrid1 = new Steema.TeeChart.Styles.ColorGrid(tChart1.Chart);
            colorGrid1.XValues.DateTime = true;

            List<DateTime> DateTimeList = new List<DateTime>();
            List<double> Y = new List<double>();
            List<double> Z = new List<double>();
            DateTime currentDate = DateTime.Today;

            for (int day = 0; day < 60; day++)
            {
                DateTimeList.Add(currentDate);
                Y.Add((double)day);
                Z.Add((double)day);
                currentDate.AddDays(1);
            }

            for (int displayPoint = 0; displayPoint < 60; displayPoint++)
            {
                colorGrid1.Add(DateTimeList[displayPoint],Y[displayPoint],Z[displayPoint]);
            }
        }
Seems like it should be possible.

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 Jan 23, 2009 10:22 am

Hi skruegel,

Yes, two little problems here:

1. This ColorGrid needs setting IrregularGrid=true as described here.

2. You need to add DateTime values to a ColorGrid converting them to double using ToOADate method as in the example I posted.

This said, using code below works fine for me.

Code: Select all

		public Form1()
		{
			InitializeComponent();
			InitializeChart();
		}

		private void InitializeChart()
		{
			tChart1.Aspect.View3D = false;
			tChart1.Axes.Bottom.Labels.Angle = 90;

			Steema.TeeChart.Styles.ColorGrid colorGrid1 = new Steema.TeeChart.Styles.ColorGrid(tChart1.Chart);
			colorGrid1.XValues.DateTime = true;
			colorGrid1.IrregularGrid = true;

			List<DateTime> DateTimeList = new List<DateTime>();
			List<double> Y = new List<double>();
			List<double> Z = new List<double>();
			DateTime currentDate = DateTime.Today;

			for (int day = 0; day < 60; day++)
			{
				DateTimeList.Add(currentDate);
				Y.Add((double)day);
				Z.Add((double)day);
				currentDate.AddDays(1);
			}

			for (int displayPoint = 0; displayPoint < DateTimeList.Count; displayPoint++)
			{
				colorGrid1.Add(DateTimeList[displayPoint].ToOADate(), Y[displayPoint], Z[displayPoint]);
			} 

		}
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