簡體   English   中英

餅圖的動態數據輸入

[英]Dynamic data input for pie chart

我正在從數據庫中獲取值到javascript數組。 我用來創建具有靜態值的餅圖的Javascript代碼如下。

        $(function () {
        $('#container').highcharts({
            chart: {
                type: 'pie'
            },

            plotOptions: {
                pie: {
                    dataLabels: {
                        distance: -30,
                        color: 'white'
                    }
                }
            },

            series: [{
                data: [
                    [test[0],   44.2],
                    [test[1],       26.6],
                    [test[2],       20],
                    [test[3],    3.1],
                    [test[4],    5.4]
                ]
            }]
        });
    });

我希望我的數據像

             series: [{
                data: [
                  for (var i=0;i<count;i++)
                 { 
                        [test[i],   44.2]
                 }
                     ]
            }]

任何想法?

您可以使用立即調用的函數表達式(IIFE),該函數表達式將數組作為數據返回。 就像是:

 data: (function() {
     var d = [];
     for (var i=0; i < count; i++) {
         d.push([test[i],44.2]);     // it's not clear from your question where the second number is supposed to come from!
     }
     return d;
 })()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM