实验目的:
- 掌握d3.min.js的读入文件的方法
- 掌握echarts的可视化的流程
实验原理:
对鸢尾花的长宽按照要求处理
引入d3.min.js文件
完整的代码:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>鸢尾花数据可视化</title>
<script src="echarts/echarts.min.js"></script>#配置路径下echarts.min.js
<script src="echarts/d3.min.js"></script>
</head>
<body>
<div id="main" style="width: 800px;height:600px;"></div>
<script>
var chartDom = document.getElementById("main");
var myChart = echarts.init(chartDom);
d3.csv("Data/iris.csv",function(error,data){
//console.log(data);
var setosa = [];
var versicolor = [];
var virginica = [];
var petal_length = [];
for (var i=0;i<data.length;i++){
petal_length.push(parseFloat(data[i].PetalLength));
if(i<50){
setosa[i]=[parseFloat(data[i].PetalLength),parseFloat(data[i].PetalWidth)];
}
else if (i>=100){
virginica[i-100] = [parseFloat(data[i].PetalLength),parseFloat(data[i].PetalWidth)];
//virginica[i]=[parseFloat(data[i].PetalLength),parseFloat(data[i].PetalWidth)];
}
else{
versicolor[i-50] = [parseFloat(data[i].PetalLength),parseFloat(data[i].PetalWidth)];
}
}
console.log(setosa);
console.log(versicolor);
co