【问题标题】:Highchart and yii not drawing a pieHighchart 和 yii 不画馅饼
【发布时间】:2013-04-30 14:44:20
【问题描述】:

这段代码实际上只画了标题

它像 yii 扩展一样使用 Highcharts

<?php $this->Widget('ext.highcharts.HighchartsWidget', array(
   'options'=>array(
        'title' => array('text' => 'Grafico a torta'),
        'chart' => array('renderTo' =>'charts'),
        'credits' => array('enabled' => false),
        'series' => array (
            'type' => 'pie',
            'name' => 'name of serie',
            'data' => array (
                array('Firefox', 44.2),
                array('IE7', 26.6),
                array('IE6', 20),
                array('Chrome', 3.1),
                array('Other', 5.4)
            ),
        ),
   )
));

?>

它创建了这个 javascript

jQuery(window).on('load',function() {
var chart = new Highcharts.Chart(
    {'chart':{'renderTo':'charts'},
     'exporting':{'enabled':true},
     'title':{'text':'Grafico a torta'},
     'credits':{'enabled':false},
     'series':{
           'type':'pie',
           'name':'name of serie',
           'data':[
                ['Firefox',44.2000000000000028],
                ['IE7',26.6000000000000014],
                ['IE6',20],
                ['Chrome',3.1000000000000001],
                ['Other',5.4000000000000004]
           ]}});
});

我无法理解出了什么问题....没有抛出 js 错误,没有控制台调试信息,什么都没有......

我错过了什么?

【问题讨论】:

    标签: php yii highcharts


    【解决方案1】:

    检查你的系列:

    series:**[**{
               type:'pie',
               name:'name of serie',
               data:[
                    ['Firefox',44.2000000000000028],
                    ['IE7',26.6000000000000014],
                    ['IE6',20],
                    ['Chrome',3.1000000000000001],
                    ['Other',5.4000000000000004]
               ]}**]**
        });
    

    您在系列中缺少 []。检查这个:http://jsfiddle.net/tqVF8/9/

    【讨论】:

    • 这意味着系列部分需要另一个数组
    【解决方案2】:

    对系列再次使用数组

    section =>
       'series' => array (
            array (
              'type' => 'pie',
              'name' => 'Browser share',
              'data' => array (
               array('Firefox', 44.2),
               array('IE7', 26.6),
               array('IE6', 20),
               array('Chrome', 3.1),
               array('Other', 5.4)
            ),
        ),
    ),        
    

    它对我有用。

    【讨论】:

      【解决方案3】:

      在这个数据中是事件数的数组。

      <?php
      
      $this->Widget('application.extensions.highcharts.HighchartsWidget',
      array('options'=>array( 'title'=>array('text'=>'User Distribution'),
                              'tooltip'=>array('formatter'=> 'js:function() { 
              return "<b>"+this.point.name+"</b>: "+Math.round(this.percentage)+"%"
                }'),
      
      'credits' => array('enabled' => true),
      'exporting' => array('enabled' => true),
      'plotOptions'=>array('pie'=> array('allowPointSelect'=>true,'cursor'=>'pointer',
                                                                                                  'dataLabels'=>array('enabled'=>true),
                                                                                                  'showInLegend'=>true)
                                                                              ),
                                                          'series' =>                           array(array('type'=>'pie',                                                             'name'=>'User Distrubution',
                                                                                  'data' => $data,)
                                                                          )
                                                          )
                                          )
                              );
      

      ?>

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多