Andrew Parhomchuk
Andrew Parhomchuk

Reputation: 3

Can't create svg in d3.js

I wrote a function that returns svg but faced an error (screenshot):

Error in created hook: "TypeError: Cannot read property 'prefix' of undefined"

This is how I add the library :

import * as d3 from 'd3'

markerSvgIcon (options) {
      const svg = document.createElementNS(d3.ns.prefix.svg, 'svg')
      // eslint-disable-next-line no-unused-vars
      const triangle = d3.svg.symbol().type('triangle').size(195)
      // eslint-disable-next-line no-unused-vars
      const svgTri = d3.select(svg)
        .append('path')
        .attr('d', triangle)
        .attr('transform', function (d) { return 'translate(' + 14 + ',' + 31 + ')' })
        .style('fill', '#35c377')
      console.log(svg)
      return svg
    }

Upvotes: 0

Views: 305

Answers (1)

Estus Flask
Estus Flask

Reputation: 222840

As the changelog says, d3.ns has been renamed to d3.namespaces.

It should be:

const svg = document.createElementNS(d3.namespaces.svg, 'svg')

Upvotes: 2

Related Questions