P Kero
P Kero

Reputation: 77

Drawing an SVG Raphael path gives error and doesn't accept variables

I'm trying to make a simple X axis for a chart using Raphael SVG path, but the variables for M(moveto) and L(lineto) aren't getting accepted.

var x1 = x,
    y1 = y+height,
    x2 = x+width,
    y2 = y+height;
var xAxis = SVGpaper.path("Mx1,y1 Lx2,y2").attr({stroke: "config.axisColor", "stroke-width": 1});

It gives the error:

Error: Problem parsing d="M,0,0"

Am I making some error in declaring the variables or in the syntax for path? I can't find any code to refer to, so please advice some tips!

Upvotes: 0

Views: 1426

Answers (1)

Robert Longson
Robert Longson

Reputation: 123995

You're just passing the string "Mx1,y1 Lx2,y2" i.e with the variable names rather than their values.

You want this...

SVGpaper.path("M" + x1 + "," + y1 + " L" + x2 + "," + y2).attr({stroke: "config.axisColor", "stroke-width": 1});

Upvotes: 1

Related Questions