简体   繁体   English

在d3.js中的x轴上以不同格式打印日期

[英]printing date in different format on x-axis in d3.js

I am using D3.js to build this line chart.and its working fine . 我正在使用D3.js构建此折线图及其工作正常。 but i am not able to print the months on x-axis in abbreviated form (jan,feb....) 但我无法以缩写形式在X轴上打印月份(jan,feb ....)

here how i am parsing the date. 这是我解析日期的方式。

var parseDate = d3.time.format("%m-%Y").parse;

the code for x-axis x轴代码

var xAxis = d3.svg.axis().scale(x).orient("bottom");

and printing and appending 以及打印和附加

svg.append("g")
  .attr("class", "x axis")
  .attr("transform", "translate(0," + height + ")")
  .call(xAxis);

help me with this. 帮助我。

只需在内部使用d3.time.format的tickFormat

var xAxis = d3.svg.axis().scale(x).orient("bottom").tickFormat(d3.time.format("%H"))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM