The Artima Developer Community
Sponsored Link

Java Answers Forum
Possible with two-colored line in a diagram??

2 replies on 1 page. Most recent reply: Apr 3, 2003 12:37 AM by Kristin

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 2 replies on 1 page
Kristin

Posts: 6
Nickname: kristin
Registered: Feb, 2003

Possible with two-colored line in a diagram?? Posted: Mar 28, 2003 6:02 AM
Reply to this message Reply
Advertisement
I would like to have a line in a diagram in two different colors. If the line is drawn before a specific x-value it should be in one color and a different color after that x-value. Is this possible?
I have my x-values in one vector and my y-values in another vector. HELP!!


Rich Burgis

Posts: 17
Nickname: songbird
Registered: Mar, 2003

Re: Possible with two-colored line in a diagram?? Posted: Mar 30, 2003 7:08 PM
Reply to this message Reply
Sure. For example suppose that you want your line to be red to the left of the line x = 100 and green to the right.

Say further that the two points you want to connect are (75, 60 ) and (150, 35 ).

You'll need to draw two segments one ending at when x = 100 and the next going on to x = 150.

To do that you need to know the point where the color changes. You do that with the equation for a line

(y - y1) / ( x - x1) = slope

the slope of the line in question is (35 - 60)/( 150 -75) or -25/75 or -1/3. So the equation you need is (using the first point for x1 and y1)

( y - 60)/( x - 75) = -1/3. To get the point where the color changes set x = 100 or

(y-60)/(100-75) = 1/3 or

y-60 = -25/3 or y =60 - 25/3 = 51 and 2/3. (You should round the result since pixel positions are integers )

So your code in this case is

g.setColor( Color.red).
g.drawLine( 75, 60, 100, 52 );
g.setColor( Color.green );
g.drawLine( 100, 52, 150, 35 );

Kristin

Posts: 6
Nickname: kristin
Registered: Feb, 2003

Re: Possible with two-colored line in a diagram?? Posted: Apr 3, 2003 12:37 AM
Reply to this message Reply
Many thanks for your help Rich! I hope I can use your reply in some way.
Unfortunately have my problem got bigger because the code I?m working on have been using chartDataWiews, JCAxis and stuff. All this have complicated my work more. I?m now trying to learn more about this before I continue. I?m not sure with which command the lines are drawn with this "method". Does anyone know?

Flat View: This topic has 2 replies on 1 page
Topic: Serizaling with the data base instead os the MySql ResultSet Previous Topic   Next Topic Topic: detect client server class mis-use at compile time

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use