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

Message ListMessage List     Post MessagePost Message

  Displaying Multiple Legends on Gantt Chart
Posted by Brent Hetland on Feb-05-2014 21:15
Hi,

I am using ChartDirector version 5.0.3.

I want two legends on my chart (one on TopCenter and on BottomCenter).  Is that
possible?

When I try it, I just get one legend, with duplicate entries.

My code is basically this:

heightToAdd = (legendDict.Count \\ columnsInLegend) *
additionalHeightPerLegendRow
c.setSize(chartWidth, chartHeight + heightToAdd)

' Add a LegendBox
Dim b As ChartDirector.LegendBox = c.addLegend2((c.getWidth()
/ 2) + 70, c.getHeight() - 15, columnsInLegend,
ChartConstants.LEGEND_LABEL_FONTNAME, ChartConstants.LEGEND_LABEL_FONTSIZE)
b.setAlignment(ChartDirector.Chart.BottomCenter)
b.setWidth(plotAreaWidth)
b.setBackground(ChartDirector.Chart.Transparent, &H444444)
b.setRoundedCorners()

For Each kvPair As KeyValuePair(Of String, Integer) In legendDict
truncatedTaskName = kvPair.Key

If (truncatedTaskName.Length > maxLegendTextLength)
Then
truncatedTaskName = Left(truncatedTaskName,
maxLegendTextLength) & "..."
End If

b.addKey(truncatedTaskName, kvPair.Value)
Next

       heightToAdd = (legendDict.Count \\ columnsInLegend) *
additionalHeightPerLegendRow
c.setSize(chartWidth, chartHeight + heightToAdd)

Dim b2 As ChartDirector.LegendBox = c.addLegend2((c.getWidth()
/ 2) + 70, 15, columnsInLegend, ChartConstants.LEGEND_LABEL_FONTNAME,
ChartConstants.LEGEND_LABEL_FONTSIZE)
b2.setAlignment(ChartDirector.Chart.TopCenter)
b2.setWidth(plotAreaWidth)
b2.setBackground(ChartDirector.Chart.Transparent, &H444444)
b2.setRoundedCorners()

For Each kvPair As KeyValuePair(Of String, Integer) In legendDict
truncatedTaskName = kvPair.Key

If (truncatedTaskName.Length > maxLegendTextLength)
Then
truncatedTaskName = Left(truncatedTaskName,
maxLegendTextLength) & "..."
End If

b2.addKey(truncatedTaskName, kvPair.Value)
Next

  Re: Displaying Multiple Legends on Gantt Chart
Posted by Peter Kwan on Feb-06-2014 01:50
Hi Brent,

Each BaseChart object can only contain one legend box, but you can create two chart
objects, each containing one legend box, and merge them into the same chart. For your
case, you may try something like the followings for the second legend box:

Dim secondLegend As XYChart = New XYChart(c.getWidth(), 100, Chart.Transparent)

Dim b2 As ChartDirector.LegendBox = secondLegend.addLegend2((c.getWidth()
/ 2) + 70, 0, columnsInLegend, ChartConstants.LEGEND_LABEL_FONTNAME,
ChartConstants.LEGEND_LABEL_FONTSIZE)

.... set up b2 as usual ....

'merge secondLegend into the chart c
c.makeChart3().merge(secondLegend.makeChart3(), 0, 15, Chart.TopLeft, 0)

Hope this can help.

Regards
Peter Kwan