Page 1 of 1

How to specify data source with datetime values.

Posted: Wed Nov 12, 2008 6:45 am
by 14049736
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.

Posted: Wed Nov 12, 2008 9:41 am
by narcis
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.

Posted: Wed Nov 12, 2008 10:06 am
by 14049736
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?
:(

Posted: Wed Nov 12, 2008 11:33 am
by narcis
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.

Posted: Wed Nov 12, 2008 12:05 pm
by 14049736
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.

Posted: Wed Nov 12, 2008 4:04 pm
by Chris
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);
}

Posted: Thu Nov 13, 2008 6:50 am
by 14049736
Thanks Christopher,

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

Vijay.