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

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"
            }
        }
    ]
};

  • 8
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值