DataV.js is a JavaScript library for data visualization
DataV全局命名空间对象定义
| 函数 | DataV() | DataV | |
| 代码 | |
||
版本号
| 属性 | DataV.version | DataV | version |
| 代码 | |
||
全局主题对象
| 属性 | DataV.Themes | DataV | Themes |
| 代码 | |
||
获取当前主题的属性
| 方法 | DataV.Themes.get() | DataV.Themes | get |
| 返回 | Mix | 返回当前主题的属性值 | |
| 代码 | |
||
添加自定义主题
| 方法 | DataV.Themes.add() | DataV.Themes | add |
| 参数 | themeName(String) | 主题名称 | |
| 参数 | theme(Object) | 主题对象json, contain attribute "COLOR_ARGS", theme.COLOR_ARGS is a 2-d array; | |
| 代码 | |
||
切换当前主题
| 方法 | DataV.changeTheme() | DataV | changeTheme |
| 参数 | themeName(String) | 主题名称 | |
| 返回 | Boolean | 返回是否切换成功 | |
| 代码 | |
||
获取当前主题的颜色配置
| 方法 | DataV.getColor() | DataV | getColor |
| 返回 | Array | 颜色参数列表 | |
| 代码 | |
||
根据当前主题的颜色配置方案,获取生成离散颜色的函数
| 方法 | DataV.getDiscreteColor() | DataV | getDiscreteColor |
| 返回 | Function | 离散函数 | |
| 代码 | |
||
获取渐变颜色,用于生成渐变效果
| 方法 | DataV.gradientColor() | DataV | gradientColor |
| 参数 | color(Array) | 颜色数组 | |
| 参数 | method(String) | 生成渐变色的方法,默认值为normal。如果为normal将采用D3的interpolateRgb算法,如果为special,则用Rapheal的HSB算法 | |
| 返回 | Function | 返回生成算法 | |
| 代码 | |
||
请求一个JSON文件
| 属性 | DataV.json | DataV | json |
| 参数 | url(String) | JSON文件地址 | |
| 参数 | callback(Function) | 回调函数 | |
| 代码 | |
||
请求一个CSV文件,并解析
| 参数 | url(String) | CSV文件地址 | |
| 参数 | callback(Function) | 回调函数,得到解析后的结果 | |
| 代码 | |
||
侦测数据,检测是二维表(带表头否),还是JSON对象数组
| 方法 | DataV.detect() | DataV | detect |
| 参数 | input(Array) | 输入的数组对象,元素可能为数组,也可能是对象 | |
| 代码 | |
||
将一个对象集合转化为二维表格,第一行为key,后续为每个对象的数据
[
{"username": "JacksonTian", "nick": "朴灵", "hometown": "Chongqing"},
{"username": "Fengmk2", "nick": "苏千", "hometown": "Guangzhou"}
];
=>
[
["username", "nick", "hometown"],
["JacksonTian", "朴灵", "Chongqing"],
["Fengmk2", "苏千", "Guangzhou"]
]
| 方法 | DataV.tablify() | DataV | tablify |
| 参数 | list(Array) | 待转化的二维表集合 | |
| 代码 | |
||
tablify的反向工程,如果不传入head,那么第一行取出作为key,后续当作数据
[
["username", "nick", "hometown"],
["JacksonTian", "朴灵", "Chongqing"],
["Fengmk2", "苏千", "Guangzhou"]
]
=>
[
{"username": "JacksonTian", "nick": "朴灵", "hometown": "Chongqing"},
{"username": "Fengmk2", "nick": "苏千", "hometown": "Guangzhou"}
];
| 方法 | DataV.collectionify() | DataV | collectionify |
| 参数 | table(Array) | 二维表数据 | |
| 参数 | head(Array) | 可选的表头数组,如果不指定,将取出二维表数据第一行作为表头 | |
| 代码 | |
||
判断输入是否是数字
| 方法 | DataV.isNumeric() | DataV | isNumeric |
| 参数 | obj(Mix) | 输入内容 | |
| 返回 | Boolean | 返回输入是否是数字 | |
| 代码 | |
||
添加数值边缘检测
| 方法 | DataV.limit() | DataV | limit |
| 参数 | number(Number) | 数字 | |
| 参数 | min(Number) | 下边缘 | |
| 参数 | max(Number) | 上边缘 | |
| 返回 | Boolean | 返回边缘检测后的数值 | |
| 代码 | |
||
继承
| 方法 | DataV.extend() | DataV | extend |
| 参数 | parent(Function) | 父类 | |
| 参数 | properties(Object) | 新属性 | |
| 返回 | Function | 新的子类 | |
| 代码 | |
||
所有Chart的源定义
var Stream = DataV.extend(DataV.Chart, {
initialize: function () {
this.type = "Stream";
},
clearCanvas: function () {
this.canvas.clear();
this.legend.innerHTML = "";
}
});
| 声明 | Chart | Chart | |
| 代码 | |
||
返回当前Chart的类型
| 方法 | Chart.prototype.getType() | getType | |
| 返回 | String | Chart类型 | |
| 代码 | |
||
优先返回用户传入的值或者方法,如果不存在,取实例方法返回
| 方法 | Chart.prototype.getFormatter() | getFormatter | |
| 参数 | key(String) | 方法或值的名称 | |
| 参数 | 值或方法(Mix) | ||
| 代码 | |
||
如果node是字符串,会当作ID进行查找。
如果是DOM元素,直接返回该元素。
如果是jQuery对象,返回对象中的第一个元素。
如果节点不存在,则抛出异常
chart.checkContainer("id");
chart.checkContainer(document.getElementById("id"));
chart.checkContainer($("#id"));
| 方法 | Chart.prototype.checkContainer() | checkContainer | |
| 参数 | node(Mix) | The element Id or Dom element | |
| 返回 | Object | 返回找到的DOM节点 | |
| 代码 | |
||
设置自定义选项
Set width 500px, height 600px;
{"width": 500, "height": 600}
| 方法 | Chart.prototype.setOptions() | setOptions | |
| 参数 | options(Object) | 自定义选项对象 | |
| 返回 | Object | 覆盖后的图表选项对象 | |
| 代码 | |
||
添加插件方法到实例对象上
| 方法 | Chart.prototype.plug() | plug | |
| 参数 | name(String) | plugin name | |
| 参数 | fn(Function) | plugin function | |
| 返回 | Object | A reference to the host object | |
| 代码 | |
||
从实例上移除插件方法
| 方法 | Chart.prototype.unplug() | unplug | |
| 参数 | plugin(String) | The namespace of the plugin | |
| 返回 | Object | A reference to the host object | |
| 代码 | |
||
数据源映射
| 方法 | Chart.prototype.map() | map | |
| 代码 | |
||
拥有一个组件
| 方法 | Chart.prototype.own() | own | |
| 代码 | |
||
浮动标签
| 方法 | DataV.FloatTag() | DataV | FloatTag |
| 代码 | |
||
function from d3, get scaleRange of an ordinal scale
| 函数 | d3_scaleExtent() | d3_scaleExtent | |
| 参数 | domain(Array) | ordinal scale's range | |
| 代码 | |
||
function from d3, get scaleRange of a scale
| 函数 | d3_scaleRange() | d3_scaleRange | |
| 代码 | |
||
function from d3, get subticks
| 函数 | d3_svg_axisSubdivide() | d3_svg_axisSubdivide | |
| 参数 | scale(scale,) | ||
| 参数 | major(ticks,) | ticks of scale | |
| 参数 | number(m,) | of subdivide | |
| 代码 | |
||
@param paper: raphael's paper object.
| 函数 | axis() | axis | |
| 返回 | axisSet: | raphael's set object. | |
| 代码 | |
||
get or set axis' scale.
| 方法 | axis.scale() | axis | scale |
| 代码 | |
||
get or set axis' orinet: "bottom", "top", "left", "right", default orient is bottom.
| 方法 | axis.orient() | axis | orient |
| 代码 | |
||
get or set axis' ticks number.
| 方法 | axis.ticks() | axis | ticks |
| 代码 | |
||
get or set axis' ticks format function, it's a function change format style.
from one string format to another string format.
| 方法 | axis.tickFormat() | axis | tickFormat |
| 代码 | |
||
get or set axis' tick size(length of tick line, unit: px).
| 方法 | axis.tickSize() | axis | tickSize |
| 参数 | ===(arguments.length) | 0, get axis' major tick size. | |
| 参数 | ===(arguments.length) | 1, set axis' all tick sizes as x. | |
| 参数 | ===(arguments.length) | 2, get axis' major tick size as x, minor and end size as y. | |
| 参数 | ===(arguments.length) | 3, get axis' major tick size as x, minor size as y, end size as z. | |
| 代码 | |
||
get or set axis' tick padding(the distance between tick text and axis).
| 方法 | axis.tickPadding() | axis | tickPadding |
| 参数 | is(x) | a number, unit is px; | |
| 代码 | |
||
get or set axis' sub tick divide number(divide number between two major ticks).
| 方法 | axis.tickSubdivide() | axis | tickSubdivide |
| 代码 | |
||
get or set axis' tick attribute(Raphael format).
| 方法 | axis.tickAttr() | axis | tickAttr |
| 代码 | |
||
get or set axis' tick text attribute(Raphael format).
| 方法 | axis.tickTextAttr() | axis | tickTextAttr |
| 代码 | |
||
get or set axis' minor tick attribute(Raphael format).
| 方法 | axis.minorTickAttr() | axis | minorTickAttr |
| 代码 | |
||
get or set axis' domain(axis line) attribute(Raphael format).
| 方法 | axis.domainAttr() | axis | domainAttr |
| 代码 | |
||
Bar构造函数
Creates Bar in a DOM node with id "chart", default width is 522; height is 522px;
width 宽度,默认为节点宽度yBase 横坐标的基线值,有的以0为起始值,有的则以数据中的最小值为起始值gap 组与组之间的缝隙宽度barColor 设置每组bar的颜色,数组xTickNumber 横轴刻度数量yTickNumber 纵轴刻度数量legendWidth 设置图例宽度showLegend 设置是否显示图例formatLabel 纵轴刻度格式化函数,传入纵轴刻度值,formatXScale 横轴轴刻度格式化函数,传入横轴刻度值,formatValue 数值格式化函数,传入数值,formatLegend 图里的文字格式化函数,传入图例文字var bar = new Bar("chart", {"width": 500, "height": 600);
| 声明 | Bar | Bar | |
| 参数 | node(Mix) | The dom node or dom node Id | |
| 参数 | options(Object) | options json object for determin bar style. | |
| 代码 | |
||
柱纬度
| 代码 | |
||
横向纬度
| 代码 | |
||
值纬度
| 代码 | |
||
创建画布
| 方法 | Bar.prototype.createCanvas() | createCanvas | |
| 代码 | |
||
设置数据源
Examples:
bar.setSource(source , {
bar: 0,
x: 1,
value: 2
});
| 方法 | Bar.prototype.setSource() | setSource | |
| 参数 | source(Array) | 数据源 第一列为排布在y轴的数据,后n列为排布在x轴的数据 | |
| 参数 | map(Object) | 映射方式 | |
| 代码 | |
||
设置坐标轴
| 方法 | Bar.prototype.setAxis() | setAxis | |
| 代码 | |
||
绘制坐标
| 方法 | Bar.prototype.drawAxis() | drawAxis | |
| 代码 | |
||
进行柱状图的绘制
| 方法 | Bar.prototype.drawDiagram() | drawDiagram | |
| 代码 | |
||
绘制图例
| 方法 | Bar.prototype.drawLegend() | drawLegend | |
| 代码 | |
||
绘制柱状图
width 宽度,默认为节点宽度typeNames 指定y轴上数据类目bar.render({"width": 1024})
| 方法 | Bar.prototype.render() | render | |
| 参数 | options(Object) | options json object for determin bar style. | |
| 代码 | |
||
set foreground and resizers' x and width;
| 函数 | d3_svg_brushRedrawX() | d3_svg_brushRedrawX | |
| 代码 | |
||
set foreground and resizers' y and height;
| 函数 | d3_svg_brushRedrawY() | d3_svg_brushRedrawY | |
| 代码 | |
||
function from d3, get scaleRange of an ordinal scale
| 函数 | d3_scaleExtent() | d3_scaleExtent | |
| 参数 | ordinal(domain,) | scale's range | |
| 代码 | |
||
function from d3, get scaleRange of a scale
| 函数 | d3_scaleRange() | d3_scaleRange | |
| 代码 | |
||
function from d3, called by d3_svg_brushMove, compute new brush extent after brush moved
| 函数 | d3_svg_brushMove1() | d3_svg_brushMove1 | |
| 代码 | |
||
function from d3, after brush moved, compute new brush extent
and redraw foreground and resizer.
| 函数 | d3_svg_brushMove() | d3_svg_brushMove | |
| 代码 | |
||
function from d3,
reset brush offset if user presses "space" key while brushing a new area,
to ensure foreground's size unchanged while position changing.
| 函数 | d3_svg_brushKeydown() | d3_svg_brushKeydown | |
| 代码 | |
||
function from d3,
reset brush offset if "space" key up to restore normal drush state.
| 函数 | d3_svg_brushKeyup() | d3_svg_brushKeyup | |
| 代码 | |
||
function from d3,
mouse up and stop brushing.
| 函数 | d3_svg_brushUp() | d3_svg_brushUp | |
| 代码 | |
||
Recently, bubble graph can represent five dimensions by xaxis,yaxis,size,color and time.
You can stop animation by pause() method, start animation by initControls method;
you can change animation start time by using global variable this.startTime;
you can visualize a time point's data by generatePaths(time point) method;
an inside method drawAllTime(key) is designed for interaction.
width, 图表宽度,默认800height, 图表高度, 默认600minRadius, 最小圆角值meshInterval, 背景网格的间距, 默认20showLegend, 是否显示图例,默认显示margin, 主图的间距,[上, 右, 下, 左], 默认为[30, 0, 80, 200]。当不显示图例时,可调节此处tipStyle, 提示框样式skeletonLineAttr, 龙骨线属性skeletonCircleAttr, 龙骨点属性| 声明 | Bubble | Bubble | |
| 代码 | |
||
@param {String} key 关键字
| 方法 | this.formatter.tipFormat() | this.formatter | tipFormat |
| 参数 | x0(Number) | 横轴值 | |
| 参数 | y0(Number) | 纵轴值 | |
| 参数 | r0(Number) | 半径值 | |
| 参数 | c0(Number) | 分组值 | |
| 参数 | time(String) | 时间值 | |
| 代码 | |
||
Creates a backCanvas for the visualization
| 方法 | Bubble.prototype.createCanvas() | createCanvas | |
| 代码 | |
||
Chooses bubble graph setted visualization dimens orderly
| 方法 | Bubble.prototype.chooseDimensions() | chooseDimensions | |
| 代码 | |
||
set source, get dimensions data, dimension type, and dimension domain
default visualization dimension is setted here
| 方法 | Bubble.prototype.setSource() | setSource | |
| 代码 | |
||
绘制图例
| 方法 | Bubble.prototype.drawLegend() | drawLegend | |
| 代码 | |
||
different visualization scale is defined here
| 方法 | Bubble.prototype.getScale() | getScale | |
| 代码 | |
||
draw x-axis, y-axis and related parts
| 方法 | Bubble.prototype.renderAxis() | renderAxis | |
| 代码 | |
||
color database
| 方法 | Bubble.prototype.colorDB() | colorDB | |
| 代码 | |
||
main visualization method where bubble is drawed inside
a time point is the method's only parameter
| 方法 | Bubble.prototype.generatePaths() | generatePaths | |
| 代码 | |
||
get key's specific dimension data which include all time points
| 方法 | Bubble.prototype.getKeyData() | getKeyData | |
| 代码 | |
||
get a unique color specified by key
| 方法 | Bubble.prototype.getColorData() | getColorData | |
| 代码 | |
||
set up an animation
| 方法 | Bubble.prototype.initControls() | initControls | |
| 代码 | |
||
interpolated some data between neibourh data point for the animation
| 方法 | Bubble.prototype.interpolateData() | interpolateData | |
| 代码 | |
||
clear animation and related artifacts
| 方法 | Bubble.prototype.clearAnimation() | clearAnimation | |
| 代码 | |
||
pause the interval
| 方法 | Bubble.prototype.pause() | pause | |
| 代码 | |
||
set the rendering process
| 方法 | Bubble.prototype.render() | render | |
| 代码 | |
||
Bullet构造函数
width 数字,图片宽度,默认为200,表示图片高200pxheight 数字,图片高度,默认为80orient string,图片方向,默认为"horizonal",表示水平方向。若为"vertical",则表示垂直方向axisStyle string, 坐标系类型,默认为"linear",表示坐标系为线性坐标系。若为"log",则表示对数坐标系logBase 数字, 采用对数坐标系时的对数基,默认为Math.EtickDivide 数字,表示坐标的标尺的分段数,默认为5margin 数字数组,表示图片上、右、下、左的边距,默认为 [20, 20, 20, 20]centerBarRatio 数字,表示中间的测度条的高度与背景条高度的比值, 默认为0.3markerWidth 数字,表示标记条的宽度, 默认为4,单位为像素markerRatio 数字,表示标记条的高度与背景条高度的比值,默认为0.7titleRatio 数字,表示子弹图title的高度与背景条高度的比值,默认为0.6,此时title与subtitle的比值backgroundColor string数组,表示背景条颜色的渐变数组,默认为["#666", "#ddd"],背景条颜色就是这两种颜色的渐变measureColor string数组,表示测度条颜色的渐变数组,默认为["steelblue", "#B0C4DE"],测度条颜色就是这两种颜色的渐变markerColor string,表示标记条的颜色,默认为"#000"//Create bullet in a dom node with id "chart", width is 500; height is 600px;
var bullet = new Bullet("chart", {
"width": 500,
"height": 600,
"margin": [10, 10, 20, 70]
});
//Create bullet with log base;
var log = new Bullet("chart2", {
width: 300,
height: 60,
margin: [10, 10, 20, 70],
backgroundColor: ["#66f", "#ddf"],
measureColor: ["#000", "#000"],
markerColor: "#44f",
axisStyle: "log",
logBase: 10
});
| 声明 | Bullet | Bullet | |
| 参数 | node(Mix) | The dom node or dom node Id | |
| 参数 | options(Object) | options json object for determin stream style. | |
| 代码 | |
||
设置数据源
bullet.setSource({
title: "Sample",
subtitle: "ratio",
ranges: [0, 0.5, 0.8, 1],
measures: [0.7, 0.9],
markers: [0.6],
rangeTitles: ["below 50%", "top 20% - 50%", "top 20%"],
measureTitles: ["value is 0.7", "value is 0.9"],
markerTitles: ["mean is 0.6"]
})
| 方法 | Bullet.prototype.setSource() | setSource | |
| 参数 | source(Object) | 数据源 | |
| 代码 | |
||
render bullet
| 方法 | Bullet.prototype.render() | render | |
| 代码 | |
||
构造函数,node参数表示在html的哪个容器中绘制该组件
options对象为用户自定义的组件的属性,比如画布大小
| 声明 | Bundle | Bundle | |
| 代码 | |
||
设置用户自定义属性
| 方法 | Bundle.prototype.setOptions() | setOptions | |
| 代码 | |
||
对原始数据进行处理
TODO: 改进为获取值时运算
| 方法 | Bundle.prototype.setSource() | setSource | |
| 代码 | |
||
创建画布
| 方法 | Bundle.prototype.createCanvas() | createCanvas | |
| 代码 | |
||
布局
| 方法 | Bundle.prototype.layout() | layout | |
| 代码 | |
||
渲染弦图
| 方法 | Bundle.prototype.render() | render | |
| 代码 | |
||
生成路径
| 方法 | Bundle.prototype.generatePaths() | generatePaths | |
| 代码 | |
||
"font-weight": "600"
| 代码 | |
||
Chinamap构造函数,继承自Chart
width 数字,图宽度,默认为600,表示图高600pxheight 数字,图高度,默认为500geoDataPath 字符串,地图数据的文件路径,如"../../lib/charts/data/chinaMap/"mapId 字符串,地图区域的Id,用于载入相应的地图文件。全国时,mapId为"0";新疆为"65"。其他各省Id可参考this.geoData.areaIdIndex。可调用getMapId()来获取某地区的mapId。showWords 布尔值,是否显示省名或市名的文字。默认为true,显示。levelChangeable 布尔值,是否开启全国与省之间的缩放。默认为true,开启。zoomAnimate 布尔值,缩放时是否显示动画。默认为true, 开启(因性能原因,IE6-8始终不开启)。colorModel 字符串,表示取色模式,可取"discrete"(默认)或"gradient"。"discrete"时颜色在colors中从头至尾循环选取,"gradient"时依照colors中颜色的渐变插值计算。colors 颜色字符串数组。默认为discrete模式下的离散颜色数组。defaultAreacolor 颜色字符串。默认为"#dddddd"。当区域没有数据时默认显示的颜色。wordStyle object。默认为{}。省名或城市名的文字的Raphael样式。具体设置方式请参考Raphael手册:http://raphaeljs.com/reference.html#Element.attrareaStyle object。默认为{}。省或城市的区域的Raphael样式。具体设置方式请参考Raphael手册:http://raphaeljs.com/reference.html#Element.attrareaHoverIn 函数,表示鼠标移上某个区域的事件响应,默认为空函数;areaHoverOut 函数,表示鼠标移出某个区域的事件响应,默认为空函数;areaClick 函数,表示点击某个区域的事件响应,默认为空函数;wordHoverIn 函数,表示鼠标移上某个地名文字时的事件响应;wordHoverOut 函数,表示鼠标移出某个地名文字时的事件响应;wordClick 函数,表示点击某个地名文字的事件响应,默认为空函数;create chinamap in a dom node with id "chart", width is 500; height is 600px;
var chinamap = new Chinamap("chart", {"width": 500, "height": 600});
| 声明 | Chinamap | Chinamap | |
| 参数 | node(Object) | The dom node or dom node Id | |
| 参数 | options(Object) | JSON object for determin chinamap style | |
| 代码 | |
||
this.floatTag;//浮框对象,这是个可操作的对象。
| 属性 | this.viewBox | this | viewBox |
| 代码 | |
||
get value from indexes
| 方法 | Chinamap.prototype._searchIndex() | _searchIndex | |
| 代码 | |
||
get longitude and latitude center by city or porvince name
regionType is optional, if it's undefined, then first search province, then city
| 方法 | Chinamap.prototype.getLoc() | getLoc | |
| 代码 | |
||
get longitude and latitude center by porvince name
| 方法 | Chinamap.prototype.getProvinceCenter() | getProvinceCenter | |
| 代码 | |
||
get longitude and latitude center by city name
| 方法 | Chinamap.prototype.getCityCenter() | getCityCenter | |
| 代码 | |
||
get format name by city or porvince name
regionType is optional, if it's undefined, then first search province, then city
| 方法 | Chinamap.prototype.getFormatName() | getFormatName | |
| 代码 | |
||
get fullName by porvince name
| 方法 | Chinamap.prototype.getProvinceFormatName() | getProvinceFormatName | |
| 代码 | |
||
get fullName by city name
| 方法 | Chinamap.prototype.getCityFormatName() | getCityFormatName | |
| 代码 | |
||
Create dom node relate to chinamap
| 方法 | Chinamap.prototype.createCanvas() | createCanvas | |
| 代码 | |
||
get mapId by area name
| 方法 | Chinamap.prototype.getMapId() | getMapId | |
| 代码 | |
||
获取区域颜色。内部函数。用户设置colorModel和colors来设置区域颜色。输入为地图区域对象,内部对象,包含某个地图区域的信息。
内部的实现流程是:如果颜色生成函数不存在,则根据colorModel生成颜色生成函数。"discrete"时颜色在colors中从头至尾循环选取,"gradient"时依照colors中颜色的渐变插值计算。离散色时颜色有区域的分类决定。渐变色时颜色由区域的值决定(最小值和最大值间进行插值)。
| 方法 | Chinamap.prototype.getColor() | getColor | |
| 代码 | |
||
设置数据源
输入为object。key为地区名称。当区域分成多个类时,value为类别名。当区域有值时,value为数字。
//示例一,区域有值,全国各省人口数据,适合用渐变色显示。
chinamap.setSource({
'北京': 19612368,
'天津': 12938224,
'河北': 71854202,
'山西': 35712111,
'内蒙': 24706321,
'辽宁': 43746323,
'吉林': 27462297,
'黑龙': 38312224,
'上海': 23019148,
'江苏': 78659903,
'浙江': 54426891,
'安徽': 59500510,
'福建': 36894216,
'江西': 44567475,
'山东': 95793065,
'河南': 94023567,
'湖北': 57237740,
'湖南': 65683722,
'广东': 104303132,
'广西': 46026629,
'海南': 8671518,
'重庆': 28846170,
'四川': 80418200,
'贵州': 34746468,
'云南': 45966239,
'西藏': 3002166,
'陕西': 37327378,
'甘肃': 25575254,
'青海': 5626722,
'宁夏': 6301350,
'新疆': 21813334,
'香港': 7097600,
'澳门': 552300,
'台湾': 23162123
});
//示例二,区域分成各个类,适合用渐变色显示。
chinamap.setSource({
'北京': '华北',
'天津': '华北',
'河北': '华北',
'山西': '华北',
'内蒙古': '华北',
'上海': '华东',
'江苏': '华东',
'浙江': '华东',
'山东': '华东',
'安徽': '华东',
'辽宁': '东北',
'吉林': '东北',
'黑龙江': '东北',
'湖北': '华中',
'湖南': '华中',
'河南': '华中',
'江西': '华中',
'广东': '华南',
'广西': '华南',
'海南': '华南',
'福建': '华南',
'四川': '西南',
'重庆': '西南',
'贵州': '西南',
'云南': '西南',
'西藏': '西南',
'陕西': '西北',
'甘肃': '西北',
'新疆': '西北',
'青海': '西北',
'宁夏': '西北',
'香港': '港澳台',
'澳门': '港澳台',
'台湾 ': '港澳台'
});
| 方法 | Chinamap.prototype.setSource() | setSource | |
| 参数 | area(Object) | json | |
| 代码 | |
||
根据省份名字,获取省份的对象
| 方法 | Chinamap.prototype.getAreaByName() | getAreaByName | |
| 代码 | |
||
清除画布
| 方法 | Chinamap.prototype.clearCanvas() | clearCanvas | |
| 代码 | |
||
计算布局位置,并渲染图表
| 方法 | Chinamap.prototype.render() | render | |
| 代码 | |
||
将点在矢量图中的位置 转化为 实际显示点相对于图片左上角的位置(像素距离)
| 方法 | Chinamap.prototype._scaleLocToPixelLoc() | _scaleLocToPixelLoc | |
| 代码 | |
||
将实际显示点相对于图片左上角的位置(像素距离) 转化为 点在矢量图中的位置
| 方法 | Chinamap.prototype._pixelLocToScaleLoc() | _pixelLocToScaleLoc | |
| 代码 | |
||
渲染城市点
| 方法 | Chinamap.prototype.createCityPoints() | createCityPoints | |
| 代码 | |
||
构造函数
| 声明 | Chord | Chord | |
| 参数 | node(Object) | 表示在html的哪个容器中绘制该组件 | |
| 参数 | options(Object) | 为用户自定义的组件的属性,比如画布大小 | |
| 代码 | |
||
值纬度
| 代码 | |
||
创建画布
| 方法 | Chord.prototype.createCanvas() | createCanvas | |
| 代码 | |
||
获取颜色
| 方法 | Chord.prototype.getColor() | getColor | |
| 参数 | i(Number) | 元素类别编号 | |
| 返回 | String | 返回颜色值 | |
| 代码 | |
||
绘制弦图
| 方法 | Chord.prototype.render() | render | |
| 代码 | |
||
绘制图例
| 方法 | Chord.prototype.drawLegend() | drawLegend | |
| 代码 | |
||
对原始数据进行处理
| 方法 | Chord.prototype.setSource() | setSource | |
| 参数 | table(Array) | 将要被绘制成饼图的二维表数据 | |
| 代码 | |
||
创建chord布局
| 方法 | Chord.prototype.layout() | layout | |
| 代码 | |
||
ar see = [
[11975, 5871, 8916, 2868],
[1951, 10048, 2060, 6171],
[8010, 16145, 8090, 8045],
[1013, 990, 940, 6907]
];
| 声明 | chordLayout | chordLayout | |
| 代码 | |
||
ar fillColor = d3.scale.ordinal()
.domain(d3.range(4))
.range(["#000000", "#FFDD89", "#957244", "#F26223"]);
| 代码 | |
||
groups[i].startAngle * 180 / Math.PI - 90)
| 代码 | |
||
his.canvas.text().attr("font", "12px arial").translate((that.defaults.width - this.xOffset) / 2 + this.xOffset, this.defaults.height).attr("text", "The unit of the scale on the periphery is 1000. \n 刻度值的单位为1000。");
| 代码 | |
||
Column构造函数
Creates Column in a DOM node with id "chart"
width 宽度,默认为522,单位像素height 高度,默认为522,单位像素yBase 纵坐标的基线值,默认为0,可以设置为任意数值;为undefined时,以数据中的最小值为起始值barWidth 柱子的宽度showLegend 是否显示图例legendWidth 图例的宽度margin 图表的间距,依次为上右下左xTickNumber 横轴刻度数yTickNumber 纵轴刻度数formatLabel 横轴提示格式化函数,传入横轴值,默认函数传出原始值formatYScale 纵轴刻度格式化函数,传入纵轴刻度值formatValue 值格式化函数var column = new Column("chart", {"width": 500, "height": 600, "typeNames": ["Y", "Z"]});
| 声明 | Column | Column | |
| 参数 | node(Mix) | The dom node or dom node Id | |
| 参数 | options(Object) | options json object for determin column style. | |
| 代码 | |
||
柱纬度
| 代码 | |
||
横向纬度
| 代码 | |
||
值纬度
| 代码 | |
||
创建画布
| 方法 | Column.prototype.createCanvas() | createCanvas | |
| 代码 | |
||
设置数据源
Examples:
column.setSource(source);
| 方法 | Column.prototype.setSource() | setSource | |
| 参数 | source(Array) | 数据源 第一列为排布在x轴的数据,后n列为排布在y轴的数据 | |
| 代码 | |
||
设置坐标轴
| 方法 | Column.prototype.setAxis() | setAxis | |
| 代码 | |
||
绘制坐标
| 方法 | Column.prototype.drawAxis() | drawAxis | |
| 代码 | |
||
进行柱状图的绘制
| 方法 | Column.prototype.drawDiagram() | drawDiagram | |
| 代码 | |
||
绘制图例
| 方法 | Column.prototype.drawLegend() | drawLegend | |
| 代码 | |
||
绘制柱状图
width 宽度,默认为节点宽度typeNames 指定y轴上数据类目column.render({"width": 1024})
| 方法 | Column.prototype.render() | render | |
| 参数 | options(Object) | options json object for determin column style. | |
| 代码 | |
||
构造函数
| 声明 | Diff | Diff | |
| 参数 | node(Object) | 表示在html的哪个容器中绘制该组件 | |
| 参数 | options(Object) | 为用户自定义的组件的属性,比如画布大小 | |
| 代码 | |
||
创建画布
| 方法 | Diff.prototype.createCanvas() | createCanvas | |
| 代码 | |
||
绘制弦图
| 方法 | Diff.prototype.render() | render | |
| 代码 | |
||
对原始数据进行处理
| 方法 | Diff.prototype.setSource() | setSource | |
| 参数 | table(Array) | 将要被绘制成饼图的二维表数据 | |
| 代码 | |
||
创建chord布局
| 方法 | Diff.prototype.layout() | layout | |
| 代码 | |
||
Flow构造函数
| 声明 | Flow | Flow | |
| 代码 | |
||
构造函数
| 声明 | Force | Force | |
| 参数 | node(Object) | 表示在html的哪个容器中绘制该组件 | |
| 参数 | options(Object) | 为用户自定义的组件的属性,比如画布大小 | |
| 代码 | |
||
节点id
| 代码 | |
||
节点名称
| 代码 | |
||
节点值
| 代码 | |
||
边源头节点
| 代码 | |
||
边指向节点
| 代码 | |
||
边值
| 代码 | |
||
Set CSV content to force-directed net
| 方法 | Force.prototype.setSource() | setSource | |
| 参数 | table(Array) | the csv table to be rendered | |
| 代码 | |
||
创建画布
| 方法 | Force.prototype.createCanvas() | createCanvas | |
| 代码 | |
||
获取节点颜色
| 方法 | Force.prototype.getColor() | getColor | |
| 参数 | i(Number) | 元素类别编号 | |
| 返回 | String | 返回颜色值 | |
| 代码 | |
||
获取节点的半径
| 方法 | Force.prototype.getRadius() | getRadius | |
| 参数 | value(Number) | 元素对应的数据值 | |
| 返回 | Number | 返回半径值 | |
| 代码 | |
||
获取节点透明度
| 方法 | Force.prototype.getOpacity() | getOpacity | |
| 参数 | value(Number) | 元素类别编号 | |
| 返回 | Number | 返回透明度值 | |
| 代码 | |
||
update the layout by modify the attributes of nodes and links
| 方法 | Force.prototype.update() | update | |
| 代码 | |
||
绘制图例
| 方法 | Force.prototype.legend() | legend | |
| 代码 | |
||
create the force-direct layout
| 方法 | Force.prototype.layout() | layout | |
| 代码 | |
||
update the force-direct layout animation
| 方法 | Force.prototype.animate() | animate | |
| 代码 | |
||
render the force-directed net on the canvas and keep updating
| 方法 | Force.prototype.render() | render | |
| 参数 | options(Object) | user options | |
| 代码 | |
||
类型纬度
| 代码 | |
||
时间纬度
| 代码 | |
||
值纬度
| 代码 | |
||
lobal Raphael, _, $
| 代码 | |
||
Line构造函数,继承自Chart
width 数字,画布宽度,默认为960,表示图片高960pxheight 数字,画布高度,默认为500margin 数组,这个折线图在画布中四周的留白,长度为4,分别代表[top, right, bottom, left], 默认值为[10, 40, 40, 40]title 字符串,一级标题, 默认值为nullsubtitle 字符串,副标题, 默认值为nullCreate line in a dom node with id "chart", width is 500px; height is 600px;
var line = new Line("chart", {"width": 500, "height": 600});
| 声明 | Line | Line | |
| 参数 | node(Mix) | The dom node or dom node Id | |
| 参数 | options(Object) | options json object for determin line style. | |
| 代码 | |
||
线纬度
| 代码 | |
||
值纬度
| 代码 | |
||
值纬度
| 代码 | |
||
创建画布
| 方法 | Line.prototype.createCanvas() | createCanvas | |
| 代码 | |
||
对原始数据进行处理
| 方法 | Line.prototype.setSource() | setSource | |
| 代码 | |
||
获取颜色函数
| 方法 | Line.prototype.getColor() | getColor | |
| 返回 | function | DataV根据主题获取随机离散色函数 | |
| 代码 | |
||
绘制X轴
| 方法 | Line.prototype.setXaxis() | setXaxis | |
| 代码 | |
||
绘制Y轴
| 方法 | Line.prototype.setYaxis() | setYaxis | |
| 代码 | |
||
绘制背景
| 方法 | Line.prototype.setBackground() | setBackground | |
| 代码 | |
||
渲染折线图
var line = new Line("chart");
line.setSource(source);
line.render();
| 方法 | Line.prototype.render() | render | |
| 参数 | options(object) | options json object for determin line style. | |
| 代码 | |
||
添加交互选项
| 方法 | Line.prototype.interactive() | interactive | |
| 代码 | |
||
构造函数
| 声明 | Matrix | Matrix | |
| 代码 | |
||
构造函数
width 数字,图片宽度,默认为750,表示图片高750pxheight 数字,图片高度,默认为500marginWidth 数组,表示图片上、右、下、左的边距,默认为 [20, 20, 20, 20]backgroundAttr 对象,没有选中的线的样式,默认为{"fill": "none", "stroke": "#ccc", "stroke-opacity": 0.4}, 具体设置方式请参考Raphael手册:http://raphaeljs.com/reference.html#Element.attrforegroundAttr 对象,被选中的线的样式,默认为{"fill": "none", "stroke": "steelblue", "stroke-opacity": 0.7}, 具体设置方式请参考Raphael手册:http://raphaeljs.com/reference.html#Element.attraxisStyle 对象,设置坐标轴属性。3中坐标轴属性:domainAttr表示坐标轴线属性。tickAttr表示坐标轴标尺属性。tickTextAttr表示坐标轴文字属性。具体设置方式请参考Raphael手册:http://raphaeljs.com/reference.html#Element.attrcustomEvent 函数对象,其中有3个自定义函数。brushstart 函数,表示刚开始拖选区间的事件响应,默认为空函数; brushend 函数,表示拖选结束后的事件响应,默认为空函数; brush 函数,表示拖选时的事件响应,默认为空函数; 这些函数可以在创建对象或setOption()时一起设置,也可以通过on()函数单独设置。| 声明 | Parallel | Parallel | |
| 参数 | node(Node,String,jQuery) | 容器节点,文档节点、ID或者通过jQuery查询出来的对象 | |
| 代码 | |
||
choose dimension
| 方法 | Parallel.prototype.chooseDimensions() | chooseDimensions | |
| 参数 | dimen(array) | Array of column names | |
| 代码 | |
||
set dimension type, ordinal or quantitative
parallel.setDimensionType({"cylinders": "ordinal", "year": "quantitative"});
| 方法 | Parallel.prototype.setDimensionType() | setDimensionType | |
| 参数 | dimenType(Object) | dimension type obj | |
| 代码 | |
||
get dimensions extents
| 方法 | Parallel.prototype.getDimensionExtents() | getDimensionExtents | |
| 返回 | Object | {key: dimension name(column name); value: dimenType("ordinal" or "quantitativ")} | |
| 代码 | |
||
set dimension extent, if chart has been rendered, then refresh the chart;
parallel.setDimensionExtent({
"cylinders": ["6", "3"],
"economy (mpg)": [35, 20]
});
| 方法 | Parallel.prototype.setDimensionExtent() | setDimensionExtent | |
| 参数 | dimenExtent(Object) | {key: dimension name(column name); value: extent array;} | |
| 代码 | |
||
get dimension types
| 方法 | Parallel.prototype.getDimensionTypes() | getDimensionTypes | |
| 返回 | Object | {key: dimension name(column name); value: dimenType("ordinal" or "quantitativ")} | |
| 代码 | |
||
get dimension domain
| 方法 | Parallel.prototype.getDimensionDomains() | getDimensionDomains | |
| 返回 | Object | {key: dimension name(column name); value: extent array;} | |
| 代码 | |
||
set dimension domain
parallel.setDimensionDomain({
"cylinders": [4, 8], //quantitative
"year": ["75", "79", "80"] //ordinal
});
| 方法 | Parallel.prototype.setDimensionDomain() | setDimensionDomain | |
| 参数 | dimenDomain(Object) | {key: dimension name(column name); value: domain array (quantitative domain is digit array whose length is 2, ordinal domain is string array whose length could be larger than 2;} | |
| 代码 | |
||
侦听自定义事件
| 方法 | Parallel.prototype.on() | on | |
| 代码 | |
||
设置数据源
第一行为列名
[
["name", "weight", "year"],
["AMC", "2000", "79"],
["Buick", "2100", "80"]
]
| 方法 | Parallel.prototype.setSource() | setSource | |
| 参数 | source(Array) | 二维数组的数据源 | |
| 代码 | |
||
绘制图表
| 方法 | Parallel.prototype.render() | render | |
| 代码 | |
||
类型纬度
| 代码 | |
||
时间纬度
| 代码 | |
||
值纬度
| 代码 | |
||
生成标签的默认方法,可以通过setOption({getPathLable: function});覆盖。
type, 条带类型rank, 条带排名sum, 当前条带总值total, 所有条带总值| 方法 | PathLabel.prototype.getPathLabel() | getPathLabel | |
| 参数 | obj(Object) | 当前条带的对象 | |
| 代码 | |
||
类型纬度
| 代码 | |
||
值纬度
| 代码 | |
||
构造函数
width 图片宽度,默认为800,表示图片高800pxheight 图片高度,默认为800showLegend 图例是否显示,默认为 true, 显示;设为false则不显示showText 是否显示文字,默认为truems 动画持续时间,默认300easing 动画类型,默认“bounce”。详见rapheal相关文档,可以使用“linear”,“easeIn”,“easeOut”,“easeInOut”,“backIn”,“backOut”,“elastic”,“bounce”create Radar Chart in a dom node with id "chart", width is 500; height is 600px;
var radar = new Radar("chart", {"width": 500, "height": 600});
| 声明 | Pie | Pie | |
| 参数 | container(Object) | 表示在html的哪个容器中绘制该组件 | |
| 参数 | options(Object) | 为用户自定义的组件的属性,比如画布大小 | |
| 代码 | |
||
标签纬度
| 代码 | |
||
值纬度
| 代码 | |
||
创建画布
| 方法 | Pie.prototype.createCanvas() | createCanvas | |
| 代码 | |
||
获取颜色
| 方法 | Pie.prototype.getColor() | getColor | |
| 参数 | i(Number) | 元素类别编号 | |
| 返回 | String | 返回颜色值 | |
| 代码 | |
||
绘制饼图
| 方法 | Pie.prototype.render() | render | |
| 代码 | |
||
绘制图例
| 方法 | Pie.prototype.drawLegend() | drawLegend | |
| 代码 | |
||
对原始数据进行处理
| 方法 | Pie.prototype.setSource() | setSource | |
| 参数 | table(Array) | 将要被绘制成饼图的二维表数据 | |
| 代码 | |
||
创建pie布局
| 方法 | Pie.prototype.layout() | layout | |
| 代码 | |
||
构造函数
width 数字,图片宽度,默认为800,表示图片高800pxheight 数字,图片高度,默认为800legend 布尔值,图例是否显示,默认为 true, 显示;设为false则不显示radius 数字,雷达图半径,默认是画布高度的40%create Radar Chart in a dom node with id "chart", width is 500; height is 600px;
var radar = new Radar("chart", {"width": 500, "height": 600});
| 声明 | Radar | Radar | |
| 参数 | container(Object) | 表示在html的哪个容器中绘制该组件 | |
| 参数 | options(Object) | 为用户自定义的组件的属性,比如画布大小 | |
| 代码 | |
||
标签纬度
| 代码 | |
||
维度名称
| 代码 | |
||
维度值
| 代码 | |
||
创建画布
| 方法 | Radar.prototype.createCanvas() | createCanvas | |
| 代码 | |
||
获取颜色
| 方法 | Radar.prototype.getColor() | getColor | |
| 参数 | i(Number) | 元素类别编号 | |
| 返回 | String | 返回颜色值 | |
| 代码 | |
||
绘制radar chart
| 方法 | Radar.prototype.render() | render | |
| 代码 | |
||
get dimension types
| 方法 | Radar.prototype.getDimensionTypes() | getDimensionTypes | |
| 返回 | Object | {key: dimension name(column name); value: dimenType("ordinal" or "quantitativ")} | |
| 代码 | |
||
get dimension domain
| 方法 | Radar.prototype.getDimensionDomains() | getDimensionDomains | |
| 返回 | Object | {key: dimension name(column name); value: extent array;} | |
| 代码 | |
||
对原始数据进行处理
| 方法 | Radar.prototype.setSource() | setSource | |
| 参数 | table(Array) | 将要被绘制成磊达图的二维表数据 | |
| 代码 | |
||
this.source = DataV.collectionify(table);
//judge dimesions type auto
//if all number, quantitative else ordinal
this.dimensionType = {};
for (var i = 0, l = this.allDimensions.length; i < l; i++) {
var type = "quantitative";
for (var j = 1, ll = table.length; j < ll; j++) {
var d = table[j][i];
if (d && (!DataV.isNumeric(d))) {
type = "ordinal";
break;
}
}
this.dimensionType[this.allDimensions[i]] = type;
}
| 代码 | |
||
set dimension domain
parallel.setDimensionDomain({
"cylinders": [4, 8], //quantitative
"year": ["75", "79", "80"] //ordinal
});
| 方法 | Radar.prototype.setDimensionDomain() | setDimensionDomain | |
| 参数 | dimenDomain(Object) | {key: dimension name(column name); value: domain array (quantitative domain is digit array whose length is 2, ordinal domain is string array whose length could be larger than 2;} | |
| 代码 | |
||
绘制图例
| 方法 | Radar.prototype.legend() | legend | |
| 代码 | |
||
设置X轴的维度
| 方法 | ScatterplotMatrix.prototype.setDimensionsX() | setDimensionsX | |
| 代码 | |
||
设置Y轴的维度
| 方法 | ScatterplotMatrix.prototype.setDimensionsY() | setDimensionsY | |
| 代码 | |
||
设置X轴和Y轴
| 方法 | ScatterplotMatrix.prototype.setAxis() | setAxis | |
| 代码 | |
||
创建canvas
| 方法 | ScatterplotMatrix.prototype.createCanvas() | createCanvas | |
| 代码 | |
||
Stack构造函数
Creates Stack in a DOM node with id "chart"
width 宽度,默认为522,单位像素height 高度,默认为522,单位像素yBase 纵坐标的基线值,默认为0,可以设置为任意数值;为undefined时,以数据中的最小值为起始值barWidth 柱子的宽度showLegend 是否显示图例legendWidth 图例的宽度margin 图表的间距,依次为上右下左showPercentage 显示绝对值或百分比xTickNumber 横轴刻度数yTickNumber 纵轴刻度数formatLabel 横轴提示格式化函数,传入横轴值,默认函数传出原始值formatYScale 纵轴刻度格式化函数,传入纵轴刻度值formatValue 值格式化函数var stack = new Stack("chart", {"width": 500, "height": 600, "typeNames": ["Y", "Z"]});
| 声明 | Stack | Stack | |
| 参数 | node(Mix) | The dom node or dom node Id | |
| 参数 | options(Object) | options json object for determin stack style. | |
| 代码 | |
||
柱纬度
| 代码 | |
||
横向纬度
| 代码 | |
||
值纬度
| 代码 | |
||
创建画布
| 方法 | Stack.prototype.createCanvas() | createCanvas | |
| 代码 | |
||
设置数据源
Examples:
stack.setSource(source);
| 方法 | Stack.prototype.setSource() | setSource | |
| 参数 | source(Array) | 数据源 第一列为排布在x轴的数据,后n列为排布在y轴的数据 | |
| 代码 | |
||
d3.extent(dataTable, function (item)
{
return item[map.value];
});
| 代码 | |
||
设置坐标轴
| 方法 | Stack.prototype.setAxis() | setAxis | |
| 代码 | |
||
绘制坐标
| 方法 | Stack.prototype.drawAxis() | drawAxis | |
| 代码 | |
||
进行柱状图的绘制
| 方法 | Stack.prototype.drawDiagram() | drawDiagram | |
| 代码 | |
||
绘制图例
| 方法 | Stack.prototype.drawLegend() | drawLegend | |
| 代码 | |
||
绘制柱状图
width 宽度,默认为节点宽度typeNames 指定y轴上数据类目stack.render({"width": 1024})
| 方法 | Stack.prototype.render() | render | |
| 参数 | options(Object) | options json object for determin stack style. | |
| 代码 | |
||
his.userConfig.rootName
| 代码 | |
||
constructor
| 声明 | Stream | Stream | |
| 参数 | the(node) | dom node or dom node Id | |
| undefined | undefined | undefined | undefined |
| 示例 | undefined | undefined | undefined |
| undefined | undefined | undefined | undefined |
| undefined | undefined | undefined | undefined |
| 代码 | |
||
@param source The data source.
| 方法 | Stream.prototype.hasRowName() | hasRowName | |
| 示例 | undefined | undefined | undefined |
| undefined | undefined | undefined | undefined |
| undefined | undefined | undefined | undefined |
| undefined | undefined | undefined | undefined |
| undefined | undefined | undefined | undefined |
| undefined | undefined | undefined | undefined |
| 代码 | |
||
| 方法 | Stream.prototype.getColor() | getColor | |
| 代码 | |
||
类型纬度
| 代码 | |
||
时间纬度
| 代码 | |
||
值纬度
| 代码 | |
||
| 方法 | Stream.prototype.getColor() | getColor | |
| 代码 | |
||
时间纬度
| 代码 | |
||
类型纬度
| 代码 | |
||
时间纬度
| 代码 | |
||
值纬度
| 代码 | |
||
Tree的构造函数
var tree = new Tree("container");
tree.setSource(source);
tree.render();
width: 画布的宽度height: 画布的高度| 声明 | Tree | Tree | |
| 代码 | |
||
饼图纬度描述
| 属性 | Tree.dimension | Tree | dimension |
| 代码 | |
||
ID标签
| 代码 | |
||
父ID标签
| 代码 | |
||
渲染Tree
| 方法 | Tree.prototype.render() | render | |
| 代码 | |
||
Treemap构造函数,继承自Chart
width 数字,图片宽度,默认为750,表示图片高750pxheight 数字,图片高度,默认为500showBackTag 布尔值,回退操作导航条是否显示,默认为 true, 显示;设为false则不显示backHeight 数字,回退操作导航条宽度,默认为20level1BorderWidth 数字,一级方框的边框宽度,默认为1(1px),不建议修改level2BorderWidth 数字,二级方框的边框宽度,默认为1(1px),不建议修改fontSizeRatio 数字,表示图中文字大小。默认为1.0(1倍), 若设为2.0,字体大小会加倍;customEvent 函数对象,其中有4个自定义函数。leafNodeClick 函数,表示点击叶子节点的事件响应,默认为空函数; hoverIn 函数,表示鼠标移进方框的事件响应,默认为空函数; hoverOut 函数,表示鼠标移出方框的事件响应,默认为空函数; mouseover 函数,表示在方框内移动鼠标的事件响应,默认为设置浮框的内容,可以替换它修改浮框内容; 这些函数可以在创建对象或setOption()时一起设置,也可以通过on函数单独设置。create treemap in a dom node with id "chart", width is 500; height is 600px;
var treemap = new Treemap("chart", {"width": 500, "height": 600});
| 声明 | Treemap | Treemap | |
| 参数 | node(Object) | The dom node or dom node Id | |
| 参数 | options(Object) | JSON object for determin treemap style | |
| 代码 | |
||
Create dom node relate to treemap
| 方法 | Treemap.prototype.createCanvas() | createCanvas | |
| 代码 | |
||
获取颜色
// 获取第二种颜色的渐变色。
{mode: "gradient", index: 1}
// 获取最深的离散色。
{mode: "random", ratio: 0}
// 获取最浅的离散色。
{mode: "random", ratio: 1}
// 获取适中的离散色。
{mode: "random", ratio: 0.5}
| 方法 | Treemap.prototype.getColor() | getColor | |
| 参数 | colorJson(Object) | Way to get color from color theme matrix | |
| 返回 | Array | 返回颜色数组 | |
| 代码 | |
||
设置数据源
treemap数据输入的格式可以是二维数组。例如下面的数组表示2000年4个季度的天数。
第1季度下面还列出了1-3月的天数。数组的第一行为四个固定的字符串"ID","name","size"和"parentID"。
四列数据分别表示层次数据集中各结点的ID,名称,大小和父节点ID。叶子节点必须有大小,根结点不能有父节点ID。各结点的ID、名称必须要有。
[
["ID", "name", "size", "parentID"],
[0, "2000", , ],
[1, "season1", , 0],
[2, "January", 31, 1],
[3, "February", 29, 1],
[4, "Match", 31, 1],
[5, "season2", 91, 0],
[6, "season3", 92, 0],
[7, "season4", 92, 0]
]
数据还可以是json格式。每个结点都有name,如果是父节点则还有children,如果为叶节点则还有size。以上数组数据对应的json数据如下:
{
"name": "2000",
"children": [
{
"name": "season1",
"children": [
{"name": "January", "size": 31},
{"name": "February", "size": 29},
{"name": "Match", "size": 31}
]
},
{"name": "season2", "size": 91},
{"name": "season3", "size": 92},
{"name": "season4", "size": 92},
]
}
| 方法 | Treemap.prototype.setSource() | setSource | |
| 参数 | source(Array,Object) | json or 2-d array | |
| 代码 | |
||
清除画布
| 方法 | Treemap.prototype.clearCanvas() | clearCanvas | |
| 代码 | |
||
计算布局,并重新渲染图表
| 方法 | Treemap.prototype.reRender() | reRender | |
| 代码 | |
||
计算布局位置,并渲染图表
| 方法 | Treemap.prototype.render() | render | |
| 代码 | |
||
设置自定义事件
| 方法 | Treemap.prototype.on() | on | |
| 代码 | |
||
constructor
| 声明 | StreamComponent | StreamComponent | |
| 参数 | the(node) | dom node or dom node Id | |
| undefined | undefined | undefined | undefined |
| 示例 | undefined | undefined | undefined |
| undefined | undefined | undefined | undefined |
| undefined | undefined | undefined | undefined |
| 代码 | |
||