2015-02-10 129 views
0

我正在制作一个饼图与JSON数据,但饼图没有与数据后端数据来。我生成的格式,这实际上是由HighCharts格式的数据。我贴我的代码饼图没有与动态数据来在HIghChart

function createChart(array){ 
//alert(array); 
var arrJobName = []; 
var arrRevenue = []; 

for(var i=0; i<array.length; i++){ 
    searchResultArray = array[i].split("$$##$$##"); 

    //var label = '\''+ searchResultArray[1]+ '\''; 
    //var value = parseInt(searchResultArray[5]); 

    //arrJobName.push(searchResultArray[1]); 
    //arrRevenue.push(parseInt(searchResultArray[5])); 
    //alert(parseFloat(searchResultArray[5])) 
    // arrRevenue.push(['\''+ searchResultArray[1]+ '\'',""(parseFloat(searchResultArray[5]))]); 

    arrRevenue.push('['+searchResultArray[1]+","+parseFloat(searchResultArray[5])+']'); 

} 

alert(arrRevenue) 
// 

$(function() { 
    $('.containerForDiagram').highcharts({ 
     chart: { 
      plotBackgroundColor: null, 
      plotBorderWidth: null, 
      plotShadow: false 
     }, 
     title: { 
      text: 'Browser market shares at a specific website, 2014' 
     }, 
     tooltip: { 
      pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>' 
     }, 
     plotOptions: { 
      pie: { 
       allowPointSelect: true, 
       cursor: 'pointer', 
       dataLabels: { 
        enabled: true, 
        format: '<b>{point.name}</b>: {point.percentage:.1f} %', 
        style: { 
         color: (Highcharts.theme && Highcharts.theme.contrastTextColor) || 'black' 
        } 
       } 
      } 
     }, 
     series: [{ 
      type: 'pie', 
      name: 'Job By Revenue', 
      data: [ 

        [arrRevenue] 
//['Director - Inventory/Planning Systems',36800],['DevOps Engineer',20000], ['Java Developer',0],['Software Development Manager',0],['Sr. Business Analyst/Oracle Functional',0],['Product Manager Native Advertising',0],['Corporate Recruiter ',26000],['Sr. Oracle Supply Chain BA',0],['Network Engineer',0],['Sharepoint Programmer Analyst',0],['Commercial Manager - Mexico',0],['Commercial Manager Colombia',0],['Sr. Global Architect - End User Computing',29900],['Head of Marketing Peru',0],['Director, Sr Attorney',0] 

this is the data i am getting with my code     ] 


     }] 
    }); 
}); 

} 

我得到了arrRevenue数据给出here.But当我使用它dynamically.I已经尝试了所有syntax.But没有用的仍然是arrRevenue不工作.Somebody请帮帮我。

+0

两件事:1)所有数目应是数字,例如:'“2 “'是一个字符串。 2)'arrRevenue.push('['+ ...']')'产生字符串。你想使用数组。我建议你去MDN(mozilla开发网络),并开始阅读关于JS的教程。 – 2015-02-10 15:19:41

+0

@PawełFus那么我将如何使数据格式['Level',12]? – lucifer 2015-02-10 17:36:34

+1

就像这样:'data:arrRevenue',其中'arrRevenue'是这样写的:''arrRevenue.push([searchResultArray [1],parseFloat(searchResultArray [5])]);' – 2015-02-10 18:33:23

回答

0

问题在于生成数据。需要有两个变动:

  • 数据分配:data: [arrRevenue] - >data: arrRevenue
  • 数据生成:arrRevenue.push('['+searchResultArray[1]+","+parseFloat(searchResultArray[5])+']'); - >arrRevenue.push([ searchResultArray[1], parseFloat(searchResultArray[5]) ]);