Page 1 of 1

Colorband using axis with datetime format (C#)

Posted: Wed Dec 20, 2006 12:19 pm
by 9528318
Hi guys!

I'm kind of stuck here. I've been trying to get a colorband in one of my graphs. The problem is that the axis on which I base the colorband has a datetime format, but I get an error stating that I have to supply a double.

My question is:
How do I create a colorband on a datetime-formatted axis with C#?

I already tried casting and converting the value, which is also done in another topic I found concerning a colorband using VB, but it doesn't seem to work the same way in C#. If someone could show me a correct C# example I would be very grateful.

Thx in advance,

Willy

Posted: Wed Dec 20, 2006 2:25 pm
by narcis
Hi Willy,

Have you tried using something as Christopher Ireland suggested here?

Posted: Wed Dec 20, 2006 4:44 pm
by 9528318
Hi Narcís!

Thx for your response. I've tried it, but it didn't help me :(

In that topic the date seems to be in an Ole Automation Date format (OADate), but how do I convert a value (date of another type) to an OADate. The only options I have corresponding to the intelli-sense are (UTC)filetime, binary and OADate.

The dates I have at my disposal are of the type string and are formatted like: yyyy-MM-dd hh:mm

Changing this into a date format is no problem, would it not be that there are no conversion options for the above mentioned formats.

The setup is as following:

Code: Select all

        tChart1.Tools.get_Items(0).asColorband.Axis = tChart1.Axis.Bottom;
        tChart1.Tools.get_Items(0).asColorband.StartValue =Convert.ToDateTime("2006-11-01 08:00").ToOADate;
        tChart1.Tools.get_Items(0).asColorband.EndValue = Convert.ToDateTime("2006-11-02 16:00").ToOADate;
        tChart1.Tools.get_Items(0).asColorband.Color = System.Convert.ToUInt32(System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Blue));
        tChart1.Tools.get_Items(0).asColorband.Transparency = 75;
        tChart1.Tools.get_Items(0).asColorband.DrawBehind = true;  

In which format should the StartValue/EndValue be supplied - OADate or Double? Because when I enter a legit double value it does implement the colorband, but I dont know how the double values correspond to the date values. For example: StartValue 0 and EndValue 75 just make the colorband span the whole graph and probably beyond that too.

Could you shed some light on this for me, am I missing something here? :shock:

Regards,
Willy (completely clueless atm)

Posted: Thu Dec 21, 2006 10:33 am
by narcis
Hi Willy,

You should try using DateTime.Parse method and then ToOADate method to convert a DateTime value to a double. It works fine for me here doing this:

Code: Select all

		private void Form1_Load(object sender, EventArgs e)
		{
			Random YVal = new Random();

			axTChart1.Series(0).XValues.DateTime = true;

			axTChart1.Series(0).AddXY(DateTime.Parse("29/10/2006").ToOADate(), YVal.Next(), "", axTChart1.Series(0).Color);
			axTChart1.Series(0).AddXY(DateTime.Parse("30/10/2006").ToOADate(), YVal.Next(), "", axTChart1.Series(0).Color);
			axTChart1.Series(0).AddXY(DateTime.Parse("31/10/2006").ToOADate(), YVal.Next(), "", axTChart1.Series(0).Color);
			axTChart1.Series(0).AddXY(DateTime.Parse("1/11/2006").ToOADate(), YVal.Next(), "", axTChart1.Series(0).Color);
			axTChart1.Series(0).AddXY(DateTime.Parse("2/11/2006").ToOADate(), YVal.Next(), "", axTChart1.Series(0).Color);
			axTChart1.Series(0).AddXY(DateTime.Parse("3/11/2006").ToOADate(), YVal.Next(), "", axTChart1.Series(0).Color);
			axTChart1.Series(0).AddXY(DateTime.Parse("4/11/2006").ToOADate(), YVal.Next(), "", axTChart1.Series(0).Color);

			axTChart1.Tools.get_Items(0).asColorband.Axis = axTChart1.Axis.Bottom;
			axTChart1.Tools.get_Items(0).asColorband.StartValue = DateTime.Parse("2006-11-01 08:00").ToOADate();
			axTChart1.Tools.get_Items(0).asColorband.EndValue = DateTime.Parse("2006-11-02 16:00").ToOADate();
			axTChart1.Tools.get_Items(0).asColorband.Color = System.Convert.ToUInt32(System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Blue));
			axTChart1.Tools.get_Items(0).asColorband.Transparency = 75;
			axTChart1.Tools.get_Items(0).asColorband.DrawBehind = true; 
		}

Posted: Thu Dec 21, 2006 2:47 pm
by 9528318
Hi Narcís

Thats the frustrating part, I already tried that setup. It doesn't result into an error, but it also doesn't implement a colorband... at least that was my first thought. It actually does implement a colorband, but somewhere in the year 2143 AD :shock: (no idea which year exactly but beyond 2010 AD at least).

... OK, nevermind. This is so embarrasing :oops: The database value I used for my X-axis is the number of the hour, not the actual datetime. After I corrected this it worked exactly as it should - it was all due a simple mixup of values.

My apologies for the inconvenience :oops:, and thanks for the superb support!

Best regards,

Willy (less clueless)