在官网看到的例子
给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 } });
时间: 2024-11-09 04:34:48