【问题标题】:anychart stock with julian date on x axisX 轴上带有朱利安日期的任何图表股票
【发布时间】:2023-02-21 19:24:54
【问题描述】:

是否可以在股票图中使用 Julian 日期或以 Julian 日期格式显示 x 轴? 我尝试使用返回 Julian 日期但没有成功的函数来格式化 x 轴

【问题讨论】:

    标签: stock anychart


    【解决方案1】:

    可以change the labels of a stock chart to a Julian Year Date,使用自定义formatting functions and tickvalue。 如果您正在寻找absolute Julian date,您可以探索changing a Gregorian calendar to a Julian的类似方法。 转换函数示例:

    // Converting Calendar to a Julian
    Date.prototype.julianDayOfTheYear=function(){
        var j=parseInt((this.getTime()-new Date('Dec 30,'+(this.getFullYear()-1)+' 23:00:00').getTime())/86400000).toString(),
        i=3-j.length;
        while(i-->0)j=0+j;
        
        return j
    };
    
    // Converting Calendar to a Julian Year Date
    Date.prototype.julianDayOfTheYear=function(){
        var j=parseInt((this.getTime()-new Date('Dec 30,'+(this.getFullYear()-1)+' 23:00:00').getTime())/86400000).toString(),
        i=3-j.length;
        while(i-->0)j=0+j;
        
        return j
    };
    

    格式化函数示例:

    // Current Julian date getter function
        var julianGetter = (e) => {
        var labelDate = new Date(e);
        var untrimmedData = labelDate.julianDayOfTheYear();
        
        // Trimming 0's at the start of the date
        for (var i = 0; i < untrimmedData.length; i++) {
            if (untrimmedData.charAt(i) == '0') {
             untrimmedData = untrimmedData.slice(1);
             i--; // update index to account for the removed character
            } else { break }
        }
        return untrimmedData;
    }
    
    // Changing labels of xAxis to Julian
        chart.plot(0).xAxis().labels().format((e)=>julianGetter(e.tickValue))
      
      // Changing minor labels of xAxis to Julian
        chart.plot(0).xAxis().minorLabels().format((e)=>julianGetter(e.tickValue))
    

    我们希望这些方法能够很好地满足您的需求。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-13
      相关资源
      最近更新 更多