Chart can't display several columns in table

I have a _value field and using map() have created an additional field (_value_2)
The resulting table looks like …


But only _value appears on the chart.

The chart obviously defaults to displaying _value. But when you click on the option you can select to display _value_2. But you can’t select both. Surely users are going to want to do this?

The code I’m using is…

from(bucket: “Power_Meter”)
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: ® => r._field =~ /KWH/)
|> map(fn: ® => ({ r with _value_2: r._value /1000.0 }))
|> increase(columns: ["_value_2"])
|> difference(nonNegative: false, columns: ["_value"])
|> keep(columns: ["_value_2", “_value”, “_time”])

Hello @asmith,
Welcome! Yes this is a major shift/difference between InfluxQL and Flux.
This issue is related:

However, here is a workaround:

data = from(bucket: "Power_Meter")
 |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
 |> filter(fn: (r) => r._field =~ /KWH/)
value_1 = data |> difference(nonNegative: false)
value_2 = data
 |> map(fn: (r) => ({ r with
   _value: r._value / 1000.0,
   _field: "KWH/1k"
 |> increase()
union(tables: [value_1, value_2])

Yes I can see what you are doing and I wondered how to do it.

Thanks so much!
That trick of using the ‘data’ variable twice is very very useful.

Can different cells share the same ‘data’ variable?

That way I can read ‘data’ once, but can have different cells which display different aspects of it.

Also I would like to up-vote the need for an unpivot() function.

Unpivot() is EXACTLY what I searched for and would be a much more elegant way to manipulate the table.

Better still, a chart should be able to display multiple columns!

That would deliver such powerful functionality no?

Hi @Anaisdg, I’m still very much interested in my follow-on question …
“Can different cells share the same ‘data’ variable”?

The use case :
Within my dash I have 10 cells. Each cell queries the same time range with the same tags and filters for different variables.
I believe it would be more efficient to query all the data once. And then each cell only has to filter data already retrieved and in the ‘data’ variable.

Would this work? Or is the data variable on the server not the client?

Does that makes sense?



1 Like