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

Message ListMessage List     Post MessagePost Message

  how to add seperate legend columns for layers
Posted by Dilip Agarwal on Dec-02-2013 17:57
Hi, I have two layer, one is AreaLayer and second is LineLayer(overlay graph). Both may
have one or more series. I want to show legends at bottom of chart in two column separate
for layers.Also legend symbol for AreaLayer as box and for LineLayer as line. How can I do
this.

Thanks

  Re: how to add seperate legend columns for layers
Posted by Peter Kwan on Dec-03-2013 01:05
Hi Dilip,

You may use BaseChart.addLegend2 to create a LegendBox with two columns. By default, the legend entry will be filled from left to right, top to bottom, ordered by the layer, then by the dataset within the layer. So it probably will not be one column for each layer.

For your case, the easiest way I can think of is to disable ChartDirector from automatically inserting the legend entry. For example:

'No automatic legend entry
Call myAreaLayer.setLegendOrder(cd.NoLegend)
Call myLineLayer.setLegendOrder(cd.NoLegend)

Then you add the legend entry using your own code:

Set legendBox = c.addLegend(c.getPlotArea().getBottomY() + 40, c.getWidth() / 2, 2, "arial.ttf", 8)
Call legendBox.setLineStyleKey()
Call legendBox.setAlignment(cd.TopCenter)

Call legendBox.addKey("aaa", areaDataSet1Color)
Call legendBox.addKey("bbb", lineDataSet1Color, 2)
Call legendBox.addKey("ccc", areaDataSet2Color)
Call legendBox.addKey("ddd", lineDataSet2Color, 2)

In brief, you need to add an legend entry for a data set for the area layer, then for a data set for the line layer, then for the area layer, then for the line layer, and so on. If you have different number of datasets for the line and area layers, you would need to add an empty entry to fill the position that has no data set. An empty entry is:

Call legendBox.addKey("", cd.Transparent, 2)

Hope this can help.

Regards
Peter Kwan