Your question was a bit inaccurate: you are using C3.js, which will generate the svg element.
So the markup returned was actually <tspan dx="0" dy=".71em" x="0">0<br>2014</tspan> .
C3 will use the textContent property for tspan to add the text content returned by your function.
As mentioned in other questions , you cannot add line breaks to <tspan> elements.
Thus, the solution effectively creates a new tspan directly below another, in the same <text> element.
Unfortunately, there is no way to get these exact elements, except by looping all the rest of the tspans, so this may sound like a real hack, but here is a script that will do what you want ...
var chart = c3.generate({ data: { json: [{ date: '2014-01-01', upload: 200, download: 200, total: 400 }, { date: '2014-01-02', upload: 100, download: 300, total: 400 }, { date: '2014-02-01', upload: 300, download: 200, total: 500 }, { date: '2014-02-02', upload: 400, download: 100, total: 500 }], keys: { x: 'date', value: ['upload', 'download'] } }, axis: { x: { type: 'timeseries', tick: { format: function (x) { if (x.getDate() === 1) { return x.getMonth() + '\n' + x.getFullYear(); } } } } } });
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.4.11/d3.min.js"></script> <script src="https://rawgit.com/masayuki0812/c3/master/c3.js"></script> <link href="https://rawgit.com/masayuki0812/c3/master/c3.css" rel="stylesheet"> <div id="chart"></div>
Kaiido
source share