Problem with dashed/dotted lines

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
Mottfried
Posts: 14
Joined: Mon Jul 24, 2006 10:51 am

Problem with dashed/dotted lines

Post by Mottfried » Wed Aug 16, 2006 12:24 pm

Hi there !

I have an XYPlot on which i want some dotted and some dashed lines.

As basic example i used http://www.jfree.org/phpBB2/viewtopic.p ... yle+dotted
The point in this example is :

Code: Select all

float lineWidth = 0.2f;
float dash[] = {5.0f};
float dot[] = {lineWidth};
   
            if (style.equalsIgnoreCase(STYLE_LINE)) {
                result = new BasicStroke(lineWidth);
            } else if (style.equalsIgnoreCase(STYLE_DASH)) {
                result = new BasicStroke(lineWidth, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f, dash, 0.0f);
            } else if (style.equalsIgnoreCase(STYLE_DOT)) {
                result = new BasicStroke(lineWidth, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 2.0f, dot, 0.0f);
            } 
my implementation uses :

Code: Select all

float miterlimit = 1.0f;
float dash[] = {10.0f};
float dot[] = {1.0f};
float dash_phase = 0.0f;
render.setSeriesStroke(ls.series, new BasicStroke(8, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, miterlimit, dash, dash_phase));
But i've tried to dash the lines with all parameters as explained here http://www.oreilly.com/catalog/java2d/c ... html#39742 and the lines wont be dashed or dotted or something else. Its just a plain line.

Anybody an idea ?
Thank you !

Mottfried
Posts: 14
Joined: Mon Jul 24, 2006 10:51 am

Post by Mottfried » Fri Aug 18, 2006 7:59 am

No help ? :cry:

david.gilbert
JFreeChart Project Leader
Posts: 11734
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Post by david.gilbert » Fri Aug 18, 2006 8:40 am

If you have a lot of data points, then the following might help:

Code: Select all

renderer.setDrawSeriesLineAsPath(true);
This assumes you are using XYLineAndShapeRenderer.

If it is not that, then check that 'render' in your code really does reference the renderer being used by your chart (perhaps it is a renderer that you created but never assigned to the chart).
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Support JFree via the Github sponsorship program

Mottfried
Posts: 14
Joined: Mon Jul 24, 2006 10:51 am

Post by Mottfried » Thu Aug 24, 2006 8:46 am

Thank you.

The mistake was that I used the XYItemRenderer :) Now everything is fine.

Mottfried
Posts: 14
Joined: Mon Jul 24, 2006 10:51 am

Post by Mottfried » Thu Aug 24, 2006 10:24 am

Found something else :shock:

I can dash or dot my lines - wonderful. But if i add a second axis, and to that second axis a dataset with some series - the stroke-style, line-colour, line-thickness are always the same like the corresponding index of the first dataset.

As example 2 axis, 2 datasets, 2 styles and the same index :

Code: Select all

c.graph[0].setLineStyle(0, 1.5f, Color.black, LineStyle.LINE_DOTTED);
c.graph[1].setLineStyle(0, 1.2f, Color.blue, LineStyle.LINE_NORMAL);
The line-style of axis 0 is overwritten by the line-style of axis 1.
Those classes only wrap the specialties of jFreeChart, so it might be an jFreeChart-problem. If u need i can email the whole code - but i think thats not necessary.

As ever - thanks for the competent help !

suwandy
Posts: 1
Joined: Tue Feb 13, 2007 12:55 am

Post by suwandy » Tue Feb 13, 2007 1:01 am

Hi,

sorry for using this thread. But I thought I should try to keep my posts relevant to the topic. Here goes anyway.
I'm using a LineAndShapeRenderer class to draw my line. here is the code I'm using

Code: Select all

        float dash[] = {5.0f}; 
        renderer2.setSeriesStroke(
            0, new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f, dash, 1.0f
            )
        );
But somehow it wouldn't show any dashed line. I have made sure I set the renderer to be drawn. I only have 2 points in the line. Is that a problem? If not, what is the actual problem?

mickish
Posts: 29
Joined: Tue Jan 08, 2008 11:15 pm
Location: Venice, Florida

Post by mickish » Wed Jan 09, 2008 4:40 pm

david.gilbert wrote:If you have a lot of data points, then the following might help:

Code: Select all

renderer.setDrawSeriesLineAsPath(true);
Thanks! That was exactly what I needed.

Locked