Profile Picture

Database Binding with DateTimeScale

Posted By Bhumi Patel 12 Years Ago
Author
Message
Bhumi Patel
Posted 12 Years Ago
View Quick Profile
Forum Member

Forum Member (34 reputation)Forum Member (34 reputation)Forum Member (34 reputation)Forum Member (34 reputation)Forum Member (34 reputation)Forum Member (34 reputation)Forum Member (34 reputation)Forum Member (34 reputation)Forum Member (34 reputation)

Group: Forum Members
Last Active: 11 Years Ago
Posts: 33, Visits: 1
Thank you Nevron Team for your reply!! This works fine for me!!

Thanks again,
Bhumi

Nevron Support
Posted 12 Years Ago
View Quick Profile
Supreme Being

Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)

Group: Forum Members
Last Active: Last Week
Posts: 3,054, Visits: 4,009

Hi Bhumi,

You simply need to add each pair of value/date time to the series - like:

someLineSeries.Values.Add(value);
someLineSeries.XValues.Add(someDateTime.ToOADate());

you also need to make sure the series uses Xvalues:

someLineSeries.UseXValues = true;



Best Regards,
Nevron Support Team



Bhumi Patel
Posted 12 Years Ago
View Quick Profile
Forum Member

Forum Member (34 reputation)Forum Member (34 reputation)Forum Member (34 reputation)Forum Member (34 reputation)Forum Member (34 reputation)Forum Member (34 reputation)Forum Member (34 reputation)Forum Member (34 reputation)Forum Member (34 reputation)

Group: Forum Members
Last Active: 11 Years Ago
Posts: 33, Visits: 1
Thanks for your reply.

I think there is a little misunderstanding here. My actual requirement is to plot values with respect to a specific datetime. I have not found any examples on the Nevron website which shows the “how to plot values from database with datetimescale”. All I have found is how to plot random values with datetimescale.

To elaborate more on my requirement, here is an example of what I get from the database:

Value  DateTime
278    2012-02-19 12:00:00
187    2012-02-19 12:05:00
247    2012-02-19 12:10:00
156    2012-02-19 12:15:00
216    2012-02-19 12:20:00
276    2012-02-19 12:25:00
185    2012-02-19 12:30:00
245    2012-02-19 12:35:00

I am able to plot the XAxis values, but how do I relate “Value” with “Datetime” (as shown in the table above) that I am getting from the database, instead of the Random?

Thanks in advance.

Nevron Support
Posted 12 Years Ago
View Quick Profile
Supreme Being

Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)

Group: Forum Members
Last Active: Last Week
Posts: 3,054, Visits: 4,009

Hi Bhumi,

We're still not sure what exactly you want to achive, one guess is that you want to display the actual x value (instead of the one generated by the date time axis, which will be day start, hour start, minute start etc. depending on the unit chosen by the scale. If this is the case you can simiply switch the scale in custom ticks mode and pass the x values to the scale as well:

   NChart chart = nChartControl1.Charts[0];

   NDateTimeScaleConfigurator dtScale = new NDateTimeScaleConfigurator();
   chart.Axis(StandardAxis.PrimaryX).ScaleConfigurator = dtScale;

   dtScale.MajorTickMode = MajorTickMode.CustomTicks;

   NLineSeries line = new NLineSeries();
   chart.Series.Add(line);

   line.UseXValues = true;
   line.DataLabelStyle.Visible = false;

   DateTime current = DateTime.Now;
   TimeSpan span = new TimeSpan(0, 4, 0, 0);

   Random rand = new Random();

   for (int i = 0; i < 10; i++)
   {
    line.Values.Add(rand.Next(100));
    line.XValues.Add(current);
    dtScale.CustomMajorTicks.Add(current);

    current += span;
   }

If this is not the desired result, please elaborate...



Best Regards,
Nevron Support Team



Bhumi Patel
Posted 12 Years Ago
View Quick Profile
Forum Member

Forum Member (34 reputation)Forum Member (34 reputation)Forum Member (34 reputation)Forum Member (34 reputation)Forum Member (34 reputation)Forum Member (34 reputation)Forum Member (34 reputation)Forum Member (34 reputation)Forum Member (34 reputation)

Group: Forum Members
Last Active: 11 Years Ago
Posts: 33, Visits: 1
Thank you Nevron Team for your quick reply.

But my concern is with YValue. How can I map the X-axis DateTime with Y-axis value?? (lineSeries.Values.Add(?)) Because DateTimeScale handles the XValues using TimeSpan.

Please review attached chart image. It displays 500 value for 12:00 AM. But in my database, the actual value at 12:00 AM is not 500. The X-values and Y-values are not mapped properly.

Thanks in advance!!

Attachments
TrendingChart.png (53 views, 47.00 KB)
Nevron Support
Posted 12 Years Ago
View Quick Profile
Supreme Being

Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)

Group: Forum Members
Last Active: Last Week
Posts: 3,054, Visits: 4,009

Hi Bhumi,

The code looks Ok - most likely you did not switch the line series in scatter mode:

lineSeries.UseXValues = true;

Hope this helps - let us know if you meet any problems.



Best Regards,
Nevron Support Team



Bhumi Patel
Posted 12 Years Ago
View Quick Profile
Forum Member

Forum Member (34 reputation)Forum Member (34 reputation)Forum Member (34 reputation)Forum Member (34 reputation)Forum Member (34 reputation)Forum Member (34 reputation)Forum Member (34 reputation)Forum Member (34 reputation)Forum Member (34 reputation)

Group: Forum Members
Last Active: 11 Years Ago
Posts: 33, Visits: 1
Hi All,

I am experiencing some difficulties while binding data from database with DateTimeScale. I am retrieving 2 different lists from database: list of DateTime(with 5 min interval) and list of values. I am not sure how can I relate the datetime with the value. Please review my code below:

DateTime StartDate = DateTimeList[0];
DateTime EndDate = DateTimeList[DateTimeList.Count - 1];

TimeSpan span = EndDate - StartDate;
span = new TimeSpan(span.Ticks / 30);

if (span.Ticks > 0)
{
while (StartDate < EndDate)
{
StartDate += span;
lineSeries.XValues.Add(StartDate);
lineSeries.Values.Add(?);
count++;
}
}



Similar Topics


Reading This Topic