|
Color of side by side bar charts not matching in legend |
Posted by Mark Oudesluys on Nov-26-2010 04:55 |
|
Hi,
I have a verticle side-by-side bar chart, which has a colored border but a transparent inside, as per my client's request. I can plot the chart properly, but the legend doesn't match the color of the bars. Is there a way of doing this?
Here is my code for the bar chart layers:
# Add a multi-bar layer with upto 6 data sets and 0 pixels 3D depth
reset($funds);
if (count($funds)>0)
{
$layer = $c->addBarLayer2(Side, 0);
if ($funds[1])
{
$layer1=$layer->addDataSet($data1, Transparent, $fundname[1]);
$layer1->setDataColor(Transparent, hexdec("0x".$f1color), Transparent, Transparent);
}
if ($funds[2])
{
$layer2=$layer->addDataSet($data2, Transparent, $fundname[2]);
$layer2->setDataColor(Transparent, hexdec("0x".$f2color), Transparent, Transparent);
}
if ($funds[3])
{
$layer3=$layer->addDataSet($data3, Transparent, $fundname[3]);
$layer3->setDataColor(Transparent, hexdec("0x".$f3color), Transparent, Transparent);
}
if ($funds[4])
{
$layer4=$layer->addDataSet($data4, Transparent, $fundname[4]);
$layer4->setDataColor(Transparent, hexdec("0x".$f4color), Transparent, Transparent);
}
if ($funds[5])
{
$layer5=$layer->addDataSet($data5, Transparent, $fundname[5]);
$layer5->setDataColor(Transparent, hexdec("0x".$f5color), Transparent, Transparent);
}
if ($funds[6])
{
$layer6=$layer->addDataSet($data6, Transparent, $fundname[6]);
$layer6->setDataColor(Transparent, hexdec("0x".$f6color), Transparent, Transparent);
}
}
See the attached image for the resulting bar chart, and notice that the legend is always black, even if the bars are set to specific colors.
Thanks,
Mark
|
Re: Color of side by side bar charts not matching in legend |
Posted by Peter Kwan on Nov-27-2010 00:00 |
|
Hi Mark,
Due to compatibility with older versions of ChartDirector, and also to allow a white legend icon to be visible on a white background (sometimes people use a non-white plot area background, and plot white borderless bars on it), the legend icon by default will have a black border. The border line color for the legend icons is configurable, but all icons must use the same border color.
For your case, I suggest you may disable the original legend icons, and use addScatterLayer to add the real legend icons. The code is like:
if (count($funds)>0)
{
$layer = $c->addBarLayer2(Side, 0);
#add this line to disable the legend icon for the bar layer
$layer->setLegendOrder(NoLegend);
....
}
Then for each of your funds, you can use something like:
$layer1=$layer->addDataSet($data1, Transparent, $fundname[1]);
$layer1->setDataColor(Transparent, hexdec("0x".$f1color), Transparent, Transparent);
#This line does not plot anything. Its purpose is to add an entry in the legend box.
$c->addScatterLayer(null, null, $fundname[1], SquareShape, 9, Transparent, hexdec("0x".$f1color));
Hope this can help.
Regards
Peter Kwan |
|