yii2 highCharts中如何传递数据库数据并显示?
How to pass the database data and display it in yii2 highCharts?
我已经安装了 miloschuman\highcharts\Highcharts,网站:https://www.yiiframework.com/extension/yii2-highcharts-widget。我有一个包含 table 列 lme_price 和 lme_name 的数据库,我想显示价格highcharts 中的铜。我正在使用 PHP.
下面是我完成的代码。这是我模型中的代码。我创建了一个静态函数,其中包含查询,以从数据库中找到我想要的数据。
public static function getCopperPrice()
{
$getCopperPrices = Lme::find()
->select('lme_price')
->where(['lme_name' => 'LME Copper'])
->all();
return $getCopperPrices;
}
这是我在视图中的代码。我在视图中有一个 table 显示,它显示了数据库中的每个数据。
<div class="lme_index">
<?= GridView::widget([
'dataProvider' => $dataProvider,
// 'searchModel'=> $searchModel,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
[
'label'=> 'DATE',
'attribute' => 'lme_title',
],
[
'label'=> 'MATERIAL',
'attribute'=> 'lme_name',
],
[
'label'=> 'PRICE (US$)',
'attribute'=> 'lme_price',
],
['class' => 'yii\grid\ActionColumn'],
],
]); ?>
这是 highcharts 图表的代码。
<div class = "graph">
<?= Highcharts::widget([
'options' => [
'title' => ['text' => 'Copper Price'],
'xAxis' => [
'categories' => []
],
'yAxis' => [
'title' => ['text' => 'Price $US']
],
'plotOption' => [
'series' => [
['name' => 'Copper',
'data' => [lme::getCopperPrices()]],
]
]
]
]);?>
我只想在高位图表中显示 1 个 material 价格。我从系列中的模型调用函数,但图表上没有显示任何内容。那里的编码没有向我显示任何错误。
有人可以帮助我或告诉我如何解决这个问题吗?谢谢
图表需要显示 integer
个值
public static function getCopperPrice()
{
$cooperPrices = [];
$copperPriceList = Lme::find()
->select('lme_price')
->where(['lme_name' => 'LME Copper'])
->column();
foreach($copperPriceList as $price) {
$cooperPrices[] = (int) price;
}
return $cooperPrices;
}
我已经安装了 miloschuman\highcharts\Highcharts,网站:https://www.yiiframework.com/extension/yii2-highcharts-widget。我有一个包含 table 列 lme_price 和 lme_name 的数据库,我想显示价格highcharts 中的铜。我正在使用 PHP.
下面是我完成的代码。这是我模型中的代码。我创建了一个静态函数,其中包含查询,以从数据库中找到我想要的数据。
public static function getCopperPrice()
{
$getCopperPrices = Lme::find()
->select('lme_price')
->where(['lme_name' => 'LME Copper'])
->all();
return $getCopperPrices;
}
这是我在视图中的代码。我在视图中有一个 table 显示,它显示了数据库中的每个数据。
<div class="lme_index">
<?= GridView::widget([
'dataProvider' => $dataProvider,
// 'searchModel'=> $searchModel,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
[
'label'=> 'DATE',
'attribute' => 'lme_title',
],
[
'label'=> 'MATERIAL',
'attribute'=> 'lme_name',
],
[
'label'=> 'PRICE (US$)',
'attribute'=> 'lme_price',
],
['class' => 'yii\grid\ActionColumn'],
],
]); ?>
这是 highcharts 图表的代码。
<div class = "graph">
<?= Highcharts::widget([
'options' => [
'title' => ['text' => 'Copper Price'],
'xAxis' => [
'categories' => []
],
'yAxis' => [
'title' => ['text' => 'Price $US']
],
'plotOption' => [
'series' => [
['name' => 'Copper',
'data' => [lme::getCopperPrices()]],
]
]
]
]);?>
我只想在高位图表中显示 1 个 material 价格。我从系列中的模型调用函数,但图表上没有显示任何内容。那里的编码没有向我显示任何错误。
有人可以帮助我或告诉我如何解决这个问题吗?谢谢
图表需要显示 integer
个值
public static function getCopperPrice()
{
$cooperPrices = [];
$copperPriceList = Lme::find()
->select('lme_price')
->where(['lme_name' => 'LME Copper'])
->column();
foreach($copperPriceList as $price) {
$cooperPrices[] = (int) price;
}
return $cooperPrices;
}