Skip to content

Commit 1f8a698

Browse files
committed
Create 2023-06-25-shapes-legends.html
1 parent 6dd3bf7 commit 1f8a698

File tree

1 file changed

+89
-0
lines changed

1 file changed

+89
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
---
2+
name: Adding Shapes to Legends
3+
language: plotly_js
4+
suite: shape
5+
order: 12
6+
sitemap: false
7+
arrangement: horizontal
8+
markdown_content: |
9+
Set `showlegend: true` on a shape to add it to the legend.
10+
---
11+
var data = [
12+
{
13+
x: [
14+
'2015-02-01', '2015-02-02', '2015-02-03', '2015-02-04', '2015-02-05',
15+
'2015-02-06', '2015-02-07', '2015-02-08', '2015-02-09', '2015-02-10',
16+
'2015-02-11', '2015-02-12', '2015-02-13', '2015-02-14', '2015-02-15',
17+
'2015-02-16', '2015-02-17', '2015-02-18', '2015-02-19', '2015-02-20',
18+
'2015-02-21', '2015-02-22', '2015-02-23', '2015-02-24', '2015-02-25',
19+
'2015-02-26', '2015-02-27', '2015-02-28',
20+
],
21+
y: [
22+
14, 17, 8, 4, 7, 10, 12, 14, 12, 11, 10, 9, 18, 14, 14, 16, 13, 8, 8,
23+
7, 7, 3, 9, 9, 4, 13, 9, 6,
24+
],
25+
mode: 'line',
26+
name: 'Revenue',
27+
},
28+
];
29+
30+
var layout = {
31+
title: 'Product price changes and revenue growth',
32+
xaxis: { title: 'Date' },
33+
yaxis: { title: 'Revenue Growth' },
34+
dragmode: 'drawline',
35+
36+
shapes: [
37+
{
38+
showlegend: true,
39+
type: 'rect',
40+
xref: 'x',
41+
yref: 'paper',
42+
x0: '2015-02-02',
43+
y0: 0,
44+
x1: '2015-02-08',
45+
y1: 1,
46+
fillcolor: '#d3d3d3',
47+
opacity: 0.2,
48+
editable: true,
49+
line: {
50+
width: 0,
51+
},
52+
label: {
53+
text: 'Price drop',
54+
font: { size: 10, color: 'green' },
55+
textposition: 'top center',
56+
},
57+
},
58+
{
59+
showlegend: true,
60+
type: 'line',
61+
x0: '2015-02-01',
62+
y0: 8,
63+
x1: '2015-02-28',
64+
y1: 8,
65+
fillcolor: '#d3d3d3',
66+
opacity: 0.2,
67+
editable: true,
68+
label: {
69+
text: 'January average',
70+
yanchor: 'top',
71+
},
72+
},
73+
],
74+
newshape: { showlegend: true },
75+
height: 500,
76+
width: 500,
77+
};
78+
79+
var config = { 'modeBarButtonsToAdd': [
80+
'drawline',
81+
'drawopenpath',
82+
'drawclosedpath',
83+
'drawcircle',
84+
'drawrect',
85+
'eraseshape'
86+
]
87+
};
88+
89+
Plotly.newPlot('myDiv', data, layout, config);

0 commit comments

Comments
 (0)