在官網看到的例子 給chart添加一個排序功能的handler 配置chart(根據orderByField這個欄位進行排序) ...
在官網看到的例子
給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 } });