追加の属性には、e.point プロパティからアクセスできます。
たとえば、ツールチップ パーツの場合、次のようなコードを使用できます。
var chart = nv.models.multiBarChart()
.options({
showXAxis: true,
showYAxis: true,
transitionDuration: 250
}).tooltip(function (key, x, y, e, graph) {
if (e.point.isHoliday) {
//your custom code here
}
}
他の 2 つの質問に対するその他のオプションを次に示します。
バーの色を変更するには、次のようにします。
d3.selectAll("rect.nv-bar")
.style("fill-opacity", function (d, i) { //d is the data bound to the svg element
//Used opacity here but anything can be changed
return d.isHoliday ? .8 : .6;
})
ラベル部分については、ラベルをより詳細に制御する必要があったため、tickFormat コールバックの代わりに以下のコードを選択しました。
d3.select('.nv-x.nv-axis > g').selectAll('g').selectAll('text')
.attr('transform', function (d, i, j) {
return d.isHoliday ? 'translate (0, 15)' : ''; //Lowers the label text for the holiday instances
})
.attr('class', function (d, i, j) {
return d.isHoliday ? 'holiday-graph-legend' : 'default-graph-legend';
})