如何在AmCharts中自定义图例项目?

时间:2016-11-29 18:54:01

标签: amcharts

有没有简单的方法来自定义图例项而不是重写数据集或创建自定义图例功能?

http://i.imgur.com/U2wjwQu.png

我希望他们按此顺序显示

http://i.imgur.com/8ZBOh5P.jpg

1 个答案:

答案 0 :(得分:0)

结束循环数据本身。

// new array for repopulating
var new_array = new Array();
// new key order
var new_order = ['Year', 'RENEWABLE POWER PLANTS', 'NUCLEAR POWER PLANTS', 'FOSSIL POWER PLANTS W/CCS', 'BIOFUELS', 'SYNTHETIC FUELS', 'VEHICLES', 'BUILDING TECHNOLOGIES', 'OTHER EFFICIENCY', 'OTHER', 'NATURAL GAS', 'COAL', 'PETROLEUM PRODUCTS', 'FOSSIL POWER PLANTS'];
// for each row in 'data'
for (i = 0; i < data.length; i += 1) {
  var new_data = {};
  // go through the 'new order' array
  for (z = 0; z < new_order.length; z += 1) {
    // re-order the keys in a new array
    new_data[new_order[z]] = data[i][new_order[z]];
  }
  // add the row to a new array
  new_array.push(new_data);
}
// replace data with the new array
data = new_array;