在Highcharts中使用渐变填充将JSON数据导出到饼图中生成问题


Generating Issues in Export JSON Data to Pie with gradient fill in Highcharts

我正在使用json、php和mysql查询从Highcharts创建一个带有渐变填充图的Pie。通过firebug控制台进行调试,但没有错误,也没有显示图形。我正在创建一个静态图[链接]http://jsfiddle.net/sunman/YKE2P/10/像这样,我想用json和mysql动态创建它。这是我的问题,我的json数据无法生成图形。下面是我的代码。我的json数据显示如下:

   [{"name":{"MOZILA":45.0}},{"name":{"IE":26.8}},{"name":{"CHROME":12.8}},{"name":{"OPERA":6.2}},{"name":{"OTHERS":9.2}}]

index.php:

$(function () {
    // Radialize the colors
    Highcharts.getOptions().colors = Highcharts.map(Highcharts.getOptions().colors, function(color) {
        return {
            radialGradient: { cx: 0.5, cy: 0.3, r: 0.7 },
            stops: [
                [0, color],
                [1, Highcharts.Color(color).brighten(-0.3).get('rgb')] //   darken
            ]
        };
    });
    // Build the chart
    $('#container').highcharts({
        chart: {
            plotBackgroundColor: null,
            plotBorderWidth: null,
            plotShadow: false
        },
        title: {
            text: ' Rate of a specific project'
        },
        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'
                    },
                    connectorColor: 'silver'
                }
            }
        },
        series: [{
            type: 'pie',
            name: 'Total without cost',
            data:[]
        }]
      });
      $.getJSON("data.php", function(json) {
          //options.series.push(data);
                    options.series[0].data = json;
          chart = new Highcharts.Chart(options);
      });
 });

data.php:

   $sql="SELECT mozila,ie,chrome,opera,safari,torch FROM webmarketing";
   $resultSql = mysql_query($sql);
   $result = array();
   while($rows=mysql_fetch_array($resultSql)) {
   $arr['name'] = array('MOZILA' => $rows['mozila']);
   $arr1['name']= array('IE' => $rows['ie']);
   $arr2['name'] = array('CHROME' => $rows['chrome']);
   $arr3['name']= array('OPERA' => $rows['opera']);
   $arr4['name'] = array('OTHERS' => $rows['safari']+$rows['torch']);
    }
     array_push($result,$arr);
     array_push($result,$arr1);
    array_push($result,$arr2);
    array_push($result,$arr3);
    array_push($result,$arr4);
   print json_encode($result, JSON_NUMERIC_CHECK);

所以请你帮忙我的代码哪里错了。我想把这种类型的图与动态链接起来。我不知道json代码。所以请你向我提出这个问题。

问题就在这里:

  $.getJSON("data.php", function(json) {
    options.series.push(data);
    chart = new Highcharts.Chart(options);
  });

你正在添加新的系列,它有一些奇怪的格式。。我建议使用它:

  $.getJSON("data.php", function(json) {
    options.series[0].data = json;
    chart = new Highcharts.Chart(options);
  });