Display several columns in a board

Hello,

I want to display several columns, but I only can display only one column at a time.
This is my code.


import "strings"

data = from(bucket: "Telegraf")
  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
  |> filter(fn: (r) => r["_measurement"] == "opcua")
  |> filter(fn: (r) =>  r["_field"] == "WIVS" )

  |> map(fn: (r) => 
    {
      IVS = strings.split(v: r["_value"], t: ",")
      return
        {
          _time: r._time,
          ValueName: WIVS[0],
          Value1: int(v: WIVS[1]),
          Value2: int(v: WIVS[2]),
          Value3: int(v: WIVS[3]),
          Value4: int(v: WIVS[4]),
          Value5: int(v: WIVS[5]),
          Value6: int(v: WIVS[6])
        }

    }

  )


@jen75321 What are you using to visualize the data? InfluxDB dashboards? Grafana? What type of visualization are you trying to use?

For now, I use InfluxDB dashboards to visualize time series data from opcua.
but I want to use grafana to visualize data.
Is it correct to modify this Flux code to visualize the data in grafana?
Or do I have to edit the telegraph config file?

I believe Grafana uses the same standard to visualize data from InfluxDB. Currently, each table in your results is represented by a line in the graph, so you somehow need to can’t your processed values into separate tables. If Flux supported unpivoting data, this would be pretty easy, but currently, it doesn’t (here’s a proposal for unpivot).

You may be able update your Telegraf configuration to split your WIVS value and write them as separate fields, but I don’t know of a way off-hand. That would make querying a lot simpler.

But to work with what you have, you could do something like this:

import "strings"

data = from(bucket: "Telegraf")
    |> range(start: -1h, stop: now())
    |> filter(fn: (r) => r["_measurement"] == "opcua")
    |> filter(fn: (r) =>  r["_field"] == "WIVS" )
    |> map(fn: (r) => {
            WIVS = strings.split(v: r["_value"], t: ",")
            
            return {
                _time: r._time,
                ValueName: WIVS[0],
                Value1: int(v: WIVS[1]),
                Value2: int(v: WIVS[2]),
                Value3: int(v: WIVS[3]),
                Value4: int(v: WIVS[4]),
                Value5: int(v: WIVS[5]),
                Value6: int(v: WIVS[6])
            }
        }
    )

Value1 = data |> map(fn: (r) => ({_time: r._time, ValueName: r.ValueName, _field: "Value1", _value: r.Value1}))
Value2 = data |> map(fn: (r) => ({_time: r._time, ValueName: r.ValueName, _field: "Value2", _value: r.Value2}))
Value3 = data |> map(fn: (r) => ({_time: r._time, ValueName: r.ValueName, _field: "Value3", _value: r.Value3}))
Value4 = data |> map(fn: (r) => ({_time: r._time, ValueName: r.ValueName, _field: "Value4", _value: r.Value4}))
Value5 = data |> map(fn: (r) => ({_time: r._time, ValueName: r.ValueName, _field: "Value5", _value: r.Value5}))
Value6 = data |> map(fn: (r) => ({_time: r._time, ValueName: r.ValueName, _field: "Value6", _value: r.Value6}))

union(tables: [Value1, Value2, Value3, Value4, Value5, Value6])
    |> group(columns: ["ValueName", "_field"])
1 Like