Skip to content

Implement hovertemplate for candlestick and ohlc traces#7619

Merged
emilykl merged 10 commits intomasterfrom
add-hovertemplate-for-candlestick
Nov 13, 2025
Merged

Implement hovertemplate for candlestick and ohlc traces#7619
emilykl merged 10 commits intomasterfrom
add-hovertemplate-for-candlestick

Conversation

@emilykl
Copy link
Contributor

@emilykl emilykl commented Nov 12, 2025

Closes #3437

This PR adds a hovertemplate attribute for ohlc and candlestick, allowing users to define a custom hover template for those traces.

hovertemplate: 'opened at %{open}<br>closed at %{close}<extra></extra>',

Screenshot 2025-11-12 at 11 12 13 AMScreenshot 2025-11-13 at 10 41 10 AM

Notes

  • The first commit of this PR runs the biome formatter which introduces some noise into the diff. Use this link to see only the meaningful changes.

  • This PR also adds the hovertemplatefallback attribute for the two traces in question

  • hovertemplate is ignored when hoverlabel.split is set to true. (Open to suggestions here but I couldn't see an obvious way to make split: true work with the hovertemplate API.)

  • Two Jasmine tests added

This completes the list in #3437.

Thanks to @chriddyp for putting this on my radar!

To test

  • Create a plot like this one:
Plotly.newPlot(
    "plot", 
    [
        {
            x: [1, 2, 3, 4, 5],
            low: [21, 13, 18, 16, 22],
            high: [34, 23, 25, 26, 24],
            open: [24, 16, 22, 23, 22],
            close: [22, 18, 21, 21, 23],
            type: 'candlestick',  // or 'ohlc'
            hovertemplate: 'opened at %{open}<br>closed at %{close}<extra></extra>',
            // hoverlabel: {split: true},  
            // if the above line is uncommented, `hovertemplate` should be ignored
            // and separate hover tooltips should be shown for open, high, low, and close
        }
    ], 
);
  • Hover over the data and confirm that the hovertemplate is respected
  • Confirm that if hoverlabel.split is set to true, the hovertemplate is ignored and the previous behavior is unchanged
@robertclaus robertclaus assigned emilykl and camdecoster and unassigned emilykl Nov 12, 2025
Copy link
Contributor

@camdecoster camdecoster left a comment

Choose a reason for hiding this comment

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

As we discussed, there's an issue with implementing the split: true logic that makes the split hover info not show up. Could you look into that?

emilykl and others added 3 commits November 12, 2025 16:22
Co-authored-by: Cameron DeCoster <cameron.decoster@gmail.com>
Co-authored-by: Cameron DeCoster <cameron.decoster@gmail.com>
@emilykl emilykl force-pushed the add-hovertemplate-for-candlestick branch 2 times, most recently from 6c901b2 to cd1f39e Compare November 13, 2025 15:04
@emilykl
Copy link
Contributor Author

emilykl commented Nov 13, 2025

@camdecoster The bug you found with split: true should be fixed now. Ready for another look. I also added a Jasmine test which tests split: true and hovertemplate together.

@emilykl emilykl force-pushed the add-hovertemplate-for-candlestick branch from cd1f39e to 6800433 Compare November 13, 2025 16:09
Copy link
Contributor

@camdecoster camdecoster left a comment

Choose a reason for hiding this comment

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

Looks good. Could you please add a draftlog before merging?

@emilykl emilykl force-pushed the add-hovertemplate-for-candlestick branch from 54bce31 to fb6e114 Compare November 13, 2025 18:50
@emilykl emilykl merged commit f0d7961 into master Nov 13, 2025
6 checks passed
@emilykl emilykl deleted the add-hovertemplate-for-candlestick branch November 13, 2025 19:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants