Skip to content

docs: recharts chart techniques from AI builder field notes#6778

Open
amsraman wants to merge 1 commit into
mainfrom
docs/recharts-field-notes
Open

docs: recharts chart techniques from AI builder field notes#6778
amsraman wants to merge 1 commit into
mainfrom
docs/recharts-field-notes

Conversation

@amsraman

Copy link
Copy Markdown
Contributor

Third batch of upstreaming Reflex Build's AI-builder knowledge base into the docs (#6775, #6777). Recharts techniques the chart pages lacked:

  • areachart / barchart: SVG gradient fills (rx.el.svg.defs + linear_gradient, fill="url(#id)"), rounded bars (radius)
  • linechart: styled axis labels (rx.recharts.label + custom_attrs, rotated y-label)
  • piechart: per-slice coloring via rx.foreach + rx.recharts.cell with an indexed palette, radial gradient fills
  • scatterchart: distinguishing series with shape
  • general/axis, label, cartesiangrid: tick styling, label styling, grid styling
  • barchart + piechart interactivity: click drill-down via per-cell on_click (bar on_click provides no args) and hover events with cell-index binding

Flexgen house style (custom HTML legends, tooltip prop constants) was deliberately stripped — only generic techniques upstreamed. Pages whose memories were already covered (radar, funnel, composed) were left untouched. All new demos exec-verified; pre-commit clean.

🤖 Generated with Claude Code

Gradient fills (area/bar/pie), rounded bars, axis label styling,
per-slice cell coloring, series shapes, tick/grid styling, and
click-drilldown + hover-event recipes. All demos exec-verified.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@amsraman amsraman requested review from a team and Alek99 as code owners July 15, 2026 23:06
@codspeed-hq

codspeed-hq Bot commented Jul 15, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 26 untouched benchmarks
⏩ 8 skipped benchmarks1


Comparing docs/recharts-field-notes (3e2de46) with main (65a2889)2

Open in CodSpeed

Footnotes

  1. 8 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

  2. No successful run was found on main (127e4d8) during the generation of this report, so 65a2889 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

@greptile-apps

greptile-apps Bot commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR adds a third batch of Recharts documentation improvements, upstreaming chart techniques from field notes into the library docs. Each new section is a self-contained, exec-verified demo showing a specific technique (SVG gradient fills, rounded bars, per-slice coloring, axis/label/grid styling, hover and click drill-down events).

  • areachart / barchart: SVG linear gradient fills via rx.el.svg.defs + linear_gradient, and rounded bar corners via the radius prop.
  • barchart / piechart: Interactive drill-down and hover patterns using rx.foreach + rx.recharts.cell so per-item data is bound at render time; axis, label, and grid styling sections added to the general pages.
  • piechart: Per-slice coloring with an indexed palette, radial gradient fills via a hidden sibling SVG, and a hover-to-reveal center-label pattern.

Confidence Score: 4/5

All changes are additive docs examples with no effect on library code; the existing pages are untouched. Two small issues in piechart.md are worth fixing before merge but neither breaks existing docs.

Most new sections are clean and follow existing patterns. The piechart additions have two fixable issues: the hover demo accesses PIE_HOVER_COLORS by raw index without a modulo guard, and both create_gradient and create_bar_gradient use id as a parameter name shadowing Python's built-in. Neither issue affects the other seven files.

docs/library/graphing/charts/piechart.md — the hover demo color indexing and the gradient helper parameter name both need a small fix.

Important Files Changed

Filename Overview
docs/library/graphing/charts/areachart.md Adds a Gradient Fill section demonstrating SVG linear gradients with rx.el.svg.defs inside the chart. Code is clean and pattern is consistent with the bar chart approach.
docs/library/graphing/charts/barchart.md Adds click drill-down, rounded bars, and gradient fill sections. The create_bar_gradient helper uses id as a parameter name, shadowing the Python built-in; a rename to gradient_id is the only issue.
docs/library/graphing/charts/linechart.md Adds an Axis Labels section showing rx.recharts.label with custom_attrs for rotation. Code is clean and the margin/height values give the labels adequate space.
docs/library/graphing/charts/piechart.md Adds per-slice coloring, radial gradient fills, and hover events. Two issues: PIE_HOVER_COLORS is accessed without a modulo guard (inconsistent with the pie_cells pattern above it), and create_gradient uses id as a parameter name shadowing the built-in.
docs/library/graphing/charts/scatterchart.md Adds a Distinguishing Series with Shapes section. The first series intentionally omits shape (uses default circle) while the other two use triangle and star.
docs/library/graphing/general/axis.md Adds a Styling Axis Ticks section demonstrating axis_line, tick_line, tick_size, interval, and custom_attrs for font size. Clean and accurate.
docs/library/graphing/general/cartesiangrid.md Adds a Styling the Grid section showing horizontal-only grid lines with reduced opacity via class_name. Simple and correct.
docs/library/graphing/general/label.md Adds a Styling Labels section showing font-size, font-weight, and angle rotation via custom_attrs on rx.recharts.label. Code is clean and the chart margin is sufficient for the rotated y-axis label.

Reviews (1): Last reviewed commit: "docs: recharts chart techniques from AI ..." | Re-trigger Greptile

rx.foreach(
PieHoverState.languages,
lambda item, index: rx.recharts.cell(
fill=rx.Var.create(PIE_HOVER_COLORS)[index],

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 The PIE_HOVER_COLORS list is indexed without a modulo guard, so if languages ever has more items than there are colors (> 5), the JavaScript expression evaluates to undefined and the affected slices lose their fill entirely (SVG defaults to black). The pie_cells example in the same file uses index % len(colors) to avoid this — the hover example should match.

Suggested change
fill=rx.Var.create(PIE_HOVER_COLORS)[index],
fill=rx.Var.create(PIE_HOVER_COLORS)[index % len(PIE_HOVER_COLORS)],

Comment on lines +351 to +360
def create_bar_gradient(color: str, id: str) -> rx.Component:
return rx.el.svg.linear_gradient(
rx.el.svg.stop(offset="5%", stop_color=color, stop_opacity=0.8),
rx.el.svg.stop(offset="95%", stop_color=color, stop_opacity=0.2),
id=id,
x1=0,
y1=0,
x2=0,
y2=1,
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 id is a Python built-in function, so using it as a parameter name in create_bar_gradient shadows it in that scope. A small rename sidesteps the issue and is the idiomatic convention for SVG element id arguments.

Suggested change
def create_bar_gradient(color: str, id: str) -> rx.Component:
return rx.el.svg.linear_gradient(
rx.el.svg.stop(offset="5%", stop_color=color, stop_opacity=0.8),
rx.el.svg.stop(offset="95%", stop_color=color, stop_opacity=0.2),
id=id,
x1=0,
y1=0,
x2=0,
y2=1,
)
def create_bar_gradient(color: str, gradient_id: str) -> rx.Component:
return rx.el.svg.linear_gradient(
rx.el.svg.stop(offset="5%", stop_color=color, stop_opacity=0.8),
rx.el.svg.stop(offset="95%", stop_color=color, stop_opacity=0.2),
id=gradient_id,
x1=0,
y1=0,
x2=0,
y2=1,
)

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Comment on lines +151 to +161
def create_gradient(color: str, id: str) -> rx.Component:
return rx.el.svg.radial_gradient(
rx.el.svg.stop(offset="10%", stop_color=color, stop_opacity=1),
rx.el.svg.stop(offset="95%", stop_color=color, stop_opacity=0.6),
id=id,
cx="50%",
cy="50%",
r="50%",
fx="50%",
fy="50%",
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 id shadows Python's built-in id() function both in the create_gradient signature and in the list comprehensions that unpack gradients. Renaming to gradient_id avoids the shadowing and keeps the code consistent with the suggested fix to create_bar_gradient.

Suggested change
def create_gradient(color: str, id: str) -> rx.Component:
return rx.el.svg.radial_gradient(
rx.el.svg.stop(offset="10%", stop_color=color, stop_opacity=1),
rx.el.svg.stop(offset="95%", stop_color=color, stop_opacity=0.6),
id=id,
cx="50%",
cy="50%",
r="50%",
fx="50%",
fy="50%",
)
def create_gradient(color: str, gradient_id: str) -> rx.Component:
return rx.el.svg.radial_gradient(
rx.el.svg.stop(offset="10%", stop_color=color, stop_opacity=1),
rx.el.svg.stop(offset="95%", stop_color=color, stop_opacity=0.6),
id=gradient_id,
cx="50%",
cy="50%",
r="50%",
fx="50%",
fy="50%",
)

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3e2de46c5e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

outer_radius="80%",
padding_angle=2,
stroke="#fff",
stroke_width=2,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Use a supported prop for pie slice stroke width

In these pie demos, stroke_width is not a declared prop on rx.recharts.pie (checked the Pie wrapper in packages/reflex-components-recharts/src/reflex_components_recharts/polar.py), so Reflex treats it as a style key and renders it via wrapperStyle rather than forwarding strokeWidth to Recharts. Users copying this example therefore won't get the advertised slice separator width (the gradient demo below has the same issue); use custom_attrs={"strokeWidth": 2} or expose a real stroke_width prop.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant