Chart.js -设备方向改变时响应性不正确
Chart.js - Responsiveness not correctly working on device orientation change
我已经将Chart.js
实现到我的项目中,该项目没有问题,但是我在移动设备上改变方向时遇到问题
如果屏幕从portait
模式更改为landscape
,则一切都按预期调整大小,
但当改变形式landscape
到portrait
图表没有被调整大小…它保持风景模式的宽度。
我正在寻找一种方法来做到这一点没有使用jQuery-mobile
如果有人知道如何处理这种(错误)行为,我真的很高兴知道该怎么做。
监听方向改变事件(在jQuery mobile - $(window).on("orientationchange",function(){ ... });
中)并触发窗口大小调整(如果你有jQuery,这可以像$(window).trigger('resize');
一样简单
或者,您可以复制在方向更改处理程序
中调整窗口大小时执行的代码。function () {
// Basic debounce of resize function so it doesn't hurt performance when resizing browser.
var timeout;
return function () {
clearTimeout(timeout);
timeout = setTimeout(function () {
Chart.helpers.each(Chart.instances, function (instance) {
// If the responsive flag is set in the chart instance config
// Cascade the resize event down to the chart.
if (instance.options.responsive) {
instance.resize(instance.render, true);
}
});
}, 50);
};
};
主要是复制粘贴的Chart.js库代码,除了我替换了Chart.helpers.each
我在不同方向的移动设备上也遇到了类似的问题。使用CSS样式解决了这个问题。如:
@media (orientation:portrait) {
.chart-container {
min-height: 40vh;
}
}
@media (orientation:landscape) {
.chart-container {
min-height: 90vh;
}
}
相关文章:
- Jquery菜单操作不稳定,定位不正确,存在一般错误
- Amazon S3 REST API大小不正确
- Javascript Reg Exp不正确匹配
- DIV并排,位置不正确
- 仅在IE中,javascript中的时区名称不正确
- 注意:wp_enqueue_script调用不正确.在 Wordpress 调试模式下
- 你能解释一下为什么这个javascript不正确吗
- 从int值来看,Javascript日期不正确
- jQuery-迭代不正确?(太长,无法执行)
- 字符串解析不正确
- 日历显示不正确
- 引导程序下拉列表显示不正确
- Node.js:多个然后'It’执行顺序不正确
- Highcharts热图显示不正确
- Mongoose响应解析不正确
- Flask模板和Datatables-响应表加载不正确
- Chart.js -设备方向改变时响应性不正确
- 为什么solr的这个响应不正确
- 使用ngResource从spring mvc到angular js的响应不正确
- JSON响应格式不正确(angularjs)