NguyNhu commited on
Commit
d9c3ec9
·
verified ·
1 Parent(s): 9127193

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -6
app.py CHANGED
@@ -187,14 +187,38 @@ with tab2:
187
  # Biểu diễn trực quan
188
  if not df_income.empty:
189
  st.subheader("📈 Biểu đồ doanh thu và lợi nhuận")
190
- revenue_cols = [col for col in df_income.columns if 'doanh thu' in col.lower()]
191
- profit_cols = [col for col in df_income.columns if 'lợi nhuận' in col.lower()]
 
 
 
 
 
 
 
 
 
 
 
 
192
 
193
  if revenue_cols and profit_cols:
194
- fig_finance = go.Figure()
195
- fig_finance.add_trace(go.Bar(x=df_income.index, y=df_income[revenue_cols[0]], name='Doanh thu'))
196
- fig_finance.add_trace(go.Bar(x=df_income.index, y=df_income[profit_cols[0]], name='Lợi nhuận'))
197
- st.plotly_chart(fig_finance, use_container_width=True)
 
 
 
 
 
 
 
 
 
 
 
 
198
 
199
  except Exception as e:
200
  st.error(f"❌ Lỗi dữ liệu tài chính: {e}")
 
187
  # Biểu diễn trực quan
188
  if not df_income.empty:
189
  st.subheader("📈 Biểu đồ doanh thu và lợi nhuận")
190
+
191
+ # Hiển thị tên các cột để debug
192
+ revenue_keywords = ['doanh thu', 'thu nhập', 'revenue', 'income']
193
+ profit_keywords = ['lợi nhuận', 'lãi', 'profit', 'earnings', 'lnst']
194
+
195
+ revenue_cols = []
196
+ for keyword in revenue_keywords:
197
+ revenue_cols.extend([col for col in df_income.columns if keyword in col.lower()])
198
+ revenue_cols = list(set(revenue_cols)) # Loại bỏ trùng lặp
199
+
200
+ profit_cols = []
201
+ for keyword in profit_keywords:
202
+ profit_cols.extend([col for col in df_income.columns if keyword in col.lower()])
203
+ profit_cols = list(set(profit_cols)) # Loại bỏ trùng lặp
204
 
205
  if revenue_cols and profit_cols:
206
+ # Tạo button để force refresh biểu đồ
207
+ if st.button("Hiển thị biểu đồ", key="show_finance_chart"):
208
+ fig_finance = go.Figure()
209
+ fig_finance.add_trace(go.Bar(x=df_income.index, y=df_income[revenue_cols[0]], name='Doanh thu'))
210
+ fig_finance.add_trace(go.Bar(x=df_income.index, y=df_income[profit_cols[0]], name='Lợi nhuận'))
211
+ fig_finance.update_layout(
212
+ title='Biểu đồ doanh thu và lợi nhuận',
213
+ xaxis_title='Kỳ báo cáo',
214
+ yaxis_title='Giá trị (VND)',
215
+ barmode='group'
216
+ )
217
+ st.plotly_chart(fig_finance, use_container_width=True)
218
+ else:
219
+ st.warning("Không tìm thấy cột doanh thu hoặc lợi nhuận trong dữ liệu. Vui lòng kiểm tra lại nguồn dữ liệu.")
220
+ else:
221
+ st.warning("Không có dữ liệu báo cáo tài chính.")
222
 
223
  except Exception as e:
224
  st.error(f"❌ Lỗi dữ liệu tài chính: {e}")