Use data field in chart subtitle

Clash Royale CLAN TAG#URR8PPPUse data field in chart subtitle
I have charts with some data imported from a CSV. Among this data, there is a "year" field. For each chart to be displayed, I would like to have a subtitle which changes dynamically according to the year the chart is displaying.
For instance, if I'm displaying data from 2017 ("year" field in my data object), I would like to have a title "Rain data" and a subtitle "Year 2017", and the same if I switch to every year in my data object. Roughly, it should be something like:
.title({
value: "Distribució de la població per edat i sexe",
sub: function(){
return "Year " + data.year;
}
})
I've tried to do something similar to what's done in the formatting function with the params and keys, but it just doesn't recognize the fields:
.format({
"text": function(text, params) {
if (text === "usd") {
return "Trade Value";
}
else {
return d3plus.string.title(text, params);
}
},
"number": function(number, params) {
var formatted = d3plus.number.format(number, params);
if (params.key === "usd") {
return "$" + formatted + " USD";
}
else {
return formatted;
}
}
})
However, I've never been able to make this syntax work outside of formatting functions.
TLDR: How can I access fields in my data in D3plus once the data object is loaded?
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.