我正在将一种颜色推入一个数组,用一种颜色覆盖每个条形图颜色,但它没有按预期工作,这些数组有问题。
我的原始问题:如何在pChart中将数组推送到barChart并使用单色进行颜色覆盖?
更新问题:print_r结果显示额外的2组数组,它应该只是一个包含数组的数组,没有更深,这些数据会被添加到哪里?我该如何纠正?
PHP / pChart:
$prop_open=(1,5,8,4,2,66);
$j=0;
$palette_cycle=array();
foreach($prop_open as $value) {
array_push($palette_cycle,array("$j"=>array("R"=>108,"G"=>157,"B"=>49,"Alpha"=>100)));
$j++;
}
$palette=$palette_cycle;
$myPicture->drawBarChart(array("OverrideColors"=>$palette,"DisplayOrientation"=>ORIENTATION_HORIZONTAL,"DisplayPos"=>LABEL_POS_INSIDE,"DisplayValues"=>TRUE,"DisplayColor"=>DISPLAY_MANUAL,"DisplayR"=>0,"DisplayG"=>0,"DisplayB"=>0,"Surrounding"=>-60,"InnerSurrounding"=>60));
这就是我的$ palette_cycle数组应该在完成之后的结果(但所有RGB都是相同的):
$palette_cycle = array("0"=>array("R"=>188,"G"=>224,"B"=>46,"Alpha"=>100),
"1"=>array("R"=>224,"G"=>100,"B"=>46,"Alpha"=>100),
"2"=>array("R"=>224,"G"=>214,"B"=>46,"Alpha"=>100),
"3"=>array("R"=>46,"G"=>151,"B"=>224,"Alpha"=>100),
"4"=>array("R"=>176,"G"=>46,"B"=>224,"Alpha"=>100),
"5"=>array("R"=>224,"G"=>46,"B"=>117,"Alpha"=>100),
"6"=>array("R"=>92,"G"=>224,"B"=>46,"Alpha"=>100),
"7"=>array("R"=>224,"G"=>176,"B"=>46,"Alpha"=>100));
$ palette_cycle的打印结果:
Array (
[0] => Array ( [0] => Array ( [R] => 108 [G] => 157 [B] => 49 [Alpha] => 100 ) )
[1] => Array ( [1] => Array ( [R] => 108 [G] => 157 [B] => 49 [Alpha] => 100 ) )
[2] => Array ( [2] => Array ( [R] => 108 [G] => 157 [B] => 49 [Alpha] => 100 ) )
[3] => Array ( [3] => Array ( [R] => 108 [G] => 157 [B] => 49 [Alpha] => 100 ) )
[4] => Array ( [4] => Array ( [R] => 108 [G] => 157 [B] => 49 [Alpha] => 100 ) )
[5] => Array ( [5] => Array ( [R] => 108 [G] => 157 [B] => 49 [Alpha] => 100 ) ) )
答案 0 :(得分:1)
也许尝试使用这样的数组:
$j=0;
$palette_cycle=array();
foreach($prop_open as $value) {
$palette_cycle[] = array("R"=>108,"G"=>157,"B"=>49,"Alpha"=>100);
}
1,使用整数索引而不是字符串索引 2,不需要array_push
答案 1 :(得分:0)
试试这个
foreach($prop_open as $value) {
array_push($palette_cycle,"$j"=>array("R"=>108,"G"=>157,"B"=>49,"Alpha"=>100));
$j++;
}
如果没有,请尝试
foreach($prop_open as $value) {
$palette_cycle[$j] = array("R"=>108,"G"=>157,"B"=>49,"Alpha"=>100);
$j++;
}