如何在 Zing Chart 中將時區設置為浮點數? (How to set time zone as float in Zing Chart?)


問題描述

如何在 Zing Chart 中將時區設置為浮點數? (How to set time zone as float in Zing Chart?)

我使用 ZingChart 將數據顯示為圖表。在字符中,我顯示了從服務器獲取的時間之後的數據。ZingChart 被設置為默認遵循客戶端時間。

我發現我們只能將圖表中的時區設置為整數值。但是,有些時區是 UTC+10:30, UTC+04:30...

那麼我們如何將時區設置為 ZingChart 顯示正確的時間呢?如果那天有夏令時,我應該如何糾正它。

JSON腳本


參考解法

方法 1:

Unfortunately it appears that ZingChart only supports whole‑hour time zone offsets. Not only does this not account for time zones with fixed fractional‑hour offsets, but it also doesn't properly account for time zones that use daylight saving time.

The example in the documentation says:

... For example, to set the timezone to Pacific Time, you would add: "timezone":‑8.

This is incorrect, as Pacific time is only at UTC‑8 during standard time. When it's in daylight time, it uses UTC‑7.

This is a common mistake. See "Time Zone != Offset" in the timezone tag wiki. My recommendation to the ZingChart developers would be:

  1. Anywhere you support timezone:‑8 you should also support fractional hour offsets such as timezone:5.5 or timezone:8.75.

  2. You should also support named time zone identifiers such as "America/Los_Angeles". To make them work, you'll need to provide a function that the developer can hook into. Don't try to implement the function directly, as there are several libraries already available for this. For example, a developer might combine ZingChart with moment‑timezone by writing something like:

    zingchart.fnTZOffset = function(timestamp, timeZone) {
        return moment(timestamp).tz(timeZone).utcOffset() / 60;
    }
    

    ZingChart would invoke this function when timezone was a string and would apply the resulting offset to the specific data point.

Without support from ZingChart, there's not much you can do to properly support time zones.

方法 2:

One other solution to the Daylight Savings time issue some ZingChart users have mentioned in the past is MomentJS. http://momentjs.com

(by Tri PhamMatt Johnson‑PintMerrily)

參考文件

  1. How to set time zone as float in Zing Chart? (CC BY‑SA 2.5/3.0/4.0)

#charts #timezone #dst #zingchart






相關問題

如何在 Playstore 或亞馬遜安卓應用中創建評論圖表? (How to create Review charts like in playstore or amazon android app?)

如何使用 XChart 使 Y 軸上的限制相同? (How to make limits on the Y axis be the same using XChart?)

擴展 SSRS 中的圖表功能 (Extending chart functionality in SSRS)

如何在 Zing Chart 中將時區設置為浮點數? (How to set time zone as float in Zing Chart?)

在重繪每個 ajax 並破壞舊的折線圖後,折線圖 (Chart.js) 上丟失了點工具提示 (lost point-tool-tips on line-chart (Chart.js) after redraw per ajax and destroying older line-chart graph)

互動你去哪兒了? (Interactivity where are you gone?)

SSRS 圖表中的可選系列? (Optional series in a SSRS chart?)

為 Google Charts Api 編寫自定義格式化程序 (Write a custom formatter for Google Charts Api)

有任何適用於 ASP.NET 的免費 PDF 或圖表生成器嗎? (Any free PDF or chart generators for ASP.NET?)

如何在這樣的 iOS 應用程序中創建圖表? (How to create charts in iOS app like this?)

與 jquery 一起使用時,Google 圖表上的 Vaxis 不顯示 (Vaxis on Google chart not showing when used with jquery)

這張股票圖可以用 Highstock 製作嗎? (Can this stock graph be made using Highstock?)







留言討論