I've been developing a spike graph using JavaScript and HTML5's canvas
element.
To accomplish what I'm going after though, I need to layer upwards of 3 canvas
elements on top of each other (using position: absolute
).
However, despite there being no opacity
property on the canvas
' - nor am I filling the rectangles with Alpha colors, the 1st layer canvas
(light grey) always manages to affect the layer colors above it.
I have used straight red (#ff0000
) on the red layer, but notice how it is affected by both the blue layer (blue is also affected), and the grey layer:
Relevant code:
function drawCanvas(ctx, samples, color){
for(var i = 0; i < samples.length; i++){
ctx.beginPath();
ctx.fillStyle = color;
ctx.rect(i + (i * 2), 60 - samples[i], 2, samples[i]);
ctx.fill();
}
}
var samples = [121,105,107,125,94,96,121];
// grey layer
drawCanvas(canvasA.getContext("2d"), samples, "#313131");
// blue layer
drawCanvas(canvasB.getContext("2d"), samples, "blue");
// red layer
drawCanvas(canvasC.getContext("2d"), samples, "red");
JsFiddle: https://jsfiddle.net/yk2hjuk5/8/
Can't wrap my head around why this might be occurring, and I'm pretty new to using the canvas
element - so all help is appreciated.
Cheers.