こんにちは私はhtml5キャンバスを使用して株棒グラフを作成しようとすると、まず私はさまざまな方法でバーオブジェクトを作成することに決めましたが、それを動作させることはできません。HTML5キャンバスオブジェクト指向
<!DOCTYPE html>
<html>
<body>
<canvas id="myCanvas" width="1024" height="600" style="border:3px solid #d3d3d3;">
Your browser does not support the HTML5 canvas tag.</canvas>
<script>
var context = document.getElementById("myCanvas").getContext("2d");
function Bar(time,open,high,low,close,dir){
vertcord=time
openC=open
highC=high
lowC=low
closeC=close
line_width=8
bar_col='#ff0000'
if (dir==1){
bar_col='#ace600'
}
this.moveTo(vertcord,highC);
this.lineTo(vertcord,lowC);
this.moveTo(vertcord-line_width/2,closeC);
this.lineTo(vertcord+30,closeC);
this.lineWidth = line_width
this.strokeStyle = bar_col;
this.stroke();
}
for (i=0; i < 300; i++) {
tempShape = new Bar(450+i,0,200,100,150,1);
tempShape.drawToContext(context);
}
</script>
</body>
</html>
コンストラクタ関数で 'this'の代わりにキャンバスの[rendering context](https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D)が必要です。 – Teemu
Bar.drawToContext()は定義されていません。 –
しかし、Barはオブジェクトでなければなりません。他の関数などで後で改善します。 – Riggun