2016-09-01 31 views
0

因此,我在Yii上使用此highcharts擴展。 我使用數據庫(從我的控制器)獲取數據。並且認爲是這樣的:Yii Highchart擴展 - 根據值更改顏色

<div class="hero-unit" id="content" style="position:relative;border: solid green"> 
<div style="max-width:100%;overflow:auto;"> 
    <div style="width:2200px;"> 
     <center> 
      <?php 
      $label = array(); //inisiasi label axis 
      $nilai = array(); //inisiasi nilai data 
      foreach ($dataProvider3->getData() as $i => $ii) { 
       $label[$i] = array($ii['no'] . '. ' . $ii['namapek']);//this is fetched from SQL syntax in controller 
       $nilai[$i] = (float) $ii['pek']; //this is fetched from SQL syntax in controller 
      } 
      $this->widget('application.extensions.highcharts.HighchartsWidget', array(
       'scripts' => array(
        'modules/exporting', 
        'themes/epcGray', 
        'highcharts-more', 
       ), 
       'options' => array(
        'chart' => array('defaultSeriesType' => 'column', 'backgroundColor' => 'rgba(255, 255, 255, 0.1)'), 
        'title' => FALSE, 
        'legend' => array(
         'enabled' => false, 
        ), 
        'xAxis' => array(
         'categories' => $label, 
        ), //nama axis 
        'yAxis' => array(
         'min' => 0, 
         'title' => array(
          'text' => 'Percentage' 
         ), 
        ), 
        'series' => array(
         array('data' => $nilai)//data, 
        ), 
        'tooltip' => array(
         'formatter' => 'js:function() {return "<b>Step "+ this.x +"</b><br/>" + "Finished: "+ Highcharts.numberFormat(this.y, 2) +"%"; }', 
        ), 
        'plotOptions' => array(
         'column' => array(
          'zones' => 
          array('value' => 50, 'color' => '#EB4011'), 
          array('value' => 120, 'color' => '#aaff99'), 
         ), 
         'series' => array(
          'point' => array(
           'events' => array(
            'click' => 'js:function() { 
           var cat = this.category; 
           var res = parseInt(cat, 10); 
           window.open ("index.php?r=reports/rinci&id=" + res); }', 
           ) 
          ), 
         ) 
        ), 
        'credits' => array('enabled' => false), 
       ) 
      )); 
      ?> 
     </center> 
    </div> 
</div> 

,我發現這個答案here有關更改基於價值的條的顏色。但它是json格式,我需要使用它的Yii小部件格式。我認爲這很容易做到,但似乎並不奏效。我究竟做錯了什麼?

我試圖把這樣的:

'colorByPoint' => true, 

以上的zones =>啄,顏色由點改變,但沒有價值我希望他們。我也把它放在series數組下,但它也不起作用。

回答

0

所以我嘗試了很多東西來使它工作。但是它似乎是擴展本身的缺陷。

所以我直接在我的視圖上使用highchart js文件。這工作正常。任何人都面臨同樣的問題,我建議如果它缺少太多有用的功能,就離開這個擴展。

這些都是必需的js文件:

<script src="https://code.highcharts.com/highcharts.js"></script> 
<script src="https://code.highcharts.com/modules/data.js"></script> 
<script src="https://code.highcharts.com/modules/drilldown.js"></script> 

使用的例子here