Wrong series being displayed in legend

  • Grafana version: v10.2.3 via webapp

  • Goal: a simple bar chart showing two histograms overlaid

  • How: histogram panel is too limiting so i’m doing the bucketing myself in SQL and displaying using a bar chart panel. The SQL outputs three numerical columns, one of the rounded bucket variable, and two of the two counts-per-bucket. I’m applying only a names transformation, everything else is in the SQL, and the problem is still present even if i remove that transformation.

  • Problem: the legend displays the name and color of just one of the two counts-per-bucket series, and also the name and color of the bucket variable itself, which of course is not shown directly and does not need a color—it’s just the X-axis

  • What I expected: the legend would display the name and color of the two counts-per-bucket series that form the two sets of bars in the chart

Raw table view output:

Bar chart panel as it’s displaying now:

How can I fix the legend? Thanks!

I think you should change the Scale ratio field to String (there’s an info that bar chart requires time or string field which you have none) using Convert field type transformation. You can explicit set the X Axis to your field of number type but it would result in what you’re experiencing (I’m not sure if that’s a bug or not). I also might be babling rn but I think I didn’t see it in Grafana 11.2 (I’m not sure though).

ah, that worked, thank you! I’m not clear on why it would work, but who knows…

Where should I have looked for the info that a bar chart requires time or string? apart from the legend thing it seemed to be working fine with a numerical column so i definitely never would have guessed that was an issue

Tbh I’m not sure also. I was reproducing your example and upon changing from Table to Bar Chart I got that info in the plot area. Also the option for setting the X axis field mentions:
image

but I agree it doesn’t specifically say that it must be string or time.