[Infinity] Multiple XY-Plots with one JSON Query

Hi Grafana Experts,

I’ve seen below solutions but still can’t figure out how to display data using Infinity data source. Probably because my case is slightly different.

One of my applications generates 100 pairs of X-Y coordinates every hour and I can convert them to any JSON structure. So far I’ve tried the following:

  1. JSON array of charts - in this case Grafana shows single line for both charts
[
	{
		"time" : 1765962001,
		"chart": 
        [
			{"X": 0.1,  "Y": 16576},
			{"X": 10.1, "Y": 26576},
			{"X": 1.1, "Y": 36576}
		]
	},
	{	"time" : 1765965601,
		"chart": 
        [
			{"X": 30.11,  "Y": 36576},
			{"X": 20.11,  "Y": 26576},
			{"X": 30.11,  "Y": 16576}
		]
	} 
]

  1. Multiple charts under JSON root element - in this case I can see only the first chart
{
  "chart": 
        [
			{"time" : 1765962001},
			{"X": 0.1,  "Y": 16576},
			{"X": 10.1, "Y": 26576},
			{"X": 1.1, "Y": 36576}
		],
  "chart": 
        [
			{"time" : 1765965601},
			{"X": 30.11,  "Y": 36576},
			{"X": 20.11,  "Y": 26576},
			{"X": 30.11,  "Y": 16576}
		] 
}

But I need to see both of them on the same panel with different colors and (if possible) timestamp of each plot. Sounds like I need some magic in Rows/Root field.

Could you please help?

welcome to forum @ysus2000

try this out, using jsonata function to convert your time to real date time. are those ns? or ms?

Thanks @yosiasz , but UQL doesn’t work for whatever reason. Did I forget to install some components?

parse-json
  jsonata "$.chart.{'time' : %.time, 'x' : X, 'y' : Y}"

Time is with ‘ms‘ resolution

Sorry, I meant it works for Bar Chart and TimeSeries panels but not for XY-Chart which I need.

It should be just multiple curves not related to time, only X and Y coordinates.

Showing timestamp for each point is not mandatory but highly desirable.

Here is better picture of what I want to achieve. Works perfect with multiple queries but do you think it is possible to get the same visualization with a single query?

Or maybe some others solutions? All my JSONs are stored in MySQL database so maybe it is possible to add queried dynamically?

Hello @yosiasz, sorry for bothering, did you have a chance to have a look?

Much appreciate your expert advice,

Thank you in advance

1 Like

You need to parse as yosiasz says, but you can also use jsonata.

I think what yosiasz has is a time series panel potentially which is why the query may not have worked.

If you do have to display with an XY. You can parse with jsonata like so:

$[].($t := time; chart[].{"time": $t, "X": X, "Y": Y, "series": "Time " & $string($t)})

(I tested this with the sample json you provided)

This then generates a single table, with 6 rows (I added another series further in the test which is why my image has 3 series). The issue is that the XY does not produce differing series when in a single table, there needs to be grouping - so instead of single rows, you need to group by some series field. This is especially critical if you have data which is varied - e.g. sometimes you get 6 series, sometimes 1. It saves you having to define each series.

After your parse/query from infinity, you need to transform the data. Add a transformation “Partition by values” this will split the series based on the field you’ve added in the jsonata parsing. Choose field “series”, naming “as label”, leave the “Keep fields” well alone / default.

If you look at the panel in “Table view” you should see that there are only 3 rows, and you can select different series below the rows in a dropdown.

Configure the XY panel, make sure all frames is selected in Frames, X as X field, Y as Y field.

You should then have something like this:

1 Like

Hello @samredman ,

Fantastic! Exactly what I need and thanks for detail explanation.