0

I am trying to insert current date to subtitle in highcharts as below:

   subtitle: {
     text: function() {
       var d = new Date();
       return '<b>' +  d + '</b>';
     },
   },

I am not getting Date value instead I am getting the function printed as the subtitle. Any ideas?

4

2 回答 2

1

d.toDateString(); 或 d.toLocaleDateString(); 或 d.toString(); ...

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date?redirectlocale=en-US&redirectslug=JavaScript%2FReference%2FGlobal_Objects%2FDate

于 2013-06-12T22:07:44.087 回答
0

如果您使用函数,则需要通过自动运行函数(闭包)调用:

 text: (function () {
            return 'aaaaa dynamic'
        })(),

http://jsfiddle.net/Kem7d/

于 2013-06-13T11:35:52.440 回答