Skip to content
Javier Cardenas — home

Google Finance Chart Implementation

December 15 2023

Google Finance has one of the cleaner financial chart implementations on the web. This project is an attempt to recreate its 5Y line chart as faithfully as possible using Observable Plot, building every detail from scratch including the gradient fill, the crosshair pointer, and the floating tooltip.

Google Finance 5Y TSLA chart
Source: Google Finance 5Y chart using TSLA data

The dataset covers Tesla stock prices from December 2018 to December 2023, with weekly granularity. Each entry includes the closing price, the weekly high, and the weekly low. The data is parsed with d3.autoType so dates and numbers are handled correctly without manual conversion.

The chart is assembled in five layers, each one added on top of the previous using Observable Plot's marks array.

① Line
Closing price as a green stroke
② Area
Gradient fill beneath the line
③ Rule
Dashed vertical crosshair on hover
④ Dot
Circle snapping to the nearest point
246.38 USD · Jan 5 2024
⑤ Tooltip
HTML tooltip via SVG foreignObject

The gradient fill is defined as an SVG linearGradient with four opacity stops. It fades quickly at the top and reaches full transparency before hitting the x-axis, which gives it that characteristic soft glow rather than a hard block of color.

0%opacity 0.30
30%opacity 0.20
60%opacity 0.10
80%opacity 0.00

The tooltip uses SVG foreignObject to embed real HTML directly inside the chart. Its horizontal position has three states to avoid clipping at either edge of the container.

246.38 · Jan 5
Left edge: tooltip anchors to the left margin
246.38 · Jan 5
Center: tooltip follows the pointer
246.38 · Jan 5
Right edge: tooltip anchors to the right margin

The result is below. The full walkthrough with all the code is in the Observable notebook.

hover hand
Hover the chart to see the crosshair and tooltip in action.