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.

Need to accept empty data

See original GitHub issue

Errors occurred when I tried to use empty data object to initialize a chart instance.

  const chart = new frappe.Chart('.panel .chart', {
    data: {},
    type: 'line',
    height: 320,
    colors: ['#0294FF'],
  })

This caused an Uncaught TypeError:

frappe-charts.min.iife.js:1 Uncaught TypeError: Cannot read property 'map' of undefined
    at Ct (frappe-charts.min.iife.js:1)
    at i.value (frappe-charts.min.iife.js:1)
    at i.e (frappe-charts.min.iife.js:1)
    at new i (frappe-charts.min.iife.js:1)
    at Tt (frappe-charts.min.iife.js:1)
    at new t (frappe-charts.min.iife.js:1)
    at HTMLDocument.<anonymous> (stats-overview.js:20)
    at l (jquery.js:2)
    at Object.fireWith [as resolveWith] (jquery.js:2)
    at Function.ready (jquery.js:2)

Seems frappe tried to call map function of datasets or labels. But I only need to create an empty chart at that time, and update data on future user events.

I tried to use this as init data

{
  labels: [],
  datasets: [],
}

and got a lot of SVG errors which blocked the future data updatings.

Error: <g> attribute transform: Trailing garbage, "translate(0, undefined)".

It’s weird that

{
  labels: [''],
  datasets: [{
    values: [0],
  }],
}

also cause some errors such as

frappe-charts.min.iife.js:1 Error: <path> attribute d: Unexpected end of attribute. Expected number, "M".

and

Error: <circle> attribute cy: Expected length, "undefined".

but without blocking future updatings.

Seems it only works fine with two or more data points.

User-Agent:

Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.86 Safari/537.36

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:8
  • Comments:9

github_iconTop GitHub Comments

2reactions
blueabysmcommented, Sep 10, 2019

The when creating charts it is necessary to provide the labels at least. With the labels in place the Charts will automatically fill in the value 0 as default for the missing values.

So a config like the following will work without any errors.

data: {
	labels: ['Monday, 'Tuesday', 'Wednesday', 'Thursday', 'Friday'],
	datasets: [],
}

I hope this answers your question.

Thanks a lot for your help. But actually for me, it’s not a perfect solution 😂. I don’t know any of the labels until the server responds them via an xhr (for example last 30 days as labels). Better if frappe could draw an empty chart without any data or labels provided at initialization. Now I manually set two labels as a walkaround, it seems a little bit strange showing two unrelated zero data points on every refresh before real data loaded.

1reaction
scmmishracommented, Sep 1, 2019

The when creating charts it is necessary to provide the labels at least. With the labels in place the Charts will automatically fill in the value 0 as default for the missing values.

So a config like the following will work without any errors.

data: {
	labels: ['Monday, 'Tuesday', 'Wednesday', 'Thursday', 'Friday'],
	datasets: [],
}

I hope this answers your question.

Read more comments on GitHub >

github_iconTop Results From Across the Web

c# - Data annotations for handling empty strings - Stack Overflow
This will let empty strings go through, but on a query for a list of entities already in the table that include null...
Read more >
When to use NULL and when to use an empty string?
NULL means absence of value (i.e. there is no value), while empty string means there is a string value of zero length. For...
Read more >
how to validate empty data in transform map? - ServiceNow
Hi All,. I need to validate below excel data while doing transform load (before loading to table). Validation should be like if the...
Read more >
Blank, Coalesce, IsBlank, and IsEmpty functions in Power Apps
Some controls and data sources use an empty string to indicate a "no value" condition. To simplify app creation, the IsBlank and Coalesce ......
Read more >
Handling JSON null and empty arrays and objects - IBM
JSON data has the concept of null and empty arrays and objects. This section explains how each of these concepts is mapped to...
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