i have just run into the same issue and found a workaround that fits my use case - YMMV.
basically, my understanding (from NVD3's source code) is that you can indeed only set a color for series, not for individual points: therefore i do add a color: '#rrggbb'
item to the values object anyways as you do in your example (just because it's easier for me to build the data structure like this), then set each series' color value from this (i'm using underscore.js but you should be able to do this in pure JavaScript):
final_groups = _.map(groups, function(values, group_id) {
return { key: group_id, color: values[0].color, values: values };
});
If you need to use a color continuum rather than setting your colours point by point or using a discrete scale, i used mbostock's advice from this answer to let D3 generate color values for me:
function compute_color_on_linear_scale(data, value, colorProperty, colorRange) {
// get a list of all the groups (this works if the colorProperty,
// aka z in your case, is numeric, otherwise the sort function
// needs to be adjusted accordingly)
// In your case, you could just write item.z rather than item[colorProperty]
// if your function doesn't need to be generic, and in that case you can
// omit the colorProperty argument from the argument list altogether
categories = _.uniq(_.map(data, function(item) {
return item[colorProperty];
}).sort(function(a,b){return a - b}), true);
// if no color range was provided, set a default one
if(typeof colorRange === 'undefined') { colorRange = ['red', 'green']; }
// this is mbostock's magic enchantment from his reply linked above
var color = d3.scale.ordinal()
.domain(categories)
.range(d3.range(categories.length).map(d3.scale.linear()
.domain([0, categories.length - 1])
.range(colorRange)
.interpolate(d3.interpolateLab)));
return color(value);
}
This should do the trick. My final touch was to hide the legend as that wouldn't make much sense in this case.
As for displaying the z value in the tooltip, you need to override the scatterChart()'s default tooltipContent() function, e.g.
var chart = nv.models.scatterChart()
.showDistX(true)
.showDistY(true)
.tooltipContent(function(key, x, y, obj) {
return '<h3>' + obj.point.label + ' (' + key + ')</h3>';
});
You can customize this as much as needed - if you just add console.log(arguments);
at the beginning of the function, you can inspect in your browser's developers tools exactly which data is available for you to use in your tooltips:
[...]
.tooltipContent(function(key, x, y, obj) {
console.log(arguments);
return '<h3>' + obj.point.label + ' (' + key + ')</h3>';
});