寻找一种方法来输出NVD3工具提示中的日期格式与x-axis
上的日期格式不同。
目前显示日期为
chart.xAxis
.tickFormat(function(d) {
return d3.time.format('%d / %m')(new Date(d))
});
如何在%d/%m/%y
中输出日期作为x-axis
,同时保持%d/%m
为chart.tooltip.contentGenerator
?
您可以使用chart.tooltip.contentGenerator(function (d) {
var html = "<h2>Date: "+ d3.time.format('%d/%m/%y')(new Date(d.value))+"</h2> <ul>";
d.series.forEach(function(elem){
html += "<li><h3 style='color:"+elem.color+"'>"
+elem.key+"</h3><b>"+elem.value+"</b></li>";
})
html += "</ul>"
return html;
创建自定义工具提示。添加一行,以您想要的格式输出日期。例如:
http://jsfiddle.net/wgmpfa2p/5/
这是一个有效的JSFiddle供参考:qazxswpoi