2013-02-25 65 views
1

下面我的代码:Highchart馅饼 - 动态数组动态馅饼

$(document).ready(function() { 
    for(var j = 0; j < productsSize; j++) { 
     //tmStringToDisplay.push(name[j], parseInt(percent[j])); 
     var tmStringToDisplay = [name[j], parseInt(percent[j])]; 
     tmStringToDisplay.push(temp); 
    } 
    console.log(tmStringToDisplay); 

    chart = new Highcharts.Chart({ 
     chart: { 
      renderTo: 'container', 
      plotBackgroundColor: null, 
      plotBorderWidth: null, 
      plotShadow: false 
     }, 
     title: { 
      text: 'The best selling products :' 
     }, 
     tooltip: { 
      pointFormat: '{series.name}: <b>{point.percentage}%</b>', 
      percentageDecimals: 1 
     }, 
     plotOptions: { 
      pie: { 
       allowPointSelect: true, 
       cursor: 'pointer', 
       dataLabels: { 
        enabled: true, 
        color: '#000000', 
        connectorColor: '#000000', 
        formatter: function() { 
         return '<b>'+ this.point.name +'</b>: '+ this.percentage +' %'; 
        } 
       } 
      } 
     }, 



     series: [{ 
      type: 'pie', 
      name: 'Product share', 
      data: tmStringToDisplay 
     }] 
    }); 

我不得不作出了“tmStringToDisplay”选项卡,把它在系列阵列的数据变种。 在一成不变的,它是这样的:

series: [{ 
      type: 'pie', 
      name: 'Browser share', 
      data: [ 
       ['Firefox', 45.0], 
       ['IE',  26.8], 
       { 
        name: 'Chrome', 
        y: 12.8, 
        sliced: true, 
        selected: true 
       }, 
       ['Safari', 8.5], 
       ['Opera',  6.2], 
       ['Others', 0.7] 
      ] 
     }] 

这是在回路的所有工作:

for(var j = 0; j < productsSize; j++) { 
     //tmStringToDisplay.push(name[j], parseInt(percent[j])); 
     var tmStringToDisplay = [name[j], parseInt(percent[j])]; 
     tmStringToDisplay.push(temp); 
    } 

我要创建和准备“tmStringToDisplay”这就需要像静示例....

谢谢!

+0

[你有什么试过](http://whathaveyoutried.com)这个家庭作业? – 2013-02-25 00:38:44

回答

1

解析tmStringToDisplay到JSON

例如 jQuery.parseJSON(tmStringToDisplay);