frappe/charts

Need to accept empty data

Ouverte

#220 ouverte le 8 avr. 2019

 (9 commentaires) (8 réactions) (1 personne assignée)JavaScript (769 forks)batch import
help wanted

Métriques du dépôt

Stars
 (14 858 étoiles)
Métriques de merge PR
 (Aucune PR mergée en 30 j)

Description

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

Guide contributeur