码迷,mamicode.com
首页 > 编程语言 > 详细

AmCharts 对数据排序后展示

时间:2017-07-08 15:17:43      阅读:164      评论:0      收藏:0      [点我收藏+]

标签:uefi   ati   color   category   orderby   star   serial   ==   fine   

在官网看到的例子

给chart添加一个排序功能的handler

 1 AmCharts.addInitHandler( function(chart){
 2     if (chart.orderByField === undefined){
 3         return;
 4     }
 5     chart.dataProvider.sort(function(a,b){
 6         if (a[ chart.orderByField ] > b[ chart.orderByField ]){
 7             return -1;
 8         }
 9         else if ( a[ chart.orderByField ] == b[ chart.orderByField ]){
10             return 0;
11         }
12         return 1;
13     });
14 }, ["serial"]);

配置chart(根据orderByField这个字段进行排序)

var chart = AmCharts.makeChart( "chartdiv", {
  "type": "serial",
  "theme": "light",
  "dataProvider": data,
  "categoryField": "key",
  "sortColumns": true,
  "orderByField": "doc_count",
  "graphs": [ {
    "balloonText": "[[category]]: <b> [[value]] </b>",
    "valueField": "doc_count",
    "fillColorsField": "color",
    "fillAlphas": 0.9,
    "fillAlpha": 0.2,
    "type": "column"
  } ],
  "categoryAxis": {
    "gridPosition": "start",
    "labelRotation": 45
  }
});

 

AmCharts 对数据排序后展示

标签:uefi   ati   color   category   orderby   star   serial   ==   fine   

原文地址:http://www.cnblogs.com/blaketairan/p/7136782.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!