Dashed line

A discussion forum for FXGraphics2D (adds a Java2D API to the JavaFX Canvas).
Post Reply
Posts: 1
Joined: Mon Jul 06, 2015 8:50 am
antibot: No, of course not.

Dashed line

Post by SophieL » Mon Jul 06, 2015 9:51 am

I test to draw a value marker on dashed line on XYPlot under JavaFX.

Since Java 8u40, the org.jfree.chart.fx.FXGraphics2D managed the dashed lines.
So I modified the bridge fx on FXGraphics2D.java

Code: Select all

    public void setStroke(Stroke s) {
        nullNotPermitted(s, "s");
        this.stroke = s;
        if (stroke instanceof BasicStroke) {
            BasicStroke bs = (BasicStroke) s;
            double lineWidth = bs.getLineWidth();
            if (lineWidth == 0.0) {
                lineWidth = this.zeroStrokeWidth;
            //Dasehd lines management
            float[] dash = bs.getDashArray();
            if (dash != null && dash.length > 1){
            	for (int i=0; i<dash.length; i++){
            	double[] actualDash = this.gc.getLineDashes();
            	if (actualDash != null){
            		for (int i=0; i<actualDash.length; i++){
Notice that the dashed line is the default behavior for grid lines of XYPlot.

Thanks again for your work.

Best regards,

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

Re: Dashed line

Post by david.gilbert » Sat Jul 25, 2015 9:44 am

Thanks Sophie. Previously I updated the code to use reflection so that dashed lines would work in 8u40 upwards but code would still run in earlier releases of JavaFX. You can see the code here:

https://github.com/jfree/fxgraphics2d/b ... ics2D.java

I guess by now, though, most people using JavaFX will be on 8u51, so perhaps I can remove the use of reflection and support dashed lines directly.
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Ask your company to buy the JFreeChart Developer Guide
:idea: Check out other products sold by my company Object Refinery Limited

Post Reply