我正在使用 Yii2 扩展 miloschuman/yii2-highcharts对于图表和将 php 数组传递到 hightcharts 感到困惑。
我的数组值
Array
(
[Power Electronics] => 14.00
[Introduction to Programming] => 3.92
[Data base Management System] => 3.28
[Object Oriented Analysis and Design] => 1.96
)
现在只是我想将此数据添加到我的 Highcharts 中,我正在像下面的代码一样在数组上方传递。
来 self 的 HIGHCHARTS 代码
'series' => [
[
"name" => "Exam Results",
"data" => $course_data,
'dataLabels' => [
'enabled' => true,
'rotation' => -90,
'color' => '#FFFFFF',
'align' => 'right',
'format' => '{point.y:.1f}', // one decimal
'y' => 10, // 10 pixels down from the top
'style' => [],
'fontSize' => '13px',
'fontFamily' => 'Verdana, sans-serif',
],
],
],
我已经尝试了很多东西但没有取得任何成功我想要像 this charts 这样的输出.
最佳答案
您是否尝试过调用 json_encode
函数并将提到的数组作为参数传递?这是代码:
<?php
$data = [
['Power Electronics', 14.00],
['Introduction to Programming', 3.92],
['Data base Management System', 3.28],
['Object Oriented Analysis and Design', 1.96],
];
echo json_encode($data);
[编辑]
您也可以尝试使用 SeriesDataHelper
功能。文档中有关于使用它的信息,这里是链接:https://github.com/miloschuman/yii2-highcharts/blob/master/doc/examples/series-data-helper.md#using-numerically-indexed-data
示例代码如下:
use miloschuman\highcharts\SeriesDataHelper;
$data = $data = [
['Power Electronics', 14.00],
['Introduction to Programming', 3.92],
['Data base Management System', 3.28],
['Object Oriented Analysis and Design', 1.96],
]
'series' => [
[
"name" => "Exam Results",
"data" => new SeriesDataHelper($course_data, ['0:name', '1:y']),
'dataLabels' => [
'enabled' => true,
'rotation' => -90,
'color' => '#FFFFFF',
'align' => 'right',
'format' => '{point.y:.1f}', // one decimal
'y' => 10, // 10 pixels down from the top
'style' => [],
'fontSize' => '13px',
'fontFamily' => 'Verdana, sans-serif',
],
],
],
关于javascript - Yii2 如何将 php 数组数据传递到 highcharts,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51725438/