javascript - d3.js 对象没有完全显示卡片
问题描述
我是 d3 的新手,目前正在学习 FreeCodeCamp 的教程。
本质上,我想将一些圆圈渲染到引导卡中,但是它似乎从左侧的卡片上脱落,并且在右侧也被切断。
import { Component } from "react";
import "./App.css";
import * as d3 from "d3";
class Process extends Component {
constructor(props) {
super(props);
this.createProcess = this.createProcess.bind(this);
}
componentDidMount() {
this.createProcess();
this.drawProcess();
}
componentDidUpdate() {
this.drawProcess();
}
drawProcess() {
const width = +this.svg.attr("width");
const height = +this.svg.attr("height");
const makeFruit = test => {
return test;
};
const fruits = d3.range(10).map(() => makeFruit("apple"));
this.svg
.selectAll("circle")
.data(fruits)
.enter()
.append("circle")
.attr("cx", (d, i) => i * 120 + 60)
.attr("fill", "orange")
.attr("cy", height / 2)
.attr("r", 50);
fruits.pop();
this.svg
.selectAll("circle")
.data("fruits")
.exit()
.remove();
}
createProcess() {
this.svg = d3
.selectAll("#flowView")
.append("svg")
.attr("width", "100%");
}
render() {
return null;
}
}
export default Process;
解决方案
你只需要translate
圈子。将此行添加到circles
.
.attr("transform", "translate(0,75)")
这将向下平移圆圈75px
。
this.svg
.selectAll("circle")
.data(fruits)
.enter()
.append("circle")
.attr("cx", (d, i) => i * 120 + 60)
.attr("fill", "orange")
.attr("cy", height / 2)
.attr("r", 50)
.attr("transform", "translate(0,75)");
推荐阅读
- c# - 状态码:415,原因短语:“不支持的媒体类型”
- typescript - PhpStorm 无法解析 @ionic/angular
- c# - ASP.NET,LoginDataContext 不包含配置文件的定义
- mocha.js - 有没有办法为 mocha 中的成功测试添加信息
- reactjs - 如何更改必填 * 字段中的星号颜色
- hadoop - 将 yarn 别名为 yarnpkg 以避免与 Hadoop Yarn 冲突
- c - Qt 多线程应用程序冻结,多个线程等待同一个互斥锁
- jquery - Jquery UI 可排序和可调整大小的 Div
- python - 迭代数据框时修改行值的值
- javascript - 在页面对象方法中共享断言