1

I want to create dual axes Highchart like as seen in image and i have install miloschuman\highcharts\Highcharts extension.

enter image description here

My yii2 code

<?php
    use miloschuman\highcharts\Highcharts;

    $emp = ['zxc', 'sdf', 'fgh', 'ggg'];
    $totalData[] = ['name' => 'Total',  'type' => 'column', 'data' => [23,45,34,34]];
    $avgData[] = ['name' => 'Avarage', 'type' => 'spline', 'data' => [2.3,4.5,3.4,3.0]];
    echo Highcharts::widget([
            'options' => [  
                'chart'=>[
                    //'type'=>'column', 
                    'zoomType' => 'xy',
                ],
                'exporting'=>[
                    'enabled'=>false, 
                ],
                'credits'=>[
                        'enabled'=>false,
                ],
                'title'=>[
                    'text'=>Yii::t('comm', $model->fg_name),
                ],
                'subtitle'=>[
                    'text'=>'',
                    'margin'=>0,
                ],
                'xAxis'=>[
                    'type' => 'category',
                    'labels' => [
                        'rotation' => -45,
                        'style' => [
                            'fontSize' => '13px',
                            'fontFamily' => 'Verdana, sans-serif'
                        ]
                    ],
                    'categories'=> $emp,
                    'title'=>[
                        'text'=>'<b>'.Yii::t('comm', 'Employee').'</b>',
                    ],
                ],
                'yAxis'=>[
                    'title'=>[
                        'text'=>Yii::t('comm', 'TOTAL/AVARAGE'),
                    ],  
                ],
                'legend' => [
                    'enabled' => false
                ],
                'plotOptions'=>[
                     'column'=>[
                        'pointPadding'=>0.2,
                        'borderWidth'=>0
                     ],
                ],
                'series'=> [$avgData,$totalData]
                ],
        ]);
?>

1 Answer 1

1

I use 2amigos highcharts, but I'm sure the process is the same, here is a recent sample I used to generate my dual axis chart:

'yAxis' => [ // primary axis
        [
          'title' => [
              'text' => 'Weeks'
          ],
          'tickInterval' => 5,
      ],
      [ // secondary axis
        'gridLineWidth' => 0,
        'title' => [
            'text' => '%'
        ],
        'max' => 100,
        'min' => 0,
        'opposite' => true,
      ]
    ],

My series ended up like this:

'series' => [$series,$line, $percent]

They were themselves arrays: Here is an example of one of the arrays, where you can state which axis the data belongs to, in my case and I guess yours yAxis will be 0 or 1. Change the type to whatever you like, this array was a column, but others wine splines

 $series Array
(
[name] => 90th Percentile
[type] => column
[yAxis] => 0
[tooltip] => Array
    (
        [valueSuffix] =>  Weeks
    )

[data] => Array
    (
        [0] => 16.86
        [1] => 11.29
        [2] => 13.86
        [3] => 32.14
        [4] => 17.71
        [5] => 7.57
        [6] => 19
        [7] => 37.57
        [8] => 10.14
        [9] => 5.43
        [10] => 7.14
        [11] => 31.57
        [12] => 17.52
    )

)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.