Cannot read properties of undefined

Hello,
I am using plugins like:

  1. Apache ECharts plugin for Grafana | Grafana Labs
  2. Echarts plugin for Grafana | Grafana Labs
    for data visualization.

When there is no data to be returned from the flux query the following message I got:

Can you please tell me, how should I modify the code related to the chart, to display more user friendly content?

This function does not run because there is no data:

const series = data.series.map((s, index) => {
const sData = s.fields.find((f) => f.type === ‘number’).values.buffer;
const sTime = s.fields.find((f) => f.type === ‘time’).values.buffer;

return {
name: s.refId,
type: ‘line’,
showSymbol: false,
lineStyle: {
width: 1,
color: colors[mod(index, colors.length)],
},
data: sData.map((d, i) => [sTime[i], d.toFixed(2)]),
};
});

When I change the series to this one:

const series = ;

I got the right output like this:

How can I manage the value of the series to display empty content when there is no data to run the map function?

Thank you!

1 Like

You will need to check to see if your data has any value if so return what you have if not return an empty array

Hello,
Yes, that was obvious for me, but I don’t know how to do that in the code. For example, when I change the ‘series’ variable to this ‘’ - got the following exception: Unexpected token ‘]’

Can you provide an example code?

Its really not a grafana issue but a js issue

const series;

If (data) {
 //the current code you have
} else {
  series = []
}

Hey,
It is a little bit more complicated, but you pointed me to the right direction.


Only the last 2 series are undefined. Thank you!

1 Like