|
X-Axis having time as data and scale also |
Posted by Niket on Feb-21-2014 00:56 |
|
Hi,
I need to map my x-axis to time data in format hh:mm:ss:ms.
right now i am using setXData() function of linelayer and at the same moment i am also
using c.xAxis().SetLinearScale() to disable auto sacling provided by the chart director.
can any one tell me how this can be accomplished.
Regards
Niket Kumar singh |
Re: X-Axis having time as data and scale also |
Posted by Peter Kwan on Feb-21-2014 02:20 |
|
Hi Niket,
You may use c.xAxis().setLabelFormat("{value|hh:nn:ss:fff}").
Hope this can help.
Regards
Peter Kwan |
Re: X-Axis having time as data and scale also |
Posted by Niket on Feb-21-2014 21:54 |
|
Hi Peter,
I tried to use dataLayer.setXData(timeData) where timeData is array of DateTime
object.
and follow by this i called c.xAxis().setlabelFormat("{Value|hh:nn:ss:fff}") but the
behavior i observed was very much different what i was expected.
See the scenario is like this i am reading data from file for every 20ms in which data
format is like below :-
-hh:mm:ss:ms- y,y,y,y,y,y,y,y(y are different parameters for 8 different y axis )
00:02:15:240, 0,0,0,0,1,1,0,0
00:02:15:260, 0,0,0,0,1,1,0,0
00:02:15:280, 0,0,0,0,1,1,0,0
00:02:15:300, 0,0,0,0,1,1,0,0
00:02:15:320, 0,0,0,0,1,1,0,0
As you can see the first parameter in every line is nothing but the time having
hour,minute,seconds and finally millisecond.
after reading time section i create DateTime object using this
DateTime dateTime = new DateTime(1, 3, 1, 00, 02, 15, 240);
i dont want this 1,3,1 for year,month and day but the constructor needs it..is there any
way to create DateTime without year,month and day..
when i read first line, my timeData array (using in "setXData" method ) contains only one
record . At the same time i have 8 value for different y axis parameters.
Again when i read second line my timeData array now contains two record for time .
this scenario goes on until file ends.
so for example right now my timeData array contains only two record as i have read only
two lines from file.
to Draw chart i called dataLayer.setXData(timeData);
c.xAxis().setDateScale(timeData[0], timeData[timeData.Length - 1]);
chart draws ticks in x-Axis ....like 5097735.240 5097735.242 5097735.244 5097735.246
..............5097735.260
Now Peter for zooming i set the
chartWinRef.setFullRange("x", timeData[0],timeData[timeData.Count - 1]);
i have set chartWinRef.ViewPortWidth = 1; chartWinRef.ViewPortLeft = 0;
after that when i call these two method
double startTime = chartWinRef.getValueAtViewPort("x", chartWinRef.ViewPortLeft);
double
endTime = chartWinRef.getValueAtViewPort("x", chartWinRef.ViewPortLeft +
chartWinRef.ViewPortWidth);
startTime contains 5097735.24 which is right.
but the endTime contains 5097735.26 which must be wrong because it should contain
5097735.260 as i am passing viewportleft+viewPortWidth
and last when i called chart.NTime(startTime) where startTime 5097735.24 it returns a
DateTime object having value like 2:15 only , without millisecond ..where milliseconds
gone.
i need this value to search the timeData array using Chart.bSearch to get the index.
could you please help me out over these issues
Thanks in advance.
Regards
Niket Kumar singh |
Re: X-Axis having time as data and scale also |
Posted by Peter Kwan on Feb-22-2014 01:10 |
|
Hi Niket,
In human language, the word "time" has two meanings - a time instant, or a duration. For
example, 03:00:00 can mean 3:00am (an instant), or it can mean a duration of 3 hours.
In computer languages, a time "instant" is commonly represented by an object (eg.
System.DateTime in .NET, and java.util.Date in Java), while a duration can be
represented by just a number (for the duration in seconds). For millisecond precisions, in
most cases, it is referring to duration. For example, for the world record to swim 100
meters, it is a duration in millisecond precision. However, not a lot of people would be
interested in the time instant that the record is created down to millisecond precision.
For your case, are your data representing time instants, or durations? If they are
durations, it may be easier to just use numbers (an array of double) to represent the
duration in seconds as the x-coordinate. In this case, you can avoid the bogus year,
month, day that are required to represent time instants and avoid all these DateTime to
double conversions (no CDate and NDate are needed), and the code will become shorter
and cleaner. Even if your data are really time instants, if you are not interested in the
date part, you can treat them as duration since 00:00:00.
You can still format the number as hh:nn:ss:fff (with Axis.setLabelFormat) and ask
ChartDirector to auto-scale the axis using natural time labels (with Axis.setDateScale).
Normally, for numbers, ChartDirector will choose points such as 0, 50, 100, 150, .... If
you use setDateScale, ChartDirector will choose points such as 0, 60, 120, 180, ...., and
you can format these points using hh:nn:ss:fff. This may make a difference if you have
many thousands of data points with millisecond precision so the entire duration is a
minute or more.
Hope this can help.
Regards
Peter Kwan |
Re: X-Axis having time as data and scale also |
Posted by Niket on Feb-22-2014 01:45 |
|
Hi,
Thanks for the reply. Peter i want to represent x-axis as instant time scale.
although i am able to represent x-axis as a time scale .
I have a .net DateTime timeData array with two values as follows :-
00:02:15:240
00:02:15:260
using the above defined array i set the x-Axis using these calls :-
dataLayer.setXData(timeData);
c.xAxis().setDateScale(timeData[0], timeData[timeData.Length - 1]);
c.xAxis().setLabelFormat("{value|hh:nn:ss:fff}");
but when i set viewport fullRange and try to use Chart.NTime to get the value back it is
not behaving like what i expected.
code snippet:-
chartWinRef.setFullRange("x", timeData[0],timeData[timeData.Length - 1]);
chartWinRef.ViewPortWidth = 1;
chartWinRef.ViewPortLeft = 0;
now when i call
Chart.NTime(chartWinRef.getValueAtViewPort("x", chartWinRef.ViewPortLeft));
Chart.NTime(chartWinRef.getValueAtViewPort("x", chartWinRef.ViewPortLeft +
chartWinRef.ViewPortWidth));
it should give me the first and second value in timeData array which is having only two
values. also Chart.NTime giving the value without millisecond.
could you please see the above code snippet and help me out.
Thanks in advance.
Regards
Niket |
Re: X-Axis having time as data and scale also |
Posted by Peter Kwan on Feb-23-2014 00:31 |
|
Hi Niket,
The Chart.NTime can only convert the yyyy-nn-dd hh:nn:ss parts, and does not have
millisecond precision. (The Chart.CTime used to be the same as well, but it has gained
millisecond precision in recent versions of ChartDirector.) If you need millisecond precision,
you would need to add it back with your own code. You may use a function like:
DateTime convertToDateTime(double t)
{
DateTime dt = Chart.NTime(t);
return (t.Milliseconds == 0) ? t.AddMilliseconds((int)((t - (int)t) * 1000)) : t;
}
Hope this can help.
Regards
Peter Kwan |
|