javascript - How do I move Plotly.js legend off second y axis -
plotly.js defaults have legend covering second y axis. here own code pen example of happening: https://codepen.io/plotly/pen/36d6c70e8fa17e471fa68788abbed90f
var trace1 = { x: [1, 2, 3], y: [40, 50, 60], name: 'yaxis data', type: 'scatter' }; var trace2 = { x: [2, 3, 4], y: [4, 5, 6], name: 'yaxis2 data', yaxis: 'y2', type: 'scatter' }; var data = [trace1, trace2]; var layout = { title: 'double y axis example', yaxis: {title: 'yaxis title'}, yaxis2: { title: 'yaxis2 title', titlefont: {color: 'rgb(148, 103, 189)'}, tickfont: {color: 'rgb(148, 103, 189)'}, overlaying: 'y', side: 'right' } }; plotly.newplot('mydiv', data, layout);
i cannot legend move more right. have tried adjusting margin/padding on plot, x position of legend, margin/padding on legend, overall size of div, , orientation of legend.
on topic of legend orientation, potentially put legend below plot solve problem. however, having trouble implementing that. here legend layout code:
legend: {orientation: 'h', y: -0.17, x: 0, font: { family:'roboto', size: 10, color: 'rgb(54, 54, 54)'} },
clearly there lot of code missing here , isn't working example of problem, orientation not changing horizontal.
what placing under plot? can adjust it's position changing x
, y
values inside legend
property.
var trace1 = { x: [1, 2, 3], y: [40, 50, 60], name: 'yaxis data', type: 'scatter' }; var trace2 = { x: [2, 3, 4], y: [4, 5, 6], name: 'yaxis2 data', yaxis: 'y2', type: 'scatter' }; var data = [trace1, trace2]; var layout = { title: 'double y axis example', yaxis: { title: 'yaxis title' }, yaxis2: { title: 'yaxis2 title', titlefont: { color: 'rgb(148, 103, 189)' }, tickfont: { color: 'rgb(148, 103, 189)' }, overlaying: 'y', side: 'right' }, legend: { y: 1, x: 1.1, bgcolor: 'transparent', } }; plotly.newplot('mydiv', data, layout);
<head> <!-- plotly.js --> <script src="https://cdn.plot.ly/plotly-latest.min.js"></script> </head> <body> <div id="mydiv" style="width: 480px; height: 400px;"> <!-- plotly chart drawn inside div --> </div> <script> <!-- javascript code goes here --> </script> </body>
Comments
Post a Comment