您的位置:首页 > Web前端 > JavaScript

【D3.js数据可视化系列教程】--(九)D3的数据类型

2013-09-08 10:06 786 查看

1 变量

JAVASCRIPT的变量是一种类型宽松的语言。定义变量不用指定数据类型。而且还是动态可变的。
var value = 100;
value = 99.9999;
value = false;
value = "hello world!";

2 数组

从0开始
var percentages = [ 0.55, 0.32, 0.91 ];
var names = [ "a", "b", "c" ];
percentages[1]  //返回 0.32
names[1]        //返回 "b"

3 对象

var people = {
name: "tianxuzhang",
birthday: "1992-06-01",
sex: "male",
hobby: "d3"
};

people.name      //返回 "tianxuzhang"
people.birthday     //返回 "1992-06-01"
people.sex  //返回 male
people.hobby     //返回 d3

4 对象数组

var fruits = [
{
kind: "grape",
color: "red",
quantity: 12,
tasty: true
},
{
kind: "kiwi",
color: "brown",
quantity: 98,
tasty: true
},
{
kind: "banana",
color: "yellow",
quantity: 0,
tasty: true
}
];
fruits[0].kind      ==  "grape"
fruits[0].color     ==  "red"
fruits[0].quantity  ==  12
fruits[0].tasty     ==  true
fruits[1].kind      ==  "kiwi"
fruits[1].color     ==  "brown"
fruits[1].quantity  ==  98
fruits[1].tasty     ==  true
fruits[2].kind      ==  "banana"
fruits[2].color     ==  "yellow"
fruits[2].quantity  ==  0
fruits[2].tasty     ==  true

5 JSON

JSON是Javascript对象。常用于AJAX数据请求。它的速度更快,比XML更容易解析
var jsonFruit = {
"kind": "grape",
"color": "red",
"quantity": 12,
"tasty": true
};

6 GeoJSON

GeoJSON是可以存储地理空间(通常为经度/纬度坐标)点,形状(如线和多边形)和其他空间的Feature。
var geodata = {
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [ 150.1282427, -24.471803 ]
},
"properties": {
"type": "town"
}
}
]
};
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息