首页 > 解决方案 > D3.JS 读取 CSV 并选择行

问题描述

伙计们,

我尝试加载“cars2017.csv”并读取目标数据,例如行 [1] 列 [发动机气缸]。结果应显示“6”。但似乎我成功加载了 csv 文件,但无法访问选定的数据。那里发生了什么?

<html>
<script src='https://d3js.org/d3.v5.min.js'></script>
<style> circle {fill: lightblue; stroke: black;} </style>
<body >
<svg width=300 height=300>
</svg>
<script>

const csv = d3.csv("https://flunky.github.io/cars2017.csv", function(data,i){
    console.log(csv); //looks good!
    console.log(data[i]); //shows "undefined"
    console.log(data[i].AverageHighwayMPG); //shows "errors"

});


</script>
</body>
</html>

标签: javascriptd3.js

解决方案


推荐阅读