admin管理员组文章数量:1405567
I am using react to render 2 charts, a line chart and bar chart stack vertically. When I scroll to look at barChart below, after each update, chartjs, forces my scroll to (0,0). I have seen some implementation that does not move the scroll's position after each update.
Please help
<canvas id="lineChart" onLoad={ load() }>
Your browser does not support canvas, please upgrade to latest browser
</canvas>
<canvas id="barChart" onLoad={ load() }>
Your browser does not support canvas, please upgrade to latest browser
</canvas>
//to load chart.js
var myChart = new Chart($("#barChart")[0], {
type: 'bar',
data: {
labels: props.labels,
datasets: [{
label: props.label,
data: props.data,
backgroundColor: props.labels.map(l => props.color) ,
borderColor: props.labels.map(l => props.borderColor) ,
borderWidth: 0.01
}]
},
options: {
scales: {
yAxes: [{
ticks: {beginAtZero: true}
}]
}
}
});
I am using react to render 2 charts, a line chart and bar chart stack vertically. When I scroll to look at barChart below, after each update, chartjs, forces my scroll to (0,0). I have seen some implementation that does not move the scroll's position after each update.
Please help
<canvas id="lineChart" onLoad={ load() }>
Your browser does not support canvas, please upgrade to latest browser
</canvas>
<canvas id="barChart" onLoad={ load() }>
Your browser does not support canvas, please upgrade to latest browser
</canvas>
//to load chart.js
var myChart = new Chart($("#barChart")[0], {
type: 'bar',
data: {
labels: props.labels,
datasets: [{
label: props.label,
data: props.data,
backgroundColor: props.labels.map(l => props.color) ,
borderColor: props.labels.map(l => props.borderColor) ,
borderWidth: 0.01
}]
},
options: {
scales: {
yAxes: [{
ticks: {beginAtZero: true}
}]
}
}
});
Share
Improve this question
asked Oct 8, 2016 at 18:21
vdj4yvdj4y
2,6692 gold badges23 silver badges32 bronze badges
1 Answer
Reset to default 9I had a similar issue when destroying a chart and recreating it. My workaround was to get the scroll position before destruction and reapply it after creation. For example in jQuery:
var pos = $(document).scrollTop();
if (chart != undefined)
chart.destroy();
chart = new Chart(ctx, chartOptions);
$(document).scrollTop(pos);
本文标签: javascriptChartjsafter each updateavoid scrolling to top positionStack Overflow
版权声明:本文标题:javascript - chart.js, after each update, avoid scrolling to top position - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744342412a2601557.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论