I have one of NVD3.js's line plus bar charts configured as below. Of course, each series of data has its own color for the bar/line display on the chart. I'm curious if there's a built-in way to set the Y-axis associated with a particular series to the same color as that series. In my example below, that would mean that:
a) the left axis and the bar chart would be "steelblue"
b) the right axis and the line chart would be "skyblue"
I stepped through the NVD3 and D3 code a little bit looking at the axis objects, but I didn't find anything that seemed like it would set this sort of an option.
Thanks in advance for any insight into this feature, present or otherwise!
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<title>Line + Bar Chart | NVD3.js</title>
<link rel="stylesheet" href="nv.d3.css"/>
<style>
#chart svg {
height: 400px;
}
</style>
</head>
<body>
<div id="chart">
<svg></svg>
</div>
<script src="d3.js"></script>
<script src="nv.d3.js"></script>
<script>
var data = [
{
'key': 'foo',
'bar': true,
'color': 'skyblue',
'values': [
[1431993600000, 31.6882],
[1432080000000, 76.1706],
[1432166400000, 76.2297],
[1432252800000, 75.1944],
[1432339200000, 75.1536],
[1432425600000, 74.528],
[1432512000000, 75.7265],
[1432598400000, 75.8659],
[1432684800000, 74.6283],
[1432771200000, 73.3533]
]
},
{
'key': 'bar',
'color': 'steelblue',
'values': [
[1431993600000, 0.0002997961386257345],
[1432080000000, 0.0004418193656404055],
[1432166400000, 0.0003122142681920564],
[1432252800000, 0.00031651293181407124],
[1432339200000, 0.0003845457835685849],
[1432425600000, 0.00031934306569343066],
[1432512000000, 0.0005163317993040745],
[1432598400000, 0.00042575122683577205],
[1432684800000, 0.00025057518394496457],
[1432771200000, 0.00041715914621428076]
]
}
];
nv.addGraph(function () {
var chart = nv.models.linePlusBarChart()
.margin({
top: 30,
right: 60,
bottom: 50,
left: 70
})
.x(function (d, i) {
return i;
})
.y(function (d, i) {
return d[1];
})
.options({
focusEnable: false,
showLegend: false
});
chart.xAxis
.showMaxMin(true)
.tickFormat(function (d) {
var dx = data[0].values[d] && data[0].values[d][0] || 0;
return d3.time.format('%x')(new Date(dx));
});
chart.y1Axis
.tickFormat(d3.format(',f'));
chart.y2Axis
.tickFormat(function (d) {
return d3.format('g')(d)
});
chart.bars.forceY([0, 200]);
chart.lines.forceY([0]);
d3.select('#chart svg')
.datum(data)
.transition()
.duration(0)
.call(chart);
nv.utils.windowResize(chart.update);
return chart;
});
</script>
</body>
</html>