2014-10-21 57 views
1

我需要帮助设置在Google Charts Calendar上使用canvg创建的画布对象的背景颜色。设置从Google Charts创建的透明画布/ png的背景颜色

这是JS Fiddle

下载的图像/ PNG具有透明背景,因为画布具有这种方式。我想改变它,使它不再是透明的,但使用setAttribute像这样white.I尝试:

canvas.setAttribute(
    'style', 
    'position: absolute; ' + 
    'top: ' + (-chartArea.offsetHeight * 2) + 'px; ' + 
    'left: ' + (-chartArea.offsetWidth * 2) + 'px;' + 
    'backgroud-color: #fff;'); 

也使用这种方式:canvas.style.backgroundColor = 'blue';但这些尝试都失败了,我一直没能找到一个好的工作答案。

非常感谢所有帮助。

回答

0

要清楚 - 你想圈蓝色?

http://jsfiddle.net/6y3ym4ov/2/>线4

<circle id="circle" fill="#202020" stroke="#0A0A0A" stroke-width="4"...

更换填充= “#202020” 与无/不同色

fill="#000099"/fill="blue"/fill="rgb(0,0,255)"

+0

我试图将[image/PNG](http://gyazo.com/9be86809a7802c7a04fd26d80a082d71)的背景从透明改为白色。对错误的蓝色抱歉。这是作为一个例子。 – shhasan 2014-10-22 15:42:19

4

尝试:

context = canvas.getContext("2d"); 

// set to draw behind current content 
context.globalCompositeOperation = "destination-over"; 

// set background color 
context.fillStyle = '#fff'; // <- background color 

// draw background/rect on entire canvas 
context.fillRect(0, 0, canvas.width, canvas.height); 

来源:http://blogs.adobe.com/digitalmedia/2011/01/setting-the-background-color-when-generating-images-from-canvas-todataurl/

+0

默认情况下它是白色的折线图,我试图做一个不同的颜色,但它总是回到白色,我之所以要下载带有背景颜色的图表,是因为它总是以透明背景下载。 – 2015-05-26 16:58:36