frappe/charts

Need to accept empty data

Open

#220 aperta il 8 apr 2019

Vedi su GitHub
 (9 commenti) (8 reazioni) (1 assegnatario)JavaScript (769 fork)batch import
help wanted

Metriche repository

Star
 (14.858 star)
Metriche merge PR
 (Nessuna PR mergiata in 30 g)

Descrizione

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

Guida contributor