How to specify data source with datetime values.

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
vijay
Newbie
Newbie
Posts: 42
Joined: Thu Jul 31, 2008 12:00 am
Contact:

How to specify data source with datetime values.

Post by vijay » Wed Nov 12, 2008 6:45 am

Hi,
I want to plot a collection of double values against date time. Is it possible to specify the data source property of a series rather than making use of the add or add range function?(Because i have some bulk data to plot in series, about 1 sec interval data of 8 hours).

I was able to plot a collection of y values against its index by specifying data source as a collection. But i want to plot it against date time.
Is there any simple way rather than adding each element.

Thanks,
Vijay.

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 Nov 12, 2008 9:41 am

Hi Vijay,

Yes, you can find an example of datasource using DateTime values here.

I also recommend you to read Tutorial8 - ADO.NET Database Access. You'll find the tutorials at TeeChart's 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

vijay
Newbie
Newbie
Posts: 42
Joined: Thu Jul 31, 2008 12:00 am
Contact:

Post by vijay » Wed Nov 12, 2008 10:06 am

Hello Narcís,
For example,
public class Data
{
public double Value { get; set; }
public DateTime Time { get; set; }
public string Unit { get; set; }
}
public class Values : Collection<Data>
{
//
}
I have created an object of Values class and added some Data objects to it.

In tchart. is it possible to bind these Values instance like this,
tChart.Series[0].XValues.DateTime = true;
tChart.Series[0].XValues.DataMember = "Time";
tChart.Series[0].YValues.DataMember = "Value";
tChart.Series[0].DataSource = values;

I was able to bind it but i was forced to implement IConvertible in Data class.

But in real scenario, my Data object does not implement IConvertible (It is of a third party). Any solution?
:(

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 Nov 12, 2008 11:33 am

Hi vijay,
I was able to bind it but i was forced to implement IConvertible in Data class.
Why? Could you please send us a full example project we can run "as-is" to reproduce the problem here?

You can either post your files at news://www.steema.net/steema.public.attachments newsgroup or at our upload page.

Thanks in advance.
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

vijay
Newbie
Newbie
Posts: 42
Joined: Thu Jul 31, 2008 12:00 am
Contact:

Post by vijay » Wed Nov 12, 2008 12:05 pm

If i didn't implement IConvertible it will throw an exception
"Unable to cast Data to IConvertible"

I have uploaded the sample project.(TeeChartTest)

Thanks,
Vijay.

Christopher
Site Admin
Site Admin
Posts: 1349
Joined: Thu Jan 01, 1970 12:00 am
Location: Riudellots de la Selva, Catalonia
Contact:

Post by Christopher » Wed Nov 12, 2008 4:04 pm

vijay,
vijay wrote:If i didn't implement IConvertible it will throw an exception
"Unable to cast Data to IConvertible"
No, if you can't modify your Data object then you won't be able to get this to work. As your Values class implements IList, it is added to the chart in the overload Steema.TeeChart.Styles.Series.Add(IList list), the source of which looks like this:

Code: Select all

public void Add(IList list)
{
	for (int t = 0; t < list.Count; t++)
		Add(Convert.ToDouble(list[t]));
}
The ToDouble overload here is the ToDouble(object value), the source of which looks like this:

Code: Select all

public static double ToDouble(object value)
{
    if (value != null)
    {
        return ((IConvertible) value).ToDouble(null);
    }
    return 0.0;
}
Here you can see that the value has to implement the IConvertible interface.

So, the only thing you can do, I'm afraid, is to iterate through the members of your Value class and add them into TChart using the Series.Add(...) overloads in the normal way, e.g.

Code: Select all

tChart1.Series.Add(fastLine);

this.GetData();

Data[] array = values.ToArray<Data>();
foreach (Data d in array)
{
	tChart1.Series[0].Add(d.Time, d.Value);
}
Thank you!

Christopher Ireland (Steema crew)
Please be aware of the newsgroup archives:
http://www.teechart.net/support/search.php
http://groups.google.com
http://codenewsfast.com/

vijay
Newbie
Newbie
Posts: 42
Joined: Thu Jul 31, 2008 12:00 am
Contact:

Post by vijay » Thu Nov 13, 2008 6:50 am

Thanks Christopher,

I have somehow made it with a custom class by implementing IList.
Thanks for your information.

Vijay.

Post Reply