2015-08-17 57 views
-1

我想画一些使用JavaScript和画布的小图表。我的画布画像素线

我正在做一个类似的东西:

RadarChart.prototype.fillRadar = function() { 
var nbLabel = this.data.labels.length; 
this.context.save(); 
this.context.lineWidth = 0.5; 
this.context.lineJoin = "round"; 
this.context.translate(this.canvas.width/2, this.canvas.height/2); 
this.context.strokeStyle = this.data.lineColor; 
for (var i = 0; i < nbLabel; i++) { 
    this.context.moveTo(0, 0); 
    this.context.lineTo(0, -((this.canvas.height/2) - 30)) 
    this.context.stroke(); 
    this.context.rotate((Math.PI/180) * (360/nbLabel)); 
} 
this.context.restore(); 
} 

的问题是,我的台词是这样的像素化和不完美。它们的宽度似乎改变了。这就像它随着时间的推移淡出......

http://i.imgur.com/MVhHEru.png

为什么这样做?我该如何解决它?

感谢您的帮助。

+0

为什么你使用'rotate'方法?为什么不直接计算所有终点并画线(光线)? – hindmost

+0

如果在任何位图图像上放大4倍,则它将变为像素化。画布不是SVG。 – ericjbasti

+0

@ericjbasti我没有放大。我在100%,我只是画线。 – Bobby

回答

3

不要使用CSS

使用 canvas.width = 500; canvas.height = 500;

未设置画布的宽度/高度作出这样的发现功能屏幕20%的像素多少钱的,然后设置宽度/代码中的高度。