New releases

Hotwire Club tooling is now open-source

Explore the agentic skills pack and the MCP server for building assistant workflows.

Stimulus - Value Changed Callbacks

Reactively update a chart.js graph using Stimulus values.

View Solution on Patreon
Stimulus - Value Changed Callbacks

Premise

Our first Stimulus challenge is here! 🎉

Turbo equips us with a ton of functionality to simplify our DOM mutating actions, but when 3rd party libraries come into the picture, it gets complicated. In our example here, we have a chart powered by chart.js displaying the prices of three imaginary stocks.

That is, at the moment they don’t display anything 🤯

Challenge

Our chart controller receives continuous price updates via a stimulus value called stockPrices. This value contains stock prices in a plain object of the following structure:

{
  TechCorp: [...],
  HealthLabs: [...],
  EcoEnergy: [...]
}

In the connect callback, our controller is already initialized with the correct chart configuration: https://stackblitz.com/edit/stimulus-value-changed-callbacks?file=controllers%2Fchart_controller.js%3AL18

Your task is to react to the incoming price changes by updating the charge in the corresponding value change listener here: https://stackblitz.com/edit/stimulus-value-changed-callbacks?file=controllers%2Fchart_controller.js%3AL53

This is what the end result should look like:

An Animated Stock Chart

Caveats

The default animation is quite annoying, in my opinion. You might want to switch it off.

Teaser

Can you spice this up with animations? For example, the “progressive line with easing” example looks interesting.

This is The Hotwire Club

46 hands-on challenges with detailed solutions, published biweekly since 2023. Subscribe to access all solutions and join the Discord community.

Subscribe on Patreon

More from

Turbo Frames - Chained Selects
24 March 2026

Build dependent dropdown menus that update dynamically using Turbo Frames and a small Stimulus controller.

Stimulus - Web Share API
25 November 2025

Use the native browser web sharing capabilities from Stimulus

Faceted Search with Stimulus and Turbo Frames
10 December 2024

Harness the power of Stimulus and Turbo Frames to drive a simple but powerful faceted search solution

essential