我正在使用Yii2扩展名miloschuman/yii2-highcharts来绘制图表,并且将php数组传递到图表中感到困惑。
我的数组值
Array
(
[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" => $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。
答案 0 :(得分:1)
您是否尝试过将提到的数组作为参数传递来调用const event = new Date('August 19, 1975 23:15:30');
console.log(event.toString());
// expected output: Tue Aug 19 1975 23:15:30 GMT+0200 (Central European Standard Time)
函数?这是代码:
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);
功能。在文档中有有关使用它的信息,这里是链接:https://github.com/miloschuman/yii2-highcharts/blob/master/doc/examples/series-data-helper.md#using-numerically-indexed-data
这是示例代码:
SeriesDataHelper
答案 1 :(得分:0)
根据文档,您的数组格式无效。看起来应该像他的:
$data = [
['Power Electronics', 14.00],
['Introduction to Programming', 3.92],
['Data base Management System', 3.28],
['Object Oriented Analysis and Design', 1.96],
];
您可以使用简单的foreach来解决此问题:
$newData = [];
foreach ($data as $key => $value) {
$newData[] = [$key, $value];
}