Custom legend - how to specify vertical axis?
Posted: Fri Oct 17, 2008 7:19 pm
I need help customizing a chart's legend. The chart contains one or more line series, and the series may be plotted using either the left or the right axis. When the series are added to the chart, they are in order so that all of the left-axis series are added first, followed by the right-axis series. My problem is to create a legend that clearly identifies which axis applies to each series.
One solution I came up with is to add an empty series after the last left-axis series. By setting LinePen.Visible = false and the series title to a single space character, an empty space appears in the legend between the 2 groups of series. I then draw a horizontal line on the canvas in the middle of the vertical space to better distinguish the 2 groups. While the appearance of the legend is acceptable, I'm not happy with this approach. Without going into all of the details, adding an empty series adds additional complexity to other parts of my code that refer to the chart series. Moreover, when I add the empty series, the range of the vertical axis is automatically decreased slightly, truncating any series pointers that are at the upper and lower edges of the graph. As far as I can tell, this odd behavior occurs because the empty series is not set to display pointers by default.
Is there a better way to customize the legend?
I've tried to increase the size of the legend rectangle and adjust the vertical position of the right-axis legend items (move them downward to create a vertical space), but I haven't been successful.
I've wondered about manually drawing the entire legend, but I'm not sure how to proceed. If this seems like the best approach, could you post some example code that shows how to draw each part of the legend (rectangle, series line & symbol, series name, etc.)?
Thanks!
Chris
One solution I came up with is to add an empty series after the last left-axis series. By setting LinePen.Visible = false and the series title to a single space character, an empty space appears in the legend between the 2 groups of series. I then draw a horizontal line on the canvas in the middle of the vertical space to better distinguish the 2 groups. While the appearance of the legend is acceptable, I'm not happy with this approach. Without going into all of the details, adding an empty series adds additional complexity to other parts of my code that refer to the chart series. Moreover, when I add the empty series, the range of the vertical axis is automatically decreased slightly, truncating any series pointers that are at the upper and lower edges of the graph. As far as I can tell, this odd behavior occurs because the empty series is not set to display pointers by default.
Is there a better way to customize the legend?
I've tried to increase the size of the legend rectangle and adjust the vertical position of the right-axis legend items (move them downward to create a vertical space), but I haven't been successful.
I've wondered about manually drawing the entire legend, but I'm not sure how to proceed. If this seems like the best approach, could you post some example code that shows how to draw each part of the legend (rectangle, series line & symbol, series name, etc.)?
Thanks!
Chris