饼图未在HIghChart中附带动态数据

时间:2015-02-10 15:00:05

标签: javascript json charts highcharts

我正在制作一个带有json数据的饼图,但饼图不带有数据后端数据。我使用这种格式生成数据,这实际上是HighCharts给出的格式。我正在粘贴我的代码

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获取的数据在这里给出。但是当我动态使用它时,arrRevenue无效。我已经尝试了所有语法。但是没有用。有人请帮助。

1 个答案:

答案 0 :(得分:0)

问题在于生成数据。需要两个更改:

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