Skip to content

Commit 83065e5

Browse files
committed
Add unified hover examples
1 parent 7efd9ae commit 83065e5

File tree

2 files changed

+88
-0
lines changed

2 files changed

+88
-0
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
---
2+
name: Custom Unified Hover Title
3+
language: plotly_js
4+
suite: hover
5+
order: 5
6+
sitemap: false
7+
arrangement: horizontal
8+
markdown_content: |
9+
Customize the title shown in unified hovermode by specifying `unifiedhovertitle.text`. The unified hover title is a template string that supports using variables from the data. Numbers are formatted using d3-format's syntax `%{variable:d3-format}`, for example `"Price: %{y:$.2f}"`. Dates are formatted using d3-time-format's syntax `%{variable|d3-time-format}`, for example `"Day: %{x|%A}"`.
10+
---
11+
var data = [
12+
{
13+
x: ['2020-01-01', '2020-02-01', '2020-03-01', '2020-04-01'],
14+
y: [150.25, 165.50, 142.75, 178.90],
15+
mode: 'lines+markers',
16+
name: 'Stock A',
17+
type: 'scatter'
18+
},
19+
{
20+
x: ['2020-01-01', '2020-02-01', '2020-03-01', '2020-04-01'],
21+
y: [85.30, 92.15, 88.45, 95.20],
22+
mode: 'lines+markers',
23+
name: 'Stock B',
24+
type: 'scatter'
25+
}
26+
];
27+
28+
var layout = {
29+
title: {
30+
text: "Stock Prices with Custom Unified Hover Title"
31+
},
32+
hovermode: 'x unified',
33+
xaxis: {
34+
title: 'Date',
35+
unifiedhovertitle: {
36+
text: '<b>%{x|%A, %B %d, %Y}</b>'
37+
}
38+
},
39+
yaxis: {
40+
title: 'Price (USD)',
41+
tickprefix: '$'
42+
}
43+
};
44+
45+
Plotly.newPlot('myDiv', data, layout);
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
---
2+
name: Unified Hover Mode
3+
language: plotly_js
4+
suite: hover
5+
order: 4
6+
sitemap: false
7+
arrangement: horizontal
8+
markdown_content: |
9+
If "x unified" (or "y unified"), a single hoverlabel will appear for multiple points at the closest x- (or y-) coordinate within the `hoverdistance` with the caveat that no more than one hoverlabel will appear per trace.
10+
---
11+
var data = [
12+
{
13+
x: ['2020-01-01', '2020-02-01', '2020-03-01', '2020-04-01'],
14+
y: [10, 15, 12, 18],
15+
mode: 'markers+lines',
16+
name: 'Series A',
17+
hovertemplate: null,
18+
type: 'scatter'
19+
},
20+
{
21+
x: ['2020-01-01', '2020-02-01', '2020-03-01', '2020-04-01'],
22+
y: [8, 12, 16, 14],
23+
mode: 'markers+lines',
24+
name: 'Series B',
25+
hovertemplate: null,
26+
type: 'scatter'
27+
}
28+
];
29+
30+
var layout = {
31+
title: {
32+
text: "layout.hovermode='x unified'"
33+
},
34+
hovermode: 'x unified',
35+
xaxis: {
36+
title: 'Date'
37+
},
38+
yaxis: {
39+
title: 'Value'
40+
}
41+
};
42+
43+
Plotly.newPlot('myDiv', data, layout);

0 commit comments

Comments
 (0)