我使用https://bl.ocks.org/mbostock/3884955中的代码绘制多系列折线图.
线条末端有标签,但如果线条彼此靠近则会有点乱.
是否可以使用d3将图例添加到折线图?我查看了API,但似乎找不到任何东西.
I want to make some functions available to all my arrays.
For instance, I want a function to remove duplicates:
Array.prototype.uniq = function () {
return Array.from(new Set(this));
};
Run Code Online (Sandbox Code Playgroud)
But I want to make this function work in my entire node.js
project.
Will it work if I just put it in server.js
which is run when I type npm start
?
It would be great if it also works on the client. Is it possible or should I consider server …
我有一个阵列['green', 'red', 'yellow', 'blue']
.
我想用这些颜色改变我网站的背景颜色.但我不想从这个数组中随机抽取颜色.我想按顺序迭代它.
因此,如果我得到我的网站的背景颜色getBgColor()
并打印red
,那么我想要一个功能setBgColor(currentColor)
打印yellow
.我该怎么做呢?
我想我应该做点什么
function setBgColor(currentColor) {
var array = ['green', 'red', 'yellow', 'blue'];
newColor = array[array.indexOf(currentColor) + 1];
}
Run Code Online (Sandbox Code Playgroud)
但这是正确的方法吗?我如何确保从蓝色变为绿色,从而不超过阵列的长度?
我有一个对象
usersById: {
1: { name: 'John' },
2: { name: 'Michelle' },
...
}
Run Code Online (Sandbox Code Playgroud)
我想返回相同的对象,但首先使用新属性填充 id=2 处的对象age
,但坚持不变性。
我猜它会是这样的
return {
...usersById,
...usersById[2].age = 40
}
Run Code Online (Sandbox Code Playgroud)
但我收到一个错误In this environment the sources for assign MUST be an object. This error is a performance optimization and not spec compliant
。
或者,我猜它应该是这样的
return Object.keys(usersById).map(userId => {
if (userId === 2) {
return {
...usersById[2],
...age = 40
}
}
return usersById[userId]
})
Run Code Online (Sandbox Code Playgroud)
但它返回一个数组而不是一个对象。
javascript ×4
arrays ×3
d3.js ×1
immutability ×1
legend ×1
linechart ×1
node.js ×1
object ×1
prototypejs ×1
reducers ×1