score:6
Accepted answer
In the end I solved this myself, based on the solution here. The trick is to remove the empty values as late as possible, so the positions of all values (points) on the canvas are preserved.
graph.selectAll("path.line")
.data(data)
.enter().append("path")
.attr("class", "line")
.style("stroke", function(d, i) { return d3.rgb(z(i)); })
.style("stroke-width", 2)
.attr("d", d3.svg.line()
.y(function(d) { return y(d.y); })
.defined(function(d) { return d.y; }) // Omit empty values.
.x(function(d,i) { return x(i); }));
This will work for empty values at the start and end of a line.
score:2
This should do it:
.data(data, function(inptArray) {
return inptArray.filter(function(obj) {
return obj.y != null;
})
});
it would be better though to write it like this:
var validatedInput = function(inptArray) {
return inptArray.filter(function(obj) {
return obj.y != null;
});
.data(data, validatedInput);
Or you can just format your data object before given it to D3:
var data = data.map(function(obj){
return obj.filter(function(obj) {
return obj.y != null;
})
})
Source: stackoverflow.com
Related Query
- D3: skip null values in line graph with several lines
- D3 line graph with arbitrarily many lines (and a specific data format)
- Animate lines in a line graph with D3.js
- Align lines and dots with x-axis values in line chart
- D3 : non continuous line chart with null values inside an object
- D3 Transition. Working with multiple lines on line graph and would like to transition smoothly between lines when button is pressed
- Why d3 line generator fails with the usage of scale around null values
- i can't change the colors on the lines in a multi line graph with d3
- Real time line graph with nvd3.js
- nvd3 line chart with string values on x-axis
- nvd3.js-Line Chart with View Finder: rotate axis labels and show line values when mouse over
- How to show a tooltip with value when mouseover a svg line graph using d3.js?
- Force a d3 line chart to ignore null values
- 0 fill null values with d3 series data
- Multiples with x/y axis and mouseover example - line path shows wrong values
- d3.js:vertical moving line's intersection point with line graph
- Simple line graph with dates in D3
- javascript d3 line graph with ordinal x axis
- d3 line graph with smooth update animation
- Creating a D3 Line Graph with Points using 2 Level Nested JSON
- Add dots on a multi line D3.js Graph with nested data
- wrong date printing on x axis of line graph in d3 with extra tick
- D3.js Combining Candlestick Chart with Line Graph
- D3 Line Graph with JSON Data in ISO 8601 Format
- how can i get a label on my lines in a line graph using d3.js
- D3 line graph with date slider
- Adding circles to multi line graph with dropdown on d3.js
- Dashed line transforms the null values into zeros on the chart
- Multi line graph with ordinal x-axis
- Incomplete line chart with missing points and missing lines
More Query from same tag
- Javascript d3 heatmap calendar, how to append day of the month?
- Detecting line closest to the mouse pointer with interrupted lines
- Backward direction of path with arrow is not showing properly in D3.js V5
- D3/Raphael js draws 1000+ animated circle with slow fps
- Triggering browser events for testing
- d3 simple linear chart with jquery ui range slider
- Change the Y axis range based on the selected data
- Re-sizing circle SVG in D3
- D3 line generator only generating NaN values
- D3.js use unordered list to rotate pie chart
- How to call a D3 script as a function
- Chord DHT Graph with D3JS
- How to keep the circle, stroke and font size when zooming in d3.js V4 layout?
- D3 - Disable/Reenable mouseover on certain layers
- 'nvd3' is not a known element: 1. If 'nvd3' is an Angular component, then verify that it is part of this module
- How to add custom tick labels in d3.js?
- d3 returns error `e is not a function` while passing nest data to d3.stack
- Dynamically access an imported module's methods in TypeScript
- d3 cannot read property "on" of undefined
- Why is nothing being displayed on my webpage?
- How to use crossfilter.js for adding data to a reusable scatterplot?
- Directed acyclic graph using d3.js without DOT
- How to repaint my nodes? D3.js
- d3.js limit panning in force layout
- d3js json pie chart
- Closure issue using d3 tip
- How to use an exit selection on text with tspan
- D3 does not support property gantt()
- D3: Surround mouse point with "Crosshair"
- Add html content with line break inside d3 circle