Stacked bar graph showing incorrect peaks compared to data

I’m trying to create a stacked bar graph in Grafana 9.3.6 on Ubuntu 20.04 LTS. The queries are as follows:

from(bucket: "InfluxDB")
  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
  |> filter(fn: (r) => r["_measurement"] == "ups")
  |> filter(fn: (r) => r["_field"] == "cur_power")
  |> timeShift(duration: -1m)
  |> aggregateWindow(every: 1m, fn: mean, createEmpty: false)
  |> map(fn: (r) => ({
      _field: "Garage UPS",
      _time: r._time,
      _value: r._value / 60.0
    })
  )
  |> sort(columns: ["_time"])
total = from(bucket: "${bucket}")
  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
  |> filter(fn: (r) => r["_measurement"] == "live_electricity")
  |> filter(fn: (r) => r["_field"] == "grid_import")
  |> timeShift(duration: -1m)
  |> aggregateWindow(every: 1m, fn: mean, createEmpty: false)
  |> map(fn: (r) => ({
      _field: "Grid Import",
      _time: r._time,
      _value: r._value / 60.0
    })
  )
  |> sort(columns: ["_time"])

ev = from(bucket: "${bucket}")
  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
  |> filter(fn: (r) => r["_measurement"] == "live_electricity")
  |> filter(fn: (r) => r["_field"] == "consumption_ev" or r["_field"] == "ev_charge_rate")
  |> timeShift(duration: -1m)
  |> aggregateWindow(every: 1m, fn: mean, createEmpty: false)
  |> map(fn: (r) => ({
      _field: "Grid Import",
      _time: r._time,
      _value: r._value / 60.0
    })
  )
  |> sort(columns: ["_time"])

total_minus_ev = join(tables:{total:total, ev:ev}, on:["_time"])
  |> map(fn:(r) => ({
      _value: (r._value_total - r._value_ev),
      _time: r._time,
      _field: r._field
    })
  )
  
ups = from(bucket: "InfluxDB")
  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
  |> filter(fn: (r) => r["_measurement"] == "ups")
  |> filter(fn: (r) => r["_field"] == "cur_power")
  |> timeShift(duration: -1m)
  |> aggregateWindow(every: 1m, fn: mean, createEmpty: false)
  |> map(fn: (r) => ({
      _field: "Garage UPS",
      _time: r._time,
      _value: r._value / 60.0
    })
  )
  |> sort(columns: ["_time"])

join(tables:{total_minus_ev:total_minus_ev, ups:ups}, on:["_time"])
  |> map(fn:(r) => ({
      _value: (r._value_total_minus_ev - r._value_ups),
      _time: r._time,
      _field: "Misc."
    })
  )
from(bucket: "${bucket}")
  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
  |> filter(fn: (r) => r["_measurement"] == "live_electricity")
  |> filter(fn: (r) => r["_field"] == "consumption_ev" or r["_field"] == "ev_charge_rate")
  |> timeShift(duration: -1m)
  |> aggregateWindow(every: 1m, fn: mean, createEmpty: false)
  |> map(fn: (r) => ({
      _field: "EV",
      _time: r._time,
      _value: r._value / 60.0
    })
  )
  |> sort(columns: ["_time"])

This is a lot of data since the granularity of each data point is 10s. If I show the previous 12 hours (or less), the graph looks correct:

However, if I show 24 hours (or more), the graph is drawn incorrectly. Notice there are lots of blue peaks, even though the value of the blue series is 0 for the entire time range:

Is this a bug or am I doing something wrong? Thanks.