A
A
Alexander2017-12-10 20:37:15
Yii
Alexander, 2017-12-10 20:37:15

YII2 Highcharts how to build from model?

There is a graph with various data:
6c126c7260.png
how to build such a graph from the model? Now it is formed from an array and not quite beautiful:

$resultData = [];
                foreach ($tmpKeys as $key) {
                    $positions = [];
                    foreach ($tmpData as  $val) {
                            $positions[] = val;
                    }
                    $resultData[] = [
                        'name' => $key,
                        'data' => $positions
                    ];
                }


echo  <?= Highcharts::widget([
                'options' => [
                    'title' => ['text' => 'Title'],
                    'xAxis' => [
                        'categories' => $resultDate
                    ],
                    'yAxis' => [
                        'title' => ['text' => 'Position'],
                        'labels' => [
                            'step' => 1,
                        ]
                    ],
                    'series' => $resultData
                ]
            ]); ?>

in the database they are like date|key|val
date x-axis
val y -axis
key - point
I would like to form a graph from the model without enumerating the data.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
Lander, 2017-12-11
@usdglander

What prevents you from putting foreach into the model's getResultData() method and writing something like

...
'series' => $model->resultData
...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question