Data in table view not displayed in chart view by second RunQuery

  • What Grafana version and what operating system are you using?
    Grafana v11.2.2
  • What are you trying to achieve?
    I try to make a staked Chart with
  • How are you trying to achieve it?
    I have created a query that generates rows from a column and counts the number.
    The whole thing is grouped by CW and year
  • What happened?
    If I display the table when creating the visualization (switch top middle), I see values per week and generated column
    Then deactivate the table view so that the graph is displayed, it only works once. If I press RunQuery, the chart disappears.
    Regardless of whether it is stacked or not.
    if i switch back to table view, all the data is there.
SELECT
  CAST(YEAR(TimeStamp) AS CHAR) AS vYear,
  WEEK(TimeStamp, 1) AS CW_Week,
  COUNT(CASE WHEN Recipe= 'Type1' THEN 1 END) AS Type1,
  COUNT(CASE WHEN Recipe= 'Type2' THEN 1 END) AS Type2
FROM Datenbank_1
WHERE TimeStamp >= now() - Interval 4 week
GROUP BY vYear,CW_Week

result in table looks like this:

Thank you and best regards!

You may consider this solution. I hope it proves helpful to you.
Modify Your SQL Query

SELECT
  STR_TO_DATE(CONCAT(YEAR(TimeStamp), ' ', WEEK(TimeStamp, 1), ' 1'), '%X %V %w') AS Time,
  COUNT(CASE WHEN Recipe = 'Type1' THEN 1 END) AS Type1,
  COUNT(CASE WHEN Recipe = 'Type2' THEN 1 END) AS Type2
FROM Datenbank_1
WHERE TimeStamp >= NOW() - INTERVAL 4 WEEK
GROUP BY Time
ORDER BY Time

please follow the detailed steps i am using postgresql db, i don’t know which datasoure you are using , if you are using postgresql then follow the step.
Step 1 : Create table

CREATE TABLE Datenbank_1 (
    id SERIAL PRIMARY KEY,
    TimeStamp TIMESTAMP NOT NULL,
    Recipe TEXT NOT NULL
);

Step 2 : Insert some dummy data

INSERT INTO Datenbank_1 (TimeStamp, Recipe) VALUES

('2025-07-01 10:00:00', 'Type1'),

('2025-07-02 11:00:00', 'Type2'),

('2025-07-08 12:00:00', 'Type1'),

('2025-07-10 13:00:00', 'Type1'),

('2025-07-15 14:00:00', 'Type2'),

('2025-07-16 15:00:00', 'Type2'),

('2025-07-22 16:00:00', 'Type1'),

('2025-07-24 17:00:00', 'Type2'),

('2025-07-29 18:00:00', 'Type1');

Step 3: fetch data in grafana panel using this query

SELECT
  EXTRACT(YEAR FROM "timestamp")::TEXT AS vYear,
  TO_CHAR("timestamp", 'IW') AS CW_Week, -- ISO Week
  COUNT(CASE WHEN Recipe = 'Type1' THEN 1 END) AS Type1,
  COUNT(CASE WHEN Recipe = 'Type2' THEN 1 END) AS Type2
FROM Datenbank_1
WHERE "timestamp" >= NOW() - INTERVAL '4 weeks'
GROUP BY vYear, CW_Week
ORDER BY vYear, CW_Week;