JS 中[] 与{}的区别:
1.[]表示为数组;如,a=[1,2,3,4];
2.{}表示为对象:如,aObject = {};
以echart的option为例:
option = {//对象
//backgroundColor:'rgba(25,25,25,25)',//一定要加引号
/*
color://数组
[
'#ff7f50','#87cefa', '#da70d6', '#32cd32', '#6495ed',
'#ff69b4', '#ba55d3', '#cd5c5c', '#ffa500', '#40e0d0',
'#1e90ff', '#ff6347', '#7b68ee', '#00fa9a', '#ffd700',
'#6b8e23', '#ff00ff', '#3cb371', '#b8860b', '#30e0e0'
]
,*/
//animation: true,
title : {
text: '某站点用户访问来源',
subtext: '纯属虚构',
x:'center',//text与subtext位置
y:'top',//text与subtext位置
textAlign:'center',//text与subtext对齐方式
//backgroundColor:'rgba(25,25,25,25)',
//borderColor:'#ccc',
//borderWidth:1,//不用写px
//padding:20,
//itemGap:50//text与subtext上下距离
textStyle:{
}
},
tooltip : {
trigger: 'item',
formatter: "{a} <br/>{b} : {c} ({d}%)"
},
legend: {
orient : 'vertical',
x : 'left',
data:['直接访问','邮件营销','联盟广告','视频广告','搜索引擎']
},
toolbox: {
show : true,
feature : {
mark : {show: true},
dataView : {show: true, readOnly: false},
restore : {show: true},
saveAsImage : {show: true}
}
},
calculable : true,
series : [
{
name:'访问来源',
type:'pie',
radius : '55%',
center: ['50%', '60%'],
data:[
{value:335, name:'直接访问'},
{value:310, name:'邮件营销'},
{value:234, name:'联盟广告'},
{value:135, name:'视频广告'},
{value:1548, name:'搜索引擎'}
]
}
]
};
myChart.setOption(option);
附:参考w3cschool
1.JS中数组定义
var a = new Array(); 与 var a = [];是一样的
2.JS中实例化对象
person=new Object(); person.firstname="Bill"; person.lastname="Gates"; person.age=56; person.eyecolor="blue";
还可用函数构造对象,对象里有变量、函数等,写法如
function person(firstname, lastname, age, eyecolor){
this.firstname = firstname;
this.lastname = lastname;
this.age = age;
this.eyecolor = eyecolor;
//方法或函数
//写法一
person.prototype.changename = function(name){
this.lastname = name;
}
//写法二
this.changename = changename;
function changename(name){
this.lastname = name
}
//写法三
this.changename = function(name){
this.lastname = name;
}
}
调用changename方法
myMother=new person("Steve","Jobs",56,"green");
myMother.changeName("Ballmeraaaaa");
document.write(myMother.lastname);