Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-12-2011, 11:36 PM   PM User | #1
Ing
New Coder

 
Join Date: Feb 2011
Location: Los Angeles
Posts: 13
Thanks: 10
Thanked 0 Times in 0 Posts
Ing is an unknown quantity at this point
Multiple layers with the Canvas tag

Hi. I'm writing a script that graphs data in different colors and shapes and I'm encountering two problems:

(1) I can't specify different colors for the graph I'm rendering. If I use fillStyle="red"; then the entire chart becomes red. It seems to use the last color specified as the color for everything on the chart.

(2) The shapes are overlapping in strange ways. The fills are not covering the lines of shapes behind them so it's unclear which shape is in front and which is behind. It's like they aren't being treated as separate shapes but instead one shape where boundaries are unclear. I don't know how else to explain it.

I'm hoping there is some way to put each shape in its own layer. Would I have to use DIV IDs for that or is there a way to keep it all in the script so it's more scalable?

Last edited by Ing; 02-13-2011 at 11:33 PM.. Reason: resolved
Ing is offline   Reply With Quote
Old 02-13-2011, 11:02 PM   PM User | #2
rnd me
Senior Coder

 
rnd me's Avatar
 
Join Date: Jun 2007
Location: Urbana
Posts: 3,553
Thanks: 9
Thanked 480 Times in 463 Posts
rnd me is a jewel in the roughrnd me is a jewel in the roughrnd me is a jewel in the roughrnd me is a jewel in the rough
are you using context.beginPath() to reset the shape drawing?
checkout https://developer.mozilla.org/en/dra...cs_with_canvas for example of drawing overlapping shapes.
__________________
my site (updated 5/13)
STATS (2013/5) HTML5:90.2% MOB:15.2% IE7:0.5% IE8:8.4% IE9:8.5% IE10:8.5%
rnd me is offline   Reply With Quote
Users who have thanked rnd me for this post:
Ing (02-13-2011)
Old 02-13-2011, 11:32 PM   PM User | #3
Ing
New Coder

 
Join Date: Feb 2011
Location: Los Angeles
Posts: 13
Thanks: 10
Thanked 0 Times in 0 Posts
Ing is an unknown quantity at this point
Quote:
Originally Posted by rnd me View Post
are you using context.beginPath() to reset the shape drawing?
No, I hadn't been. That was the problem causing the overlapping lines!
Lesson learned: always use cxt.beginPath(); and cxt.closePath();

And the issue with the multiple colors was just a syntax issue - I had forgotten to use quotations around the color names in my array.

Thank you.
Ing is offline   Reply With Quote
Reply

Bookmarks

Tags
canvas, div, div id, html5, layers

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 07:56 AM.


Advertisement
Log in to turn off these ads.