How to provide data to Animated time-line pie amcharts?

旧城冷巷雨未停 提交于 2019-12-11 15:27:33

问题


I am trying to push data dynamically during runtime for the Animated Time-Line Pie Chart

Here is the code:

var array = new Array();
function pushvalue(curyear,curmonth,monvalue){
        array.push({year: curyear, month: curmonth, count: moncount});
}
var chartdata = new Array();
for (var i=1; i < array.length; i++){
     chartdata = {
             “Year”: array[i].year: [
                          { “Month”: array[i].month, “Count”: array[i].count }, ] };
}

The value for array is got from input from file. The problem I get is the chartdata can’t get the value assigned to it with the objects year, it shows error as expected a ‘}’ or syntax error if I include or exclude ‘:’ after the ”Year”: array[i].year

May I know what am I doing wrong and how to fix it? Thank you!


回答1:


The syntax for assigning a new year is wrong. You can't do "Year": varname: [ ... ] in one line. You'll want to change it to something like this:

for (var i = 0; i < array.length; ++i) {
  if (!chartData[array[i].year]) {
    chartData[array[i].year] = [];
  }
  chartData[array[i].year].push({"Month": array[i].month, "Count": array[i].count });
}

Demo using some fake values: http://jsfiddle.net/9428r6fw/4/

Also note that your pushvalue method is wrong - your parameter for the count is named monvalue but you're trying to push moncount



来源:https://stackoverflow.com/questions/46475345/how-to-provide-data-to-animated-time-line-pie-amcharts

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!