Public
Edited
Apr 24, 2023
Insert cell
Insert cell
Insert cell
data = hasApiKey
? stripe("/v1/balance_transactions")
: FileAttachment("sample-transactions.json").json()
Insert cell
Plot.plot({
y: {
tickFormat: "$.2",
label: "Revenue"
},
color: {
domain: [-1, 1],
scheme: "RdBu"
},
marks: [
Plot.ruleY([0]),
Plot.rectY(
data,
Plot.binX(
{ y: "sum" },
{
x: (d) => new Date(d.created * 1000), // Stripe gives dates as seconds since Unix epoch
y: (d) => d.net / 100, // Stripe gives transaction amounts in cents
fill: (d) => Math.sign(d.net), // Inflows blue, outflows red
thresholds: d3.utcWeek // Bin by week
}
)
)
]
})
Insert cell
import {stripe, hasApiKey} from "@observablehq/stripe-api-helpers"
Insert cell
// For a notebook to access Secrets, it must statically reference one; this cell grants Secret access to the notebook from which we import the GitHub API helpers. `undefined &&` prevents the Secret from appearing in plaintext in the Inspector.
undefined && Secret("STRIPE_API_KEY")
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more