Skip to content

Commit 1585aa3

Browse files
AtishayMsftatisjai
andauthored
Add examples for tables (#146)
Co-authored-by: Atishay Jain (from Dev Box) <[email protected]>
1 parent aa41492 commit 1585aa3

File tree

6 files changed

+2055
-0
lines changed

6 files changed

+2055
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import plotly.graph_objects as go
2+
import json
3+
4+
# Create the table
5+
products = ["Apples", "Bananas", "Oranges"]
6+
quantities = [10, 20, 15]
7+
prices = [1.0, 0.5, 0.75]
8+
totals = [q * p for q, p in zip(quantities, prices)]
9+
10+
fig = go.Figure(data=[go.Table(
11+
header=dict(values=["Product", "Quantity", "Price", "Total"]),
12+
cells=dict(values=[products + ["Total"],
13+
quantities + [sum(quantities)],
14+
prices + [""],
15+
totals + [sum(totals)]])
16+
)])
17+
18+
# Export to JSON
19+
fig_json = fig.to_json()
20+
21+
# Save to file
22+
with open("table_total_rows.json", "w") as f:
23+
f.write(fig_json)
24+
25+
# Optional: print preview of JSON (first 300 characters)
26+
print(fig_json[:300])

0 commit comments

Comments
 (0)