2 Attachment(s)
Graphics Quality - Interconnecting Line Segments ???
Consider the attached image LINE1.jpg. You'll notice it has a diagonal line in the middle of the screen. The chart actually display's commodity prices but that is NOT what were talking about.
My "main" program was originally developed in C# and I'm transferring it into JAVA. The original algorithm was designed to draw one line segment per candle. So the resulting line on the attached image is actually many interconnected line segments.
You'll also notice however that the line appears jagged and un-smooth. I'm using:
g2.setRenderingHint(
RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
in my code but does not correct the problem. Continuing my research I'm also looking into the BasicStroke and line cap but that too does not correct the problem.
LINE2.jpg shows what I want. Lines drawn that are 100% smooth. This was accomplished in JAVA but is actually one line and not many line segments that are interconnected as in LINE1.jpg
My Question ...
How can I make interconnected lines draw 100% smooth ???
Re: Graphics Quality - Interconnecting Line Segments ???
I'm going to respond to my own post. I just modified my code so that it looks for the first and line segment only and connects the two. Here's my code:
x = screen_left;
// find right starting point
for (int i = 0; i < bars_per_window - bars_removed - 1; i++)
{
x += bar_width;
}
float left_x = Float.MAX_VALUE;
float left_price = 0;
float right_x = Float.MIN_VALUE;
float right_price = 0;
// draw candles
for (int i = jScrollBar.getValue(); i >= 0; i--)
{
for (int i2 = 0; i2 < indicator.trendline.values.size(); i2++)
{
Indicator.Value value = (Indicator.Value)indicator.trendline.values.get(i2 );
if (value.id == i)
{
float p1 = (float)price_to_screen(value.value, min_price, max_price, screen_top, screen_height);
float p2 = (float)price_to_screen(value.value + indicator.trendline.inc, min_price, max_price, screen_top, screen_height);
if (x < left_x)
{
left_x = x;
left_price = p1;
}
if (x > right_x)
{
right_x = x;
right_price = p2;
}
break;
}
}
x -= bar_width;
if (Math.ceil(x) < screen_left) break;
}
g2.draw(new Line2D.Float(left_x, left_price, right_x, right_price));