question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Line chart with gap in data

See original GitHub issue

I’m submitting a … (check one with “x”)

[ ] bug report => search github for a similar issue or PR before submitting
[x] feature request
[ ] support request => Please do not submit support request here

Current behavior

I can’t get the line chart to draw a graph with a gap in it’s data. And it doesn’t seem to be documented here https://swimlane.gitbooks.io/ngx-charts/content/charts/line-chart.html I tried to set my data to both null or undefined. Null results in it being 0 and undefined keeps it from drawing. For e.g.:

  {
    "name": "Germany",
    "series": [
      {
        "name": "2010",
        "value": 7300000
      },
      {
        "name": "2011",
        "value": 8940000
      },
      {
        "name": "2012",
        "value": null
      },
      {
        "name": "2013",
        "value": 8940000
      }
    ]
  },

Expected behavior

Not sure about undefined or null as the api here, but I would expect the graph to just stop drawing at the point before and start drawing again on the point after. So that we just get a gap where not data is.

Reproduction of the problem

Just use the plnkr from https://swimlane.gitbooks.io/ngx-charts/content/charts/line-chart.html and replace the data with the above.

What is the motivation / use case for changing the behavior?

The intention is to communicate, that there are no values for that timespan available.

Please tell us about your environment:

Shouldn’t matter, I will get back to you if it does.

  • ngx-charts version: x.x.x

Shouldn’t matter, I will get back to you if it does.

  • Angular version: 2.x.x

Shouldn’t matter, I will get back to you if it does.

  • Browser: [all | Chrome XX | Firefox XX | IE XX | Safari XX | Mobile Chrome XX | Android X.X Web Browser | iOS XX Safari | iOS XX UIWebView | iOS XX WKWebView ]

Shouldn’t matter, I will get back to you if it does.

  • Language: [all | TypeScript X.X | ES6/7 | ES5] Shouldn’t matter, I will get back to you if it does.

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:36
  • Comments:11 (3 by maintainers)

github_iconTop GitHub Comments

5reactions
Mouldecommented, Jul 30, 2018

I have the same issue. The areachart is visualized correctly ie. no border or point is visible, but the point still exists, and when i mouse over the point it will throw an error when trying to create the tooltip due to the value being null. Reading null as a 0 is IMO not correct, as 0 is in most cases, a valid value, whereas null or NaN indicates that the point has no value.

It’s also not a solution to just skip the points with null values, as that skews the chart, at least in the case of x value being a timestamp.

Would adding a configuration flag, maybe makeNullPointInvisible with a default value of False, and use this to decide if it should visualize the point, be a solution? (ofc the hardest part is what to call the parameter…) That way the current handling will stay the same, but setting the flag to true, will make it place a invisible point, and not show any tooltips. But the point will still take up room in the chart.

4reactions
End-Scommented, Jun 24, 2019

I have found that if you provide a series with the same name, ngx-charts groups this as a single entry in the legend. This means that you can split the series up every time your data contains a null value and your plotted line will display with gaps. For example:

results: any[] = [
    {
      'name': 'Saint Pierre and Miquelon',
      'series': [
        {
          'value': 6182,
          'name': '2016-09-22T13:44:43.081Z'
        },
        {
          'value': 4938,
          'name': '2016-09-23T00:29:51.341Z'
        },
        {
          'value': 5137,
          'name': '2016-09-17T02:59:36.606Z'
        },
        {
          'value': 2841,
          'name': '2016-09-21T11:01:36.508Z'
        },
        {
          'value': 6347,
          'name': '2016-09-19T21:28:14.801Z'
        },
      ],
    },
    // A null value would have occurred here
    {
      'name': 'Saint Pierre and Miquelon',
      'series': [
        {
          'value': 7347,
          'name': '2016-09-19T23:28:14.801Z'
        },
        {
          'value': 5347,
          'name': '2016-10-19T11:28:14.801Z'
        }
      ]
    }
  ];

I appreciate this is not a complete solution but if you are plotting against time it should be a clean workaround until null values get support. ngx_charts_gap

Read more comments on GitHub >

github_iconTop Results From Across the Web

A Line chart may plot gaps in lines when the data range ...
Describes an issue where the lines of a Line chart may plot with gaps when the data range of the chart contains blank...
Read more >
How to Handle Data Gaps in Excel Charts (Examples)
Handle Data Gaps in Excel Charts · Select the chart · Go to Design –> Select Data · In Select Data Source dialogue...
Read more >
How-to Show Gaps in a Line Chart When Using the Excel ...
First, you can click so that only the marker is selected. Then you right click, and select “Format Data Point”. Under “marker options”...
Read more >
How to create a gap in a line chart for empty data ... - Mr. Excel
The chart data series are arrays of values calculated in VBA and assigned to the chart. I have found the gaps will generate...
Read more >
How to deal with missing data in line charts
Sometimes, missing values in a line chart will create a gap in the line. In this tutorial, you'll learn how to draw an...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found