|
Add border color to first data set |
Posted by Jason on Dec-06-2010 20:00 |
|
Hi Peter,
I have the following code to generate the graph (attached) as you can see there would be 2 arrays for the loop in $array to create both bars.
My problem is that the client wants the first 2 bars under the label "M&A Maturity Score" to have a border color. If I change the:
$layer->setBorderColor(Transparent);
line in my code below its going to effect the whole dataset.
I assume I need to create a seperate bar layer for the first piece of data that appears under this label, but then you would have to create a 2nd layer for the rest of the bars and this is where it gets confusing.
I dont know chart director that well so if you could point me in the right direction, any code would really help! Thanks
----------------------
$layer = $chart->addBarLayer2(3, 0, Transparent);
$layer->setBorderColor(1,1);
$colors[] = 0xFFDF00;
$colors[] = 0xebecec;
$colors[] = 0xc5c5c7;
$colors[] = 0x6f7073;
$item_count = 0;
if(is_array($array)){
foreach($array as $key=>$value){
$layer->addDataSet(array_values($value), $colors[$item_count], $country[$item_count]);
$layer->setBorderColor(Transparent);
$item_count++;
}
}
|
Re: Add border color to first data set |
Posted by Peter Kwan on Dec-06-2010 23:52 |
|
Hi Jason,
#The firstBarLayer is for the first bar only. It has a border color.
$firstBarLayer = $chart->addBarLayer2(Side);
$firstBarLayer->setBorderColor(0x000000);
$layer = $chart->addBarLayer2(Side);
$layer->setBorderColor(Transparent);
$colors[] = 0xFFDF00;
$colors[] = 0xebecec;
$colors[] = 0xc5c5c7;
$colors[] = 0x6f7073;
$item_count = 0;
if(is_array($array)){
foreach($array as $key=>$value){
$data = array_values($value);
#The first bar layer only contains the first value
$firstBarLayer->addDataSet(array($data[0]), Transparent);
$layer->addDataSet($data, $colors[$item_count], $country[$item_count]);
$item_count++;
}
}
Hope this can help.
Regards
Peter Kwan |
Re: Add border color to first data set |
Posted by Jason on Dec-07-2010 00:29 |
|
Thanks Peter! |
Re: Add border color to first data set |
Posted by Jason on Dec-08-2010 18:39 |
|
Hi Peter,
All is good but as you can see from the attached the dark grey bar in the first label now looks out of position as there are more bars in the whole graph (when there's less it looks fine).
Is there a way to fix this or do you think its a chart director software issue (we have version 4.1 installed)?
|
Re: Add border color to first data set |
Posted by Peter Kwan on Dec-09-2010 01:02 |
|
Hi Jason,
May be you change the code to:
if(is_array($array)){
foreach($array as $key=>$value){
$data = array_values($value);
#The first bar layer only contains the first value
$firstBarLayer->addDataSet(array($data[0]), $colors[$item_count]);
#Second bar layer does not contain the first value
$data[0] = NoValue;
$layer->addDataSet($data, $colors[$item_count], $country[$item_count]);
$item_count++;
}
}
In the above, I plot the first set of bars entirely using the $firstBarLayer, and remove the first set of bars from the $layer. In this way, the bars from two layers should not overlap (as each set of bars only exist in one of the layers), and it should solve the alignment issues.
Hope this can help.
Regards
Peter Kwan |
|