From 4e288b9a4714cf2a366958d3f4e0b95f0f4088c8 Mon Sep 17 00:00:00 2001 From: Jackson Tian Date: Sat, 16 Feb 2013 11:16:27 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=B8=8D=E5=AF=B9=E6=A8=AA?= =?UTF-8?q?=E8=BD=B4=E6=95=B0=E6=8D=AE=E6=8E=92=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/charts/column.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/lib/charts/column.js b/lib/charts/column.js index 02af409..a24cf04 100644 --- a/lib/charts/column.js +++ b/lib/charts/column.js @@ -28,6 +28,7 @@ * - `formatLabel` 横轴提示格式化函数,传入横轴值,默认函数传出原始值 * - `formatYScale` 纵轴刻度格式化函数,传入纵轴刻度值 * - `formatValue` 值格式化函数 + * - `sortX` 是否将横轴数据排序,默认为true * * Examples: * ``` @@ -75,7 +76,8 @@ this.defaults.barWidth = 10; this.defaults.circleR = 3; - this.defaults.barColor = ["#308BE6","#8EEC00","#DDDF0D"]; + this.defaults.barColor = ["#308BE6", "#8EEC00", "#DDDF0D"]; + this.defaults.sortX = true; this.defaults.xTickNumber = 5; this.defaults.yTickNumber = 5; @@ -91,7 +93,6 @@ this.setOptions(options); this.createCanvas(); this.initEvents(); - } }); @@ -161,9 +162,12 @@ // 不指定列,将当前数据作为一列 this.columns = (typeof map.column === 'undefined') ? {column: dataTable} : _.groupBy(dataTable, map.column); var that = this; - _.each(this.columns, function (group, key) { - that.columns[key] = _.sortBy(group, map.x); - }); + // 排序横轴 + if (conf.sortX) { + _.each(this.columns, function (group, key) { + that.columns[key] = _.sortBy(group, map.x); + }); + } this.columnCount = _.keys(this.columns).length; conf.xAxisData = _.pluck(_.first(_.values(this.columns)), map.x); conf.xTickNumber = Math.min(conf.xAxisData.length, conf.xTickNumber);