0

データベースから 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]
                 }
                     ]
            }]

何か案が?

4

1 に答える 1

0

データとして配列を返す即時呼び出し関数式 (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;
 })()
于 2013-05-28T21:00:11.543 に答える