ASE Home Page Products Download Purchase Support About ASE
ChartDirector Support
Forum HomeForum Home   SearchSearch

Message ListMessage List     Post MessagePost Message

  Displaying local times in X axis
Posted by Taylor on Dec-18-2013 03:58
I understand that ChartDirector doesn't have a concept of time zones. So to display local
times, I need to somehow apply the UTC offset of the local time zone. Using Qt, this would
look like:

QDateTime t = QDateTime::fromMSecsSinceEpoch(time*1000);
time = Chart::chartTime(t.date().year(), t.date().month(), t.date().day(), t.time().hour(),
t.time().minute(), t.time().second());

However, this approach has one major issue that I can think of... If at some point in the
series of timestamps, we cross the daylight savings boundary, the times will jump forward
(or worse, backward).

Is there any way to address this issue? What I'd like is to set the values as universal times,
since this is the only way to have no ambiguity, but DISPLAY them as local times. So that
when looking at the time tick marks, I would see, for example: "1:58, 1:59, 1:00, 1:01",
when the DST boundary is crossed

  Re: Displaying local times in X axis
Posted by Taylor on Dec-18-2013 05:43
Also: I realize I can ALMOST get what I want by generating the axis marker labels myself
and using "setDateScale2". But this would require that the left and right ends of my graph
are aligned with axis markers, which is not always the case.

  Re: Displaying local times in X axis
Posted by Peter Kwan on Dec-19-2013 00:09
Hi Taylor,

You can use the following method:

- Use setDataScale2 to define an axis scale with no labels (use an empty labels array)

- Use Axis.addLabel to put labels at the positions you want.

Hope this can help.

Regards
Peter Kwan

  Re: Displaying local times in X axis
Posted by Taylor on Dec-19-2013 01:19
Exactly what I was looking for; thank you Peter!

I had tried using addLabel before, but for some reason didn't get it to work, but it does
after calling setDateScale2.

  Re: Displaying local times in X axis
Posted by Brian Struhammer on Nov-22-2014 04:09
Peter,

I had a similar issue with daylight savings time labeling, and was able to take the code you provided to Taylor to create custom labels on my y-axis, which will move ahead/back 1 hour as needed.

However, I have a follow-on question to this. Prior to manually supplying the labels, I had been using the setFormatCondition/setMultiFormat function pair to automatically vary the format of the labels on that axis for when the operator zooms in or out, depending on whether we're on an hourly or daily schedule. I assume that means I have to manually control this so I can still handle the 1-hour DST delta, by somehow recognizing the range of date/times within the viewer, and manually re-formatting the labels as necessary.

Is that true, and if so, how do I recognize for when an operator zooms, what the date/time range being displayed is?

Appreciate your help on this.

Brian

  Re: Displaying local times in X axis
Posted by Peter Kwan on Nov-24-2014 17:01
Hi Brian,

You can obtain the visible range of the axis using getValueAtViewPort.

For example, in the "Zooming and Scrolling with Track Line" sample code, in the beginning of
the drawChart subroutine, there should be two lines like:

DateTime viewPortStartDate = Chart.NTime(viewer.getValueAtViewPort(
"x", viewer.ViewPortLeft));
DateTime viewPortEndDate = Chart.NTime(viewer.getValueAtViewPort(
"x", viewer.ViewPortLeft + viewer.ViewPortWidth));

(Note: The above is taken from .NET edition of ChartDirector. The exact code may differ
depending on which programming language edition of ChartDirector you are using.)

The viewPortStartDate and viewPortEndDate represents the date range which is visible.

Hope this can help.

Regards
Peter Kwan

  Re: Displaying local times in X axis
Posted by Brian Struhammer on Dec-11-2014 03:03
Attachments:
Thanks Peter,
Sorry it's taken awhile to get back to you. I had a whole series of questions since that one, but I've been slowly working my way through them without having to bother you.

I'm down to hopefully my last issue, which I may or may not figure out on my own. I'm trying to use a single scroll bar to control 2 charts, a XY line chart for environmental data, and a stacked bar chart with the XY axes swapped, to be used like a Gantt chart. Both axes work off the manually controlled labeling from the stacked bar chart, and things look pretty good, including handling daylight savings time adjustments. However, when I zoom in (which works fine) and then try to scroll by clicking on the scroll control (as opposed to dragging the scroll bar), occasionally the line chart is shortened on both ends as seen in the attached file (note: I have not added a margin yet to the right end, just to make sure that is not related to the problem). I suspect that the viewer range/percentages somehow get out of synch with the line data. If you have any suggestions, that would be great. In the meantime, I'll keep poking around when I get a chance.

Thanks again.
Chart End Gaps.png

  Re: Displaying local times in X axis
Posted by Peter Kwan on Dec-12-2014 01:08
Hi Brian,

May be you can check if this is due to the line not being overdrawn. For the line chart to
work correctly during zoom-in, it has to overdrawn.

For example, suppose you have five data points at x = 0, 1, 2, 3, 4. If you zoom-in to view
the range x = 1.4 to 3.5, you would need to plot the points from 1 to 4, even though the
points at x = 1 and x = 4 are outside the visible range. If you just plot the points within the
visible range (which just contains two points at x = 2 and x = 3), there will be gaps
between x = 1.4 and x = 2, and between x = 3.5 to x = 4.

In our zooming and scrolling sample code, the code uses the Math.Floor and Math.Ceiling
function to obtain one additional point outside the selected range if necessary. There is also
a line that calls XYChart.setClipping to ensure the overdrawn part is clipped to the plot
area.

Regards
Peter Kwan

  Re: Displaying local times in X axis
Posted by Brian Struhammer on Jan-05-2015 10:11
Hey Peter,
Thanks for the info. I think that you?re onto something about the line not being overdrawn. Now I couldn?t  use the Math.Floor and Math.Ceiling calls like you suggest, because I had to wrap them with the Chart.NTime call, as follows:
DateTime viewPortStartDate = Chart.NTime(Math.Floor(viewer.getValueAtViewPort("x", viewer.ViewPortLeft)));
When I did this, I got an exception. I didn?t look a lot into the reason of the exception, other than I saw that the Math.Floor call resulted in a negative value, which I?m guessing that the Chart.NTime call didn?t like.
However, I did adjust my start and end index values, as follows, which appears to have fixed the problem, though much more testing is required (I may even look more into the exception, to see what?s causing that).
     int startIndex = (int)BinarySearchDates(viewPortStartDate) - 1;
     int endIndex = (int)BinarySearchDates(viewPortEndDate) + 1;

Thanks again,
Brian

  Re: Displaying local times in X axis
Posted by Peter Kwan on Jan-06-2015 02:19
Hi Brian,

In the original sample code that comes with ChartDirector, the Math.Ceiling and Math.Floor
is applied to the index to allow you to obtain one additional date on either direction. I have
copied the original sample code as follows:

DateTime viewPortStartDate = Chart.NTime(viewer.getValueAtViewPort("x",
viewer.ViewPortLeft));
DateTime viewPortEndDate = Chart.NTime(viewer.getValueAtViewPort("x",
viewer.ViewPortLeft + viewer.ViewPortWidth));

// Get the array indexes that corresponds to the visible start and end dates
int startIndex = (int)Math.Floor(Chart.bSearch(timeStamps, viewPortStartDate));
int endIndex = (int)Math.Ceiling(Chart.bSearch(timeStamps, viewPortEndDate));

I thinking adding -1 and 1 to the indexes are not ideal. It is possible to get negative index
or indexes that are out of bounds of your array. For example, if your "BinarySearchDates"
function returns 0, the startIndex will become negative. On the other hand, the Math.Floor
cannot return negative numbers if Chart.bSearch is non-negative. Similarly, the Math.Ceiling
cannot return out of bound index.

Hope this can help.

Regards
Peter Kwan

  Re: Displaying local times in X axis
Posted by Brian Struhammer on Jan-09-2015 05:52
Thanks Peter,

Putting the Math.Floor and Math.Ceiling calls around the index instead of the viewer viewer.getValueAtViewPort helped (and made sense). I was worried about the -1/+1 approach causing problems, even though I had already checked to make sure it didn't go below 0, but I hadn't checked the upper end for exceeding the array limit. This works better anyway.

At this point, the only problem I'm aware of is when I zoom in, I can't scroll to the far end. I can scroll all the way to the left, but not the right. I'll look into it when I can.

Brian

  Re: Displaying local times in X axis
Posted by Peter Kwan on Jan-10-2015 03:39
Hi Brian,

Your code should have configured the "full range" of the x-axis using setFullRange. If your
code does not do this, ChartDirector will automatically assume the "full range" to be the first
chart that was displayed. In any case, the scrolling cannot exceed the full range. For
example, if the full range is from "Jan 1, 2014" to "Jan 1, 2015", then you cannot scroll
beyond Jan 1, 2015, even if your database or data array contains data beyond that date.

To diagnose the problem, you may "single step" the code to see if the values are what you
expect. For example, in the code:

DateTime viewPortEndDate = Chart.NTime(viewer.getValueAtViewPort("x",
viewer.ViewPortLeft + viewer.ViewPortWidth));

If you have scrolled to the rightmost position, the (viewer.ViewPortLeft +
viewer.ViewPortWidth) should equal to 1, and viewPortEndDate should be the date at the
rightmost position.

Regards
Peter Kwan

  Re: Displaying local times in X axis
Posted by Brian Struhammer on Jan-14-2015 06:17
Single stepping worked fine. Thanks Peter. Great support.

Brian

  Re: Displaying local times in X axis
Posted by Brian Struhammer on Jan-14-2015 06:17
Single stepping worked fine. Thanks Peter. Great support.

Brian