我试图通过数据提供者将数据从数据库放到高级图的“系列”中。我使用this小部件。现在图表已呈现,但我有类别的另一个问题,您可以在printscreen上看到。
我猜print_r
看起来不错:
我该如何解决这个问题?
$data = $provider->getModels();
$barData = array();
$xAxis = array();
if(is_array($data)) {
foreach ($data as $row) {
$barData[] = [
'name' => $row['strategy_title'],
'data' => [(float) $row['strategy_current_money']]
];
$xAxis[] = [
'categories' => $row['strategy_title'],
];
}
}
试试这样吧。我不确定我是否理解得很好但是我想帮忙。我用[]解决了你的第一个问题。对于其他问题,您必须更具体。
经过几个小时的阅读后,我决定回到文档,我找到了我的问题qazxsw poi的解决方案
https://github.com/miloschuman/yii2-highcharts/blob/master/doc/examples/series-data-helper.md
<?php
use yii\helpers\Html;
use yii\helpers\ArrayHelper;
use yii\helpers\Url;
use miloschuman\highcharts\Highcharts;
use miloschuman\highcharts\SeriesDataHelper;
/* @var $this yii\web\View */
$data = $provider->getModels();
$dataProvider = new \yii\data\ArrayDataProvider(['allModels' => $data]);
?>
<div class="container">
<div class="row">
<div class="col-md-12 col-sm-12 strategy_bar">
<?php
echo Highcharts::widget([
'options' => [
'title' => ['text' => 'Basic Example'],
'yAxis' => [
['title' => [
'text' => 'OHLC'
]
],
],
'series' => [
[
'type' => 'column',
'name' => new SeriesDataHelper($dataProvider, ['strategy_title']),
'data' => new SeriesDataHelper($dataProvider, ['strategy_current_money:int']),
],
]
]
]);
?>
</div>
</div>
</div>