<!DOCTYPE html>
<html>
<head>
<script src="http://d3js.org/d3.v4.min.js"></script>
</head>
<body>
<div id="grid"></div>
<script>
//create 1670 numbers of matrices with size of 180*90
var myMatrix = new Array(1670)
for (var i=0; i<1670; i++){
myMatrix[i] = twodmatrix()
}
function twodmatrix(){
var myMat = new Array(180)
for (var i=0; i<180; i++){
myMat[i] = new Array(90)
}
return(myMat)
}
const NUM_COLOR = 16200;
var colorArr = new Array(NUM_COLOR);
for (var i = 0; i < NUM_COLOR; i++) {
colorArr[i] = getColor();
}
d3.text("tempanomaly_new.txt", function(data){ myMatrix = data })
function getColor() {
color = "#"+[Math.floor(myMatrix)].toString(16);
// Math.values is not a function, myMatrix is empty array cause of missing file
return color;
}
const BLOCK_SIZE = 30;
const BLOCK_SPACE = 5;
var gridData = new Array(180)
for (var i = 0; i < 180; i++) {
gridData[i] = new Array(90)
for (var j = 0; j < 90; j++) {
gridData[i][j] = {
x: (i + 1) * BLOCK_SIZE + BLOCK_SPACE,
y: (j + 1) * BLOCK_SIZE + BLOCK_SPACE,
size: BLOCK_SIZE,
color: colorArr[(i * 10 + j) % NUM_COLOR]
}
}
}
var grid = d3.select("#grid")
.append("svg")
.attr("width", "5500px")
.attr("height", "3000px")
.style("color", "#b2b2b2");
var row = grid.selectAll(".row")
.data(gridData)
.enter().append("g")
.attr("class", "row");
var column = row.selectAll(".square")
.data(function(data) {
return data;
})
.enter()
.append("rect")
.attr("class", "square")
.attr("x", function(data) {
return data.x;
})
.attr("y", function(data) {
return data.y;
})
.attr("width", function(data) {
return data.size;
})
.attr("height", function(data) {
return data.size;
})
.style("fill", function(data) {
return data.color;
})
.style("stroke", "#222");
</script>
</body>
</html>
- Math.values не является функцией.
- d3.text (файл, функция (данные) {myMatrix = data;},ты уверен, что он работает?