Changing stroke shape for different datasets

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
evan
Posts: 14
Joined: Thu Feb 08, 2007 6:26 pm

Changing stroke shape for different datasets

Post by evan » Wed Feb 14, 2007 3:58 am

Hi.

I've tried different ways to do this, but it just doesn't seem to be working for me. Here is what I've done:

Code: Select all

chart.getXYPlot().getRenderer().setStroke(new BasicStroke(0.0f, BasicStroke.CAP_ROUND, 
						   							  		      BasicStroke.JOIN_ROUND,
						   							  			  1.0f, new float[] {2.0f, 6.0f}, 0.0f));
		chart.getXYPlot().getRenderer().setBaseStroke(new BasicStroke(0.0f, BasicStroke.CAP_ROUND, 
				  		      BasicStroke.JOIN_ROUND,
				  			  1.0f, new float[] {2.0f, 6.0f}, 0.0f));
		chart.getXYPlot().getRenderer().setSeriesStroke(0, new BasicStroke(0.0f, BasicStroke.CAP_ROUND, 
				  		      BasicStroke.JOIN_ROUND,
				  			  1.0f, new float[] {2.0f, 6.0f}, 0.0f));
So basically, I end up with having this new Stroke everywhere (i.e. as stroke, baseStroke, first element of the strokeList) in the render, but when it draws, I still keep getting the standard square shape regardless.

Any ideas why this happens? Thanks.

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 » Wed Feb 14, 2007 11:28 am

Only the setStroke(...) call in your code will have any effect, because it sets an override so that the other settings are ignored. Try changing the stroke width from 0.0f to 5.0f, just to see that the stroke is, in fact, being used.

I wonder if you will even see the CAP_ROUND effect with a very thin stroke?
David Gilbert
JFreeChart Project Leader

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

evan
Posts: 14
Joined: Thu Feb 08, 2007 6:26 pm

Post by evan » Wed Feb 14, 2007 2:49 pm

I've tried many different values of the parameters of the stroke, but I cannot see any changes (e.g. stroke shape, size, etc). Any other possibilities that could cause this problem?

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 » Wed Feb 14, 2007 2:57 pm

evan wrote:I've tried many different values of the parameters of the stroke, but I cannot see any changes (e.g. stroke shape, size, etc). Any other possibilities that could cause this problem?
Have you eliminated silly errors? For example, are you sure that the 'chart' you are modifying is the same one you are looking at in the output? If you post a small self-contained demo that reproduces the problem, then I'll have a much better chance of tracking it down.
David Gilbert
JFreeChart Project Leader

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

evan
Posts: 14
Joined: Thu Feb 08, 2007 6:26 pm

Post by evan » Fri Feb 16, 2007 10:34 pm

Here's some code I'm using:

Code: Select all

private FastXYPlot getFastPlot ()
	{
		// setting up x and y axes
		NumberAxis domainAxis = new NumberAxis("T");
        domainAxis.setAutoRange(true);
        domainAxis.setAutoRangeIncludesZero(true);
        NumberAxis rangeAxis = new NumberAxis(ResultData.getYAxisName(dataType));
        rangeAxis.setAutoRange(true);
        rangeAxis.setAutoRangeIncludesZero(true);
		
        XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(false, true);
        renderer.setStroke(new BasicStroke(5.0f, BasicStroke.CAP_ROUND, 
                        BasicStroke.JOIN_ROUND, 
                       1.0f, new float[] {2.0f, 6.0f}, 0.0f));
        
		FastXYPlot plot = new FastXYPlot(sets[0], domainAxis, rangeAxis, new XYLineAndShapeRenderer(false, true));

		return plot;
	}
I call this method to get the plot, and then create my chart:

Code: Select all

// create the chart
		plot = getFastPlot();
		JFreeChart chart = new JFreeChart(ResultData.getChartName(dataType), plot);
These are the relavant code, I think. It might be worth to point out that I'm using a modified plot. Many thanks.

skunk
Posts: 1087
Joined: Thu Jun 02, 2005 10:14 pm
Location: Brisbane, Australia

Post by skunk » Fri Feb 16, 2007 11:31 pm

Perhaps your FastXYPlot has some optimizations that assume that all datasets use the same rendering attributes in order to be "fast"?

evan
Posts: 14
Joined: Thu Feb 08, 2007 6:26 pm

Post by evan » Sat Feb 17, 2007 5:23 pm

yea, that seems to be the problem. thanks skunk.

Locked