Plot line chart with multiple series and colors

  • What Grafana version and what operating system are you using?
    Grafana v10.3.1 (00a22ff8b2)

  • What are you trying to achieve?
    Plot line chart with multiple series and each with its own color.

  • How are you trying to achieve it?
    Select different visualizations.

  • What happened?
    Trend: no graph is plotted.
    XY Chart: series are plotted but with same color.

Hi community,

I extracted data from InfluxDB using a single query, and after applying some transformations, I obtained data as follows:

quantity,animal,probability
1000,“dog”,0.203
1000,“cat”,0.225
1000,“turtle”,0.264
1000,“eagle”,0.204
1000,“rat”,0.197
1000,“lion”,0.251
2000,“dog”,0.204
2000,“cat”,0.250
2000,“turtle”,0.269

From this I want to plot a graph where x-axis is quantity, y-axis is probability, and each animal has its own line.

Which visualisation to choose?

What version of grafana are you on?

You can use almost all visualization except time series

Alias
quantity column as value,
Animal colum as metric

1 Like

Thank you for the reply.

I’m using Grafana v10.3.1 (00a22ff8b2).

I believe Trend visualization would be the more appropriate, but it returns: “Values must be in ascending order”, even applying Transformation: sort by quantity…

Do a sort order on the source query itself instead of transformation

1 Like

Adding to the query: ORDER BY "quantity" ASC, it returns: “InfluxDB Error: error parsing query: only ORDER BY time supported at this time”.

Adding Sort by quantity as transformation, it keeps returning: “Values must be in ascending order”.

Probably means your quantity is not a tag. Influxql can either sort by time or a tag

I would post this in an influxdb community forum unless someone else chimes in such an guru @grant2

1 Like

Using Trends I managed to plot this. How could I assign a color to each animal or add lines between animal’s points?

Thank you for your help.

Look at the Color setting

1 Like

Color settings has two options: text or series. What it does it colors the values of y-axis with the same color as the points…

And color scheme option only changes the color of all points.

Should applying “Partition by values” transformation solve my problem?

What worked?
Maybe look into value mapping for color

1 Like

The title is now updated. Do you have a suggestion to solve my problem?

Look at value mapping

It has no impact.

No idea what you have tried so it is hard to see how we can help you

Post screen shots

I used infinity with CSV as my input and Grafana 10.2, but hopefully it’ll work with for you…

Add ‘partition by values’ as your final transition:
image

This should split the data into a different data series for each value of animal, although it seems to loose the name of the animal (it turns up as a series label, but not as part of the data). As Frame Name seems to give more useful names.

Then select an XY Chart, with manual series mapping:
image
No idea why it says Animal is not found, even though it works to separate the colors.

The resulting graph:

Can’t work out how to change the series names, they don’t show up as candidates for overrides, and there’s no-where in the X-Y chart to specify the value to be used. I’m sort of thinking auto on the X-Y chart should have picked up on the fact there were multiple series and given each one a separate color with the correct series name (you can see them if you switch to table view).

You also need to specify the axis labels - same label for both Axis? - otherwise it labels them for the first series - Probability “dog” for Y and Quantity “dog” for X - even though it’s showing data for all of them.

Hovering over a point only shows you data for that point, even if you pick All.

Mik

1 Like

Well, that’s interesting.

Fiddled with it a bit, and now it’s giving me the multi-coloured chart with:
image

Guess using the base field names is auto-generating the different series. Pity it’s not getting the series name right.

Went through a couple of combinations where it was all green, then deleted the series and re-added it and it came right.

Gives an error if you try and add a series for each animal manually…

Mik

1 Like