我正在尝试将d3图表与Vue集成。使用ref似乎会出错,但这是正确的方法吗?
<template>
<div ref="chart"></div>
</template>
const chart = ref(null);
onMounted(() => {
const chartContainer = d3.select(chart);
const margin = { top: 20, right: 20, bottom: 30, left: 50 };
const width = chartContainer.offsetWidth - margin.left - margin.right;
const height = chartContainer.offsetHeight - margin.top - margin.bottom;
const svg = chartContainer
.append("svg")
.attr("width", width + margin.left + margin.right)
.attr("height", height + margin.top + margin.bottom)
.append("g")
.attr("transform",`translate(${margin.left},${margin.top})`);
});
我收到此错误:
Uncaught (in promise) TypeError: this.ownerDocument is undefined
1条答案
按热度按时间eh57zj3b1#
尝试d3.select全部,而不是d3.select
如果这不起作用,更多的提示在这里:
https://stackoverflow.com/a/49696538/7549483