在 Retina 显示屏上使用 Flot 创建高分辨率图表
我想在我的 Web 应用程序中显示一些简单的图表,但在配备 Retina 显示屏的 Apple 设备上使用 Flot 看起来很模糊。
我使用“正常”视口设置:
以及 Flot 的此容器绘制:
这就是我得到的:
显然,Flot 默认情况下不使用 window.devicePixelRatio
,所以我想帮忙一些自定义代码:
var newWidth = $(chart.getCanvas()).attr("width") * window.devicePixelRatio;
var newHeight = $(chart.getCanvas()).attr("height") * window.devicePixelRatio;
$(chart.getCanvas()).attr("width", newWidth);
$(chart.getCanvas()).attr("height", newHeight);
chart.setupGrid();
chart.draw();
这实际上改变了画布的尺寸,并且即使在绘制之后它们仍然保持这种状态。在 iPhone 4S 上,它告诉我画布尺寸现在为 600 * 800(绘制后),但看起来仍然不清晰。
I want to show some simple chart in my web application, but using Flot on an Apple device with Retina display looks blurry.
I use the 'normal' viewport settings:
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" />
and this container for Flot to draw in:
<div id="placeholder" style="width: 300px;height:400px;"></div>
This is what I get:
So obivously Flot doesn't use window.devicePixelRatio
by default, so I wanted to help out with some custom code:
var newWidth = $(chart.getCanvas()).attr("width") * window.devicePixelRatio;
var newHeight = $(chart.getCanvas()).attr("height") * window.devicePixelRatio;
$(chart.getCanvas()).attr("width", newWidth);
$(chart.getCanvas()).attr("height", newHeight);
chart.setupGrid();
chart.draw();
This in fact changes the canvas' dimensions and they keep that way even after the drawing. On the iPhone 4S it tells me the canvas dimensions are now 600 * 800 (after the drawing), but it still doesn't look crisp.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论