admin管理员组文章数量:1434949
I am building an angular application. In which we need to create on click buttons for zooming in and zooming out for plotly chart. We can zoom in zoom out in plotly chart using buttons on hoverable mode bar but this is not required for our application. We want to zoom in and zoom out the chart using user created on click buttons. Is there a way to trigger actions of hoverable mode bar zoom in and out using on click buttons? if not then what are the other ways to do? any suggestion is appreciated.
Code in .ts file
basicChart() {
var trace1 = {
x: ['2020-10-04', '2021-11-04', '2023-12-04'],
y: [90, 40, 60],
type: 'scatter'
};
var data = [trace1];
var layout = {
title: 'Chart',
showlegend: false
};
Plotly.newPlot('myDiv', data, layout);
}
I am building an angular application. In which we need to create on click buttons for zooming in and zooming out for plotly chart. We can zoom in zoom out in plotly chart using buttons on hoverable mode bar but this is not required for our application. We want to zoom in and zoom out the chart using user created on click buttons. Is there a way to trigger actions of hoverable mode bar zoom in and out using on click buttons? if not then what are the other ways to do? any suggestion is appreciated.
Code in .ts file
basicChart() {
var trace1 = {
x: ['2020-10-04', '2021-11-04', '2023-12-04'],
y: [90, 40, 60],
type: 'scatter'
};
var data = [trace1];
var layout = {
title: 'Chart',
showlegend: false
};
Plotly.newPlot('myDiv', data, layout);
}
Share
Improve this question
edited Jan 20, 2020 at 8:30
ankitkanojia
3,1224 gold badges24 silver badges37 bronze badges
asked Jan 20, 2020 at 4:45
VikramVikram
931 silver badge6 bronze badges
4
- Please add your existing code to give users a place to start. – sfarbota Commented Jan 20, 2020 at 4:53
- @sfarbota I have added the .ts file code. – Vikram Commented Jan 20, 2020 at 5:03
- 1 You cannot trigger native Plotly events, but you can provide new X and Y ranges for your chart and apply Plotly.relayout. Can't your users a mouse for zooming in? – Mark Commented Jan 28, 2020 at 20:27
- Yes I did it this way only. @Mark – Vikram Commented Jan 30, 2020 at 9:07
1 Answer
Reset to default 4I had this same problem and ended up just using the DOM to click the modebar.
zoom-functions-example.js
const plot = Plotly.newPlot('myDiv', data, layout)
let zoomIn = function(plot){
plot.querySelector('a[data-attr="zoom"][data-val="in"]').click()
},
let zoomOut = function(plot){
plot.querySelector('a[data-attr="zoom"][data-val="out"]').click()
},
let resetView = function(plot){
plot.querySelector('a[data-attr="zoom"][data-val="reset"]').click()
},
CSS to hide modebar:
.modebar-container{
display: none;
}
本文标签:
版权声明:本文标题:javascript - How to trigger zoom in and zoom out in plotly chart using user created on click buttons? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745636222a2667573.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论