Sampath
Sampath

Reputation: 163

Change date format to string d3 js

I'm trying to change the label format from date to string.

I tried changing the formats but it didn't work. Here is my codepen: https://codepen.io/sampath-PerOxide/pen/bzVOoG

var dateformat = "%Y-%m"
drawTimeSeriesGraph(data1, dateformat);

I want to pass the string in the place of the date.

Upvotes: 0

Views: 281

Answers (1)

ksav
ksav

Reputation: 20821

You can format your axis ticks however you like with tickFormat. Just pass it your own function that returns the string you want based on the data (the function can access the current datum and index).

xAxis.tickFormat((d, i) => {
    const date = formatDate(d)
    return `${date} - Month ${i+1}`
});

Codepen

Upvotes: 1

Related Questions