Linechart for several products with one query

  • What Grafana version and what operating system are you using?
    I am using the newest grafana community edition

  • What are you trying to achieve?
    I want to display the amount of products i had in storage. The data about the products and the storage amounts are in 2 separate SQL tables.

ProductData table:
ProductID|Name|…Other columns that are not important
1| Product A|
2| Product B|
3| Product C|

Storage table:
ProductID| amount| Date| other unimportant coloums
1| 10| 2020
2| 5| 2020
3| 7| 2020
1| 3| 2021
2| 10| 2021
3| 1| 2021
1 7| 2022
2| 8| 2022
3| 9| 2022

  • How are you trying to achieve it?
    i can select and join data using SQL queries just fine, however i can not make grafana draw 3 lines for 3 example products using the product name in the legend and tooltip.
    I assume this is a standard task and nothing special, yet i can’t find any solution.

  • What happened?

  • What did you expect to happen?
    i want 3 lines in 1 graph, one for each product

Hi @henrigehrt33

Could you share a screenshot of the graph that you are getting? Or are you getting nothing at all?

What happens when you run the same query in SSMS? (or whatever tool you use to view / test queries and explore data…I presume you are using MS SQL)

Just a few things that I can think of…

  • Have you read through this tutorial?
  • Is the date column in your storage table identified to Grafana as the time column? (I presume you are trying to make a time series chart. In general, the time series visualization will look for columns that are of date/time types, or columns that look like UNIX times).
  • Have you tried any of the transformations, for example:
    image