Yii Highchart扩展 - 根据值更改颜色

时间:2016-09-01 02:42:03

标签: javascript php yii highcharts extension-methods

所以,我在Yii上使用这个highcharts扩展名。 我使用数据库(从我的控制器)获取数据。视图看起来像这样:

<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 widget格式。我认为这样做很容易,但似乎不起作用。我究竟做错了什么?

我试着说:

'colorByPoint' => true,

zones =>之上,颜色会按点变化,但不会按照我想要的值变化。我也将它放在series数组下,但它也不起作用。

1 个答案:

答案 0 :(得分: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