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

Message ListMessage List     Post MessagePost Message

  One question about X axis label format to show timestamp
Posted by Ziyu on Jul-03-2020 04:35
Hello, I need some support to show timestamp with X axis.

For example, I have a timestamp "2017-09-06 17:53:24.963991", then I convert it to decimal with unit second,  then set x axis label format to "{value|hh:nn:ss.fff}{={value}*10000%10|0}{={value}*100000%10|0}{={value}*1000000%10|0}",

but I got the x label shown in the graph as below

17:53:24.9631091

looks the 4th decimal position '9' has been rounded up to 10. How could I get the real digit '9' here.

Thanks a lot

Br
Ziyu

  Re: One question about X axis label format to show timestamp
Posted by Peter Kwan on Jul-03-2020 13:16
Hi Ziyu,

There are several issues:

In the format, the "{...|0}" round to zero decimal place (that is, round to integer). However, what you want is to "truncate" the other digits. You may try the following format instead:

{value|hh:nn:ss}.{={value}%1*1000000-{value}%1*1000000%1|0}

The formula for truncation is x - x%1 (the original value minus the fractional part). In your case, x = {value}%1*1000000 (for 6 decimal places). As your probably know, floating point computation cannot be assumed to be accurate. So a value minus its fractional part may still differ from an integer by a very very small amount. That's why we still need to round to integer for safety.

- Another issue is that the ChartDirector date/time format internal uses a double precision floating point number, which only has 16 to 17 significant digits precision. Your number exceeds that limit. That means for your date/time, the last 2 digits may not be accurate.

Which programming language you are using? I think .NET DateTime and Java Date may be able to represent that kind of precision. Most other programming languages (eg. C++) use numbers to represent date/time, and they have the same precision limitation as ChartDirector. For example, in C++, if you use:

double d = 63640317204.963989;
printf("%20f\n", d);

you cannot get back the original number, as C++ cannot store the original number to that accuracy.

Would you mind to clarify why you need so many decimal places for date/time? If your chart covers a long time range (eg. 1 year), normally there no need to display microsecond labels on the x-axis. If your chart covers a short time (eg. 1 millisecond), you can just use a number as the x-coordinate instead of Date/Time. The date is unlikely to change during the 1ms interval, so you can omit it. If you need to display the date, you may put it somewhere else, such as in the axis title or chart title.

If you must use the full date/time and need to display microsecond precision on the x-axis, you may use custom labeling. If you need to use this method, please let me know.

Regards
Peter Kwan

  Re: One question about X axis label format to show timestamp
Posted by Peter Kwan on Jul-03-2020 16:15
Hi Ziyu,

I just found out my previous format is incorrect. The format should be:

{value|hh:nn:ss.fff}{={value}*10000%10 - {value}*10000%1|0}{value}*100000%10 - {value}*100000%1|0}{={value}*1000000%10 - {value}*1000000%1|0}

In any case, the 5th and 6th decimal place are not accurate. It is due to double precision floating point only has 16 to 17 significant digits of accuracy. (The calculation above is based on double precision numbers.)

Regards
Peter Kwan

  Re: One question about X axis label format to show timestamp
Posted by Ziyu on Jul-03-2020 17:40
Attachments:
Hello Peter

Thanks for the quick reply.

Now seems the format works, at least there is no rounded up.

I uploaded one graph about what I draw using chartdirector. (We will buy the license later of the year if we decide use this lib).

I have studied the demo about finance chart for days, but we want to use it for the data collected from a sensor network.

The data is collected to a database, which has the timestamp with accuracy of 1 micro second, 2017-09-06 17:53:24.063367, meanwhile as the dataset is so big, it may span over days even months, years. so I need a wide range number of show the time.

The chart could be zoomed in and out.

Currently in the chart, the legend is still not as I expected. the number in square bracket of top left corner shall be the same format as x axis label, and the shape of data point is also not configurable.

legendEntry << "<*block*><*img=@square,width=8,edgeColor=000000,color="
                                << hex << dataSet->getDataColor() << "*> " << name << "<*/*>";

I don't know whether there are enough predefined img like img=@square in the lib.

I need to draw a billion data. It will be a big challenge. For now I already see a delay if I draw one million data. Perhaps I need to preprocess the date (such as sampling) before pass to the lib. I will try it this later.


If it is convenient for you, I could send my code to you via mail, it is a little long to paste here although I removed non-relevant code.

Thanks again Peter

Br
Ziyu
12.png

  Re: One question about X axis label format to show timestamp
Posted by Ziyu on Jul-03-2020 17:47
Sorry I forgot to mention that I am using QT C++.