Discuss / JavaScript / 关键看坐标转换

关键看坐标转换

Topic source

LevonLin

#1 Created at ... [Delete] [Delete and Lock User]

以5000点作最大值,适用性有点低:

    ctx.clearRect(0, 0, width, height);
    var space =20;
    for(var i=0; i<data.length; i++) {
        ctx.beginPath();
        ctx.moveTo(space+2,(5000-data[i].high)/10);
        ctx.lineTo(space+2,(5000-data[i].low)/10);
        if(data[i].close-data[i].open>0) {
            ctx.fillStyle='#f00';
            ctx.strokeStyle='#f00';
            ctx.fillRect(space,(5000-data[i].close)/10,4,(data[i].close-data[i].open)/10); 
        }
        else if(data[i].close-data[i].open<0) {
            ctx.fillStyle='#0f0';
            ctx.strokeStyle='#0f0';
            ctx.fillRect(space,(5000-data[i].open)/10,4,(data[i].open-data[i].close)/10); 
        }
        ctx.stroke();
        space+=8;
    }

  • 1

Reply