我有一个散点图,在我的X轴上绘制每个日期的独特事件,以及它们在Y轴上每一天发生的时间。
为此,我获取了用于X轴的日期数据,并通过一个函数运行该数据,该函数将输出事件发生当天的确切秒数(0到86400)。从这个意义上说,我的Y轴从86400秒到3秒。
这使得我可以在图表上以点的形式唯一地表示每个点,直到第二个点。
我对我的图表结果很满意:
?
?
唯一的问题是我的Y标签从0到86400。我想将文本更改为熟悉的HH AM/PM格式,可能类似于"0 to 23,where : if (y value = 3600) return "1 AM“。
我的散点图如下所示:
scatterPlot
.width(window.innerWidth-100)
.height(window.innerHeight/2)
.x(d3.time.scale().domain([minDate, maxDate]))
.brushOn(false)
.mouseZoomable(true)
// .title(function (d) {
// return "Event: " + d['text'];
// })
.clipPadding(5)
.yAxisLabel("Hour of the day")
.elasticY(true)
.dimension(eventsByDateAndHourDim)
.group(eventsByDateAndHourGroup);
我试着这样做:
scatterPlot.yAxis().tickFormat(function (d) {
if (domain = 43200)
return "12 PM";
})
但这只会将所有标签更改为"12 PM“。我不确定如何引用我的Y域的实际值。
我尝试使用组"if (eventsByDateAndHourGroup = 43200)...“但这也不管用。
转载请注明出处:http://www.bigbigcall.com/article/20230330/2363193.html