Added no data available message to sparklineplus
This commit is contained in:
parent
bded864229
commit
0c8cf9261d
32
nv.d3.js
32
nv.d3.js
@ -7842,7 +7842,9 @@ nv.models.sparklinePlus = function() {
|
|||||||
color = nv.utils.defaultColor(),
|
color = nv.utils.defaultColor(),
|
||||||
id = Math.floor(Math.random() * 100000), //Create semi-unique ID incase user doesn't selet one
|
id = Math.floor(Math.random() * 100000), //Create semi-unique ID incase user doesn't selet one
|
||||||
xTickFormat = d3.format(',r'),
|
xTickFormat = d3.format(',r'),
|
||||||
yTickFormat = d3.format(',.2f');
|
yTickFormat = d3.format(',.2f'),
|
||||||
|
noData = "No Data Available."
|
||||||
|
;
|
||||||
|
|
||||||
var x = d3.scale.linear(),
|
var x = d3.scale.linear(),
|
||||||
y = d3.scale.linear(),
|
y = d3.scale.linear(),
|
||||||
@ -7853,6 +7855,27 @@ nv.models.sparklinePlus = function() {
|
|||||||
var availableWidth = width - margin.left - margin.right,
|
var availableWidth = width - margin.left - margin.right,
|
||||||
availableHeight = height - margin.top - margin.bottom;
|
availableHeight = height - margin.top - margin.bottom;
|
||||||
|
|
||||||
|
|
||||||
|
//------------------------------------------------------------
|
||||||
|
// Display No Data message if there's nothing to show.
|
||||||
|
|
||||||
|
if (!data || !data.length || !data.filter(function(d) { return d.values.length }).length) {
|
||||||
|
container.append('text')
|
||||||
|
.attr('class', 'nvd3 nv-noData')
|
||||||
|
.attr('x', availableWidth / 2)
|
||||||
|
.attr('y', availableHeight / 2)
|
||||||
|
.attr('dy', '-.7em')
|
||||||
|
.style('text-anchor', 'middle')
|
||||||
|
.text(noData);
|
||||||
|
return chart;
|
||||||
|
} else {
|
||||||
|
container.select('.nv-noData').remove();
|
||||||
|
}
|
||||||
|
|
||||||
|
//------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
x .domain(d3.extent(data, getX ))
|
x .domain(d3.extent(data, getX ))
|
||||||
.range([0, availableWidth]);
|
.range([0, availableWidth]);
|
||||||
|
|
||||||
@ -7989,6 +8012,13 @@ nv.models.sparklinePlus = function() {
|
|||||||
return chart;
|
return chart;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
chart.noData = function(_) {
|
||||||
|
if (!arguments.length) return noData;
|
||||||
|
noData = _;
|
||||||
|
return chart;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
return chart;
|
return chart;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
2
nv.d3.min.js
vendored
2
nv.d3.min.js
vendored
File diff suppressed because one or more lines are too long
@ -9,7 +9,9 @@ nv.models.sparklinePlus = function() {
|
|||||||
color = nv.utils.defaultColor(),
|
color = nv.utils.defaultColor(),
|
||||||
id = Math.floor(Math.random() * 100000), //Create semi-unique ID incase user doesn't selet one
|
id = Math.floor(Math.random() * 100000), //Create semi-unique ID incase user doesn't selet one
|
||||||
xTickFormat = d3.format(',r'),
|
xTickFormat = d3.format(',r'),
|
||||||
yTickFormat = d3.format(',.2f');
|
yTickFormat = d3.format(',.2f'),
|
||||||
|
noData = "No Data Available."
|
||||||
|
;
|
||||||
|
|
||||||
var x = d3.scale.linear(),
|
var x = d3.scale.linear(),
|
||||||
y = d3.scale.linear(),
|
y = d3.scale.linear(),
|
||||||
@ -20,6 +22,27 @@ nv.models.sparklinePlus = function() {
|
|||||||
var availableWidth = width - margin.left - margin.right,
|
var availableWidth = width - margin.left - margin.right,
|
||||||
availableHeight = height - margin.top - margin.bottom;
|
availableHeight = height - margin.top - margin.bottom;
|
||||||
|
|
||||||
|
|
||||||
|
//------------------------------------------------------------
|
||||||
|
// Display No Data message if there's nothing to show.
|
||||||
|
|
||||||
|
if (!data || !data.length || !data.filter(function(d) { return d.values.length }).length) {
|
||||||
|
container.append('text')
|
||||||
|
.attr('class', 'nvd3 nv-noData')
|
||||||
|
.attr('x', availableWidth / 2)
|
||||||
|
.attr('y', availableHeight / 2)
|
||||||
|
.attr('dy', '-.7em')
|
||||||
|
.style('text-anchor', 'middle')
|
||||||
|
.text(noData);
|
||||||
|
return chart;
|
||||||
|
} else {
|
||||||
|
container.select('.nv-noData').remove();
|
||||||
|
}
|
||||||
|
|
||||||
|
//------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
x .domain(d3.extent(data, getX ))
|
x .domain(d3.extent(data, getX ))
|
||||||
.range([0, availableWidth]);
|
.range([0, availableWidth]);
|
||||||
|
|
||||||
@ -156,5 +179,12 @@ nv.models.sparklinePlus = function() {
|
|||||||
return chart;
|
return chart;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
chart.noData = function(_) {
|
||||||
|
if (!arguments.length) return noData;
|
||||||
|
noData = _;
|
||||||
|
return chart;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
return chart;
|
return chart;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user