想知道你是否可以帮助我。我正在查询一个表以使用 H 时间轴和 V 计数轴填充图表,并且我试图根据数据库表中的服务器动态地将过滤器添加到图表中。此时它是静止的。
我使用以下代码查询数据库并将系列添加到图表中
$results = array();
foreach( \IPS\Db::i()->select( '*', 'stats', $where, 'time ASC' ) as $row )
{
$value = '_'.$row['server'];
if( !isset( $results[ $row['time'] ] ) )
{
$results[ $row['time'] ] = array(
'time' => $row['time'],
'_64' => 0,
'_66' => 0
);
}
//$results[ $row['time'] ][$value] = 0;
if ($value == '_64')
{
$results[ $row['time'] ]['_64'] = $row['value_1'];
}
elseif($value == '_66')
{
$results[ $row['time'] ][ '_66' ] = $row['value_1'];
}
}
return $results;
并添加过滤器
$chart->addSeries('_66', 'number');
$chart->addSeries('_64', 'number');
我试图通过这样做使它变得动态
foreach(\IPS\Db::i()->query( "SELECT DISTINCT server FROM stats ORDER BY server" ) as $row)
{
$value = '_'.$row['server'];
$chart->addSeries($value, 'number');
}
和
$value = '_'.$row['server'];
if( !isset( $results[ $row['time'] ] ) )
{
$results[ $row['time'] ] = array(
'time' => $row['time'],
$value => 0,
);
}
$results[ $row['time'] ][$value] = $row['value_1'];
但这无论如何都不起作用。我认为我要添加到数组中是完全错误的。请问有什么建议吗?
数组应该是这样的
array (size=8)
1504025011 =>
array (size=3)
'time' => int 1504025011
'_64' => int 2
'_66' => int 0
1504094803 =>
array (size=3)
'time' => int 1504094803
'_64' => int 0
'_66' => int 14
但反而
array (size=8)
1504025011 =>
array (size=2)
'time' => int 1504025011
'_64' => int 2
1504094803 =>
array (size=2)
'time' => int 1504094803
'_66' => int 14