Showing a dashed line for missing data
See original GitHub issueI’m doing a line chart where some data might be missing.
To avoid showing the missing data points I create a derivative data table:
{
"name": "definedtable",
"source": "table",
"transform": [
{
"type": "filter",
"expr": "!isNaN(datum.value)"
}
]
}
To break the line where data is missing, I can use
encode.enter.defined = {"signal": "!isNaN(datum.value)"}
Now what I would want is to have a dashed line in between segments of the line, as in d3-line-chunked. Is this feasible with Vega (Vega 3)?
The d3-line-chunk plugin is not ported to Vega (see issue #15). But maybe there is a simple way to “connect the dots”.
Issue Analytics
- State:
- Created 7 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
How to deal with missing data in line charts
Calculate missing values and fill in the gaps. How to show your interpolated lines. Use multiple line symbols; Use dashed lines ...
Read more >Showing Missing Data in Line Charts - Bocoup
Animation behaves poorly when missing data is in different x values and when there are different number of points in the destination path....
Read more >Displaying Missing Data Values in a Graph
In line graphs, a dotted line connects the missing value with the succeeding value. In 3D bar graphs, solid lines outline the flat...
Read more >Show missing values with dotted lines - Stack Overflow
1 Answer 1 · find the index i of the next occurrence of NA , make left = data[i - 1] · find...
Read more >How to Add Dotted Lines to Line Graphs in Microsoft Excel
Image showing data statistics that are missing a number of years' data. The Challenge. The challenge is twofold: First, how do you take...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Great question! If you look at the implementation details of d3-line-chunked, you’ll find that it draws two paths: typically one dashed and one solid. The only difference between the two is that the solid line also includes a clipping path that masks the solid lines over “undefined” regions. This strategy is nice because it works regardless of the line interpolation method (linear, monotone, etc) used.
In Vega, it is straightforward to similarly draw two lines: one dashed and and one solid. Using the
defined
property for the solid line, you can also remove segments corresponding to missing data. For linear, and step-* interpolation this works nicely. However, for curved interpolation (cardinal, monotone, etc) you’ll unfortunately get results where the two curves do not align. I’ve included a full spec below that demonstrates this approach.So, if you are satisfied with non-curved interpolation you should be good to go. Otherwise, we will need to consider alternative approaches (perhaps including new transforms or mark implementations) to service the general case. Feel free to open a new, more targeted, feature request issue if so!
@jheer Wonderful example! I was wondering if this is able to be translated over to Vega-lite? I’ve been spinning my wheels trying to figure this out.