plotly 甘特图数值使用SQL查询结果,不能全部在图表中显示

SQL查询数据库,使用for循环查询:
for i in self.Product:
Product=i[0]
StartTime=i[1]
FinishTime=i[2]
查询结果:
SSSS 2022-01-07 07:46:16 2022-01-07 08:40:36
AAAA 2022-01-07 06:09:52 2022-01-07 07:38:47
CCCC 2022-01-07 04:46:15 2022-01-07 06:03:54
DDDD 2022-01-06 21:54:24 2022-01-07 04:20:30

plotly 甘特图语句:
df = [dict(Task=Product,Start=StartTime,Finish=FinishTime),]
pyplt = py.offline.plot
fig = ff.create_gantt(df)
pyplt(fig, filename='1.html')

plotly 甘特图显示数据只有最后一条的数据,图表中该怎么显示所有的数据

img

这样试试


sql = "SELECT Product,StartTime,FinishTime FROM {}.dbo.PlanProduction " \
      "WHERE DateDiff(hh,FinishTime,getdate())<=%s " \
      "AND Line='Line1A' AND FinishTime IS NOT NULL " \
      "ORDER BY StartTime DESC".format(self.db)
self.cur.execute(sql, (self.GuiCon_FinishDay))
self.Product = self.cur.fetchall()
df = []
for i in self.Product:
    Product = i[0]
    StartTime = i[1]
    FinishTime = i[2]
    print(Product, StartTime, FinishTime)
    df.append(dict(Task=Product, Start=StartTime, Finish=FinishTime))


pyplt = py.offline.plot
fig = ff.create_gantt(df)
pyplt(fig, filename='1.html')

具体代码贴一下, 目前看起来 你的 df 只有1条数据?
print(df) 看看