Connect InfluxDB to vue app for visualization

I have a InfluxDB that i want to connect to my vue app. I already made the connection to the DB and I’m able to log the data in the terminal (not console) with the code below:

import { InfluxDB, Point } from ‘@influxdata/influxdb-client’

/** Environment variables **/
const url = ‘http://193.174.28.232:5102’;
const token = ‘qE83Rq0yQPGek6teUu745OkrOKW7jmInL5QrMq48-VIaXOagxPP3B8fvATAZsi7avaOlOSuMI0lRAKY9h9hnxg==’
const org = ‘TeamEE’

/**

  • Instantiate the InfluxDB client
  • with a configuration object.
  • Get a query client configured for your org.
    **/
    const queryApi = new InfluxDB({url, token}).getQueryApi(org)

/** To avoid SQL injection, use a string literal for the query. */
const fluxQuery = from(bucket:"fdre818") |> range(start: 2022-04-20T10:00:00Z, stop: 2022-04-20T10:02:00Z) |> filter(fn: (r) => r._measurement == "86B20CC8") |> filter(fn: (r) => r._field == "Speed") |> aggregateWindow(every: 5s, fn: mean) |> map(fn: (r) => ({ r with _value: r._value * 3.6 })) |> limit(n: 10)

const fluxObserver = {
next(row, tableMeta) {
const o = tableMeta.toObject(row)
console.log(
${o._time} ${o._field}=${o._value}
)
},
error(error) {
console.error(error)
console.log(‘\nFinished ERROR’)
},
complete() {
console.log(‘\nFinished SUCCESS’)
}
}

/** Execute a query and receive line table metadata and rows. */
queryApi.queryRows(fluxQuery, fluxObserver)

Now i want to get that data to my vue component and that’s not working. I tried to import the influxdb.js file with import * as Influxdb from '../database/influxdb.js' That gives me the error:

HEllo @Florian99,
I’m not sure. What have you tried?
Could this be helpful?

1 Like

Hi, you have to import @influxdata/influxdb-client-browser in place of @influxdata/influxdb-client. See influxdb-client-js installation for details.

2 Likes

Thanks a lot, it worked like a charm!