abraham9486937737 commited on
Commit
819cf2c
·
1 Parent(s): 5e5314a

Improve revenue chart: use DataFrame-based histogram

Browse files
Files changed (1) hide show
  1. streamlit_app/app.py +24 -16
streamlit_app/app.py CHANGED
@@ -516,34 +516,42 @@ if page == "📊 Overview":
516
  # Filter to positive values only
517
  revenue_values = revenue_values[revenue_values > 0].dropna()
518
 
519
- if not revenue_values.empty and len(revenue_values) > 5:
 
 
 
 
520
  try:
521
- # Create histogram
 
 
 
522
  fig = px.histogram(
523
- revenue_values,
524
- nbins=min(30, len(revenue_values)//5),
 
525
  title=f"Revenue Distribution - {best_col}",
526
- color_discrete_sequence=['#636EFA'],
527
- labels={'value': best_col, 'count': 'Count'}
528
  )
529
  fig.update_layout(
530
  height=400,
531
  xaxis_title=best_col,
532
  yaxis_title="Count",
533
- hovermode='x unified'
 
534
  )
535
  fig.update_traces(marker=dict(line=dict(width=0)))
536
  st.plotly_chart(fig, use_container_width=True)
537
  except Exception as e:
538
- st.warning(f"Could not create histogram: {e}")
539
- # Fallback: show summary stats
540
- st.metric("Average Revenue", f"₹{revenue_values.mean():,.0f}")
541
- st.metric("Median Revenue", f"₹{revenue_values.median():,.0f}")
542
- st.metric("Max Revenue", f"₹{revenue_values.max():,.0f}")
543
- elif revenue_values.empty:
544
- st.info(f"No positive revenue values found in {best_col}")
545
- else:
546
- st.info("Insufficient data for distribution chart")
547
  else:
548
  st.info("Revenue column not found. Add a revenue/amount column to plot this chart.")
549
 
 
516
  # Filter to positive values only
517
  revenue_values = revenue_values[revenue_values > 0].dropna()
518
 
519
+ if revenue_values.empty:
520
+ st.info(f"No positive revenue values found in {best_col}")
521
+ elif len(revenue_values) <= 5:
522
+ st.info("Insufficient data for distribution chart")
523
+ else:
524
  try:
525
+ # Create histogram using DataFrame format for better Streamlit compatibility
526
+ nbins = min(30, max(5, len(revenue_values) // 10))
527
+ df_hist = pd.DataFrame({'Revenue': revenue_values})
528
+
529
  fig = px.histogram(
530
+ df_hist,
531
+ x='Revenue',
532
+ nbins=nbins,
533
  title=f"Revenue Distribution - {best_col}",
534
+ color_discrete_sequence=['#636EFA']
 
535
  )
536
  fig.update_layout(
537
  height=400,
538
  xaxis_title=best_col,
539
  yaxis_title="Count",
540
+ hovermode='x unified',
541
+ showlegend=False
542
  )
543
  fig.update_traces(marker=dict(line=dict(width=0)))
544
  st.plotly_chart(fig, use_container_width=True)
545
  except Exception as e:
546
+ st.error(f"Error creating histogram: {str(e)}")
547
+ # Fallback: show summary stats in columns
548
+ col_stats1, col_stats2, col_stats3 = st.columns(3)
549
+ with col_stats1:
550
+ st.metric("Average", f"₹{revenue_values.mean():,.0f}")
551
+ with col_stats2:
552
+ st.metric("Median", f"{revenue_values.median():,.0f}")
553
+ with col_stats3:
554
+ st.metric("Max", f"₹{revenue_values.max():,.0f}")
555
  else:
556
  st.info("Revenue column not found. Add a revenue/amount column to plot this chart.")
557