How to colour code data points according to the associated label in a time series graph?

  • What Grafana version and what operating system are you using?

Grafana version → v11.2.0 (2a88694fd3)
OS → MacOS 13.6.5

  • What are you trying to achieve?

I have the following payload:

[
  {
    "time": 100,
    "value": 52,
    "vm-name": "vm-1"
  },
  {
    "time": 110,
    "value": 29,
    "vm-name": "vm-1"
  },
  {
    "time": 120,
    "value": 2,
    "vm-name": "vm-1"
  },
  {
    "time": 130,
    "value": 19,
    "vm-name": "vm-1"
  },
  {
    "time": 140,
    "value": 79,
    "vm-name": "vm-1"
  },
  {
    "time": 150,
    "value": 11,
    "vm-name": "vm-1"
  },
  {
    "time": 160,
    "value": 91,
    "vm-name": "vm-1"
  },
  {
    "time": 170,
    "value": 79,
    "vm-name": "vm-1"
  },
  {
    "time": 180,
    "value": 11,
    "vm-name": "vm-1"
  },
  {
    "time": 190,
    "value": 20,
    "vm-name": "vm-1"
  },
  {
    "time": 100,
    "value": 88,
    "vm-name": "vm-2"
  },
  {
    "time": 110,
    "value": 88,
    "vm-name": "vm-2"
  },
  {
    "time": 120,
    "value": 46,
    "vm-name": "vm-2"
  },
  {
    "time": 130,
    "value": 10,
    "vm-name": "vm-2"
  },
  {
    "time": 140,
    "value": 98,
    "vm-name": "vm-2"
  },
  {
    "time": 150,
    "value": 38,
    "vm-name": "vm-2"
  },
  {
    "time": 160,
    "value": 16,
    "vm-name": "vm-2"
  },
  {
    "time": 170,
    "value": 13,
    "vm-name": "vm-2"
  },
  {
    "time": 180,
    "value": 34,
    "vm-name": "vm-2"
  },
  {
    "time": 190,
    "value": 53,
    "vm-name": "vm-2"
  }
]

I want to plot a time series graph with the data points being coloured different for different vm-name. So data points with vm-name vm-1 should be of different colour than the data points of vm-2. I am using Infinity plugin to receive the json payload from an endpoint of a service.

  • How are you trying to achieve it?

I am formatting the received columns to correct data types so that Grafana can understand it according its definition of timeseries data.

Here’s an image of the table thus formed:

  • What happened?

Grafana is visualizing a single time series.
Here’s an image:

  • What did you expect to happen?

Since the data points have an identifier from the payload, that is vm-name, I expected Grafana to visualize data points with different colours.

Followed the suggestion from this answer.

Added the $sort($,function($l,$r) {$l.timestamp > $r.timestamp }) jsonata query but still no change in the visualizations.

Have you tried adding prepare timeseries transformation

1 Like

I think the issue might be that Grafana considers this one serie (each timestamp has two points which shouldn’t be possible with one serie). You should split / group by vm-name label. There’s a transformation Partition by values which should help.

Without:

With parition by values:

Probably you can do the same partitioning with JSONata, but I’m not too fluent with that.

1 Like

Thanks @dawiddebowski and @yesoreyeram! Both of your solutions work.