Search⌘ K

Exercise: Data Buttons on Line Charts

Explore how to create interactive line charts in Plotly by adding date range buttons for different time spans. Learn to build 2x1 grid subplots with customized date selectors for pricing and volume data, enhancing chart interactivity and data exploration.

We'll cover the following...

Exercise 1

Create a red line chart of the spy closing prices. Add date buttons for 20 years into the past, 10 years into the past, 5 years into the past, 1 year into the past, 6 months into the past, 3 months into the past, 1 month into the past, the year so far and the month so far. Also, add an option to see all of the available data.

Solution

  • A trace is created using the go.Scatter() function on line 2 with x and y values taken from the spy DataFrame.

  • A figure is created using the go.Figure() function on line 5 ...