I've installed the d3 dependency in the project directory like this:
npm install d3 --save
and I've imported the d3 module in the Component like this:
import d3 from "d3";
which shows no errors or warnings to me. Unfortunately, calling any method from the d3 module fails.
For example, I tried to draw this line chart and an error appeared at the very first select method from the module.
Uncaught (in promise) TypeError: Cannot read property 'select' of undefined.
How could this be? Hovering on every single method of the d3 module in VS Code shows me the documentation of the method. So I guess the module can't be undefined.
<script>
import d3 from 'd3';
const data = [99, 71, 78, 25, 36, 92];
export default {
name: 'non-vue-line-chart',
template: '<div></div>',
mounted() {
const svg = d3.select(this.$el) // the error appears on the very first line of the d3-module
.append('svg')
.attr('width', 500)
.attr('height', 270)
.append('g')
.attr('transform', 'translate(0, 10)');
const x = d3.scaleLinear().range([0, 430]);
const y = d3.scaleLinear().range([210, 0]);
d3.axisLeft().scale(x);
d3.axisTop().scale(y);
x.domain(d3.extent(data, (d, i) => i));
y.domain([0, d3.max(data, d => d)]);
const createPath = d3.line()
.x((d, i) => x(i))
.y(d => y(d));
svg.append('path').attr('d', createPath(data));
},
};
</script>
There must be some integration mismatch, that I can't fix it by myself. Please help.