I have a data array's like this. and I want to make this data into grafik. and the problem is when i put the script
if (isset($b['admin'])) {
echo $b['admin'];
$series = $this->HighCharts->addChartSeries();
$series->addName($user)->addData([(int)$b['admin']]);
$mychart->addSeries($series);
}
in the foreach($datas as $a){. why the date_part 3 couldn't be show?
QUERY RESULT ARRAY
$array = array(
(int) 0 => array(
'B' => array(
'company' => 'ABC'
),
'User' => array(
'company' => 'abc'
),
(int) 0 => array(
'date_part' => '3',
'jumlah' => null,
'jumbuy' => '50990',
'admin' => '50010'
)
),
(int) 1 => array(
'B' => array(
'company' => 'BCD'
),
'User' => array(
'company' => 'bcd'
),
(int) 0 => array(
'date_part' => '3',
'jumlah' => null,
'jumbuy' => '65000',
'admin' => '5000' )
),
(int) 2 => array(
'B' => array(
'company' => 'ABC'
),
'User' => array(
'company' => 'abc'
),
(int) 0 => array(
'date_part' => '4',
'jumlah' => null,
'jumbuy' => '98990',
'admin' => '2010' )
),
(int) 3 => array(
'B' => array(
'company' => 'CDE'
), 'User' => array(
'company' => 'cde'
),
(int) 0 => array(
'date_part' => '4',
'jumlah' => null,
'jumbuy' => '34566',
'admin' => '2010' )
),
(int) 4 => array(
'B' => array(
'company' => 'BCD'
),
'User' => array(
'company' => 'bcd'
),
(int) 0 => array(
'date_part' => '4',
'jumlah' => null,
'jumbuy' => '9000',
'admin' => '5000' )
),
);
IN CONTROLLERS
$chartName = 'Line Chart with Data Labels';
$tooltipFormatFunction = <<<EOF
function() { return '<b>'+ this.series.name +'</b><br/>'+ this.x +': '+ this.y +'°C';}
EOF;
$mychart = $this->HighCharts->create($chartName, 'line');
$data = array();
foreach($report_posts as $values) {
if (!isset($data[$values['User']['company']])) {
$data[$values['User']['company']] = $values;
} else {
$last_element = array_pop($values);
$data[$values['User']['company']][] = $last_element;
}
}
$datas = array_values($data);
foreach ($datas as $a) {
$user = [$a['User']['company']];
foreach ($a as $b) {
if (isset($b['date_part'])) {
$this->HighCharts->setChartParams($chartName, array(
'renderTo' => 'linewrapper', // div to display chart inside
'chartWidth' => 1000,
'chartHeight' => 750,
'chartMarginTop' => 60,
'chartMarginLeft' => 90,
'chartMarginRight' => 30,
'chartMarginBottom' => 110,
'chartSpacingRight' => 10,
'chartSpacingBottom' => 15,
'chartSpacingLeft' => 0,
'chartAlignTicks' => FALSE,
'chartTheme' => 'dark-green',
'title' => 'Monthly Average Temperature',
'subtitle' => 'Source: WorldClimate.com',
'titleAlign' => 'center',
'titleFloating' => TRUE,
'titleStyleFont' => '18px Metrophobic, Arial, sans-serif',
'titleStyleColor' => '#0099ff',
'titleX' => 20,
'titleY' => 10,
'legendEnabled' => TRUE,
'legendLayout' => 'horizontal',
'legendAlign' => 'center',
'legendVerticalAlign ' => 'bottom',
'legendItemStyle' => array('color' => '#222'),
'legendBackgroundColorLinearGradient' => array(0, 0, 0, 25),
'legendBackgroundColorStops' => array(array(0, 'rgb(217, 217, 217)'), array(1, 'rgb(255, 255, 255)')),
'tooltipEnabled' => TRUE,
'tooltipFormatter' => $tooltipFormatFunction,
'xAxisLabelsEnabled' => TRUE,
'xAxisLabelsAlign' => 'right',
'xAxisLabelsStep' => 1,
'xAxislabelsX' => 5,
'xAxisLabelsY' => 20,
'xAxisCategories' => [$b['date_part']],
'yAxisTitleText' => 'Admin',
'plotOptionsLineDataLabelsEnabled' => TRUE,
'plotOptionsLineEnableMouseTracking' => TRUE,
'enableAutoStep' => FALSE
)
);
}//end if
}//end foreach
if (isset($b['admin'])) {
echo $b['admin'];
$series = $this->HighCharts->addChartSeries();
$series->addName($user)->addData([(int)$b['admin']]);
$mychart->addSeries($series);
}
}
Aucun commentaire:
Enregistrer un commentaire