ASE Home Page Products Download Purchase Support About ASE
ChartDirector Support
Forum HomeForum Home   SearchSearch

Message ListMessage List     Post MessagePost Message

  Unable to get legend icon
Posted by Terrance on Jun-24-2013 23:54
Hi,

I have a graph in which I am trying to get it's legend icons for each layer and putting it in a separate image which will be a custom legend in a CDML table. Needless to say, the icons never show up. When I do an output of "$layer->getLegendIcon(0)" I always get "<*img=@@0*>". There is only one dataset per layer. I get the same result regardless if the legend for the graph is on or off. Any idea what could be wrong?

  Re: Unable to get legend icon
Posted by Peter Kwan on Jun-25-2013 05:35
Hi Terrance,

As mention in the ChartDirector documentation, the result of getLegendIcon is only valid in the BaseChart object that contains the data set. Are you trying to call getLegendIcon using the $layer or one chart object, and use the result in another chart (or DrawArea) object?

If you need to create a CDML table with the legend icons, please make sure you create the CDML table in the same chart object that contains the icons. If you need the CDML table to be in a "separate image", you can first create the CDML table in the same chart object, and copy the created CDML table to a separate empty DrawArea using DrawArea.merge, and then erase the CDML table from the original chart object (eg. by reducing the size of the original chart).

Regards
Peter Kwan

  Re: Unable to get legend icon
Posted by Terrance on Jun-26-2013 05:25
Peter,

I've tried several different ways. Based on the doc, getLegendIcon is available through, Layer and DataSet.

$c = new XYChart(400, 400, 0xffffff, -1, 0);
$c->setPlotArea(50, 60, 390, 400, 0xffffff, -1, -1, 0xc0c0c0, -1);
$layer = $c->addLineLayer2();
$dataSet = $layer->addDataSet($data, -1, $description);

$layer->getLegendIcon(0);
$dataSet->getLegendIcon();

In either case the output is "<*img=@@0*>"

As far as the separate image, it may be irrelevant. I'm storing all the resulting graphs/images in array so that I can later access their properties. I did run the code above as it is to make sure that there wasn't something else going on after I was done editing the graph.

  Re: Unable to get legend icon
Posted by Peter Kwan on Jun-26-2013 23:53
Hi Terrance,

The output "<*img=@@0*>" is normal. As mentioned in the ChartDirector documentation, the output is a CDML representation of the icon, and the above is the CDML representation. It is only valid in the BaseChart object that contains the data set can be used in any ChartDirector API that supports CDML. When ChartDirector sees this CDML representation, it will render the icon.

You can store the "<*img=@@0*>" in an array if you like, but you can only use it in the same chart that generates this CDML. You cannot use it in a different chart object, or display it not using ChartDirector API that supports CDML (such as displaying it as HTML on a web page).

So for your case, the "<*img=@@0*>" should be correct. The key is how your code is using the CDML representation. Is your code eventually passed it to a ChartDirector method that supports CDML?

Hope this can help.

Regards
Peter Kwan

  Re: Unable to get legend icon
Posted by Terrance on Jul-09-2013 00:29
Ahh, I think understand now. I feeling that since I was storing the graphs in an array,  that I should be able to still access everything including their graph legend info(color) and put that in another image. I ended up just using and looping through the default color palette to match the colors up. Thanks for your time.