如何将对象数组中的一个对象提供给 zingchart?



考虑我有一个具有以下结构的对象数组


var dummyArray = [
{diff: "0.000", totalLength: 3},
{diff: "0.001", totalLength: 3},
{diff: "0.002", totalLength: 4},
{diff: "0.003", totalLength: 2},
{diff: "0.004", totalLength: 1},
{diff: "0.005", totalLength: 3},
{diff: "0.012", totalLength: 1},
{diff: "0.016", totalLength: 1},
{diff: "0.023", totalLength: 1},
{diff: "0.044", totalLength: 1},
{diff: "0.111", totalLength: 1},
{diff: "0.156", totalLength: 1}
];

现在我想将差异作为参数提供给以下 zingchart 配置。

"scale-x": {
"values": "1994:2014",
"max-items": 99,
"guide": {
"visible": false
}
},

而不是值"1994:2014" 类似于以下方式

"scale-x": {
"values": dummyArray.diff,
"max-items": 99,
"guide": {
"visible": false
}
},

考虑数据表 API,我们如何直接给出对象(属性(名称。

同样,是否可以直接给出类似上述方式的东西,而无需通过任何数组过滤器操作数据?

提前致谢

分配所有值的唯一方法是将map与如下所示的toString()
一起使用dummyArray.map(x => x.diff).toString();

(工作示例(

const dummyArray = [{diff:"0.000",totalLength:3},{diff:"0.001",totalLength:3},{diff:"0.002",totalLength:4},{diff:"0.003",totalLength:2},{diff:"0.004",totalLength:1},{diff:"0.005",totalLength:3},{diff:"0.012",totalLength:1},{diff:"0.016",totalLength:1},{diff:"0.023",totalLength:1},{diff:"0.044",totalLength:1},{diff:"0.111",totalLength:1},{diff:"0.156",totalLength:1}];
const myObj = {
"values": dummyArray.map(x => x.diff).toString(),
"max-items": 99,
"guide": {
"visible": false
}
}
console.log(myObj);

如果你有带有字符串列表的数组,那么你不需要map,你只需要做toString()

dummyArray = ["0.000","0.001","0.002","0.003","0.004","0.005","0.012","0.016","0.023","0.044","0.111","0.156"];
dummyArray.toString();

相关内容

  • 没有找到相关文章

最新更新