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
Custom legend - how to specify vertical axis?
-
- Site Admin
- Posts: 14730
- Joined: Mon Jun 09, 2003 4:00 am
- Location: Banyoles, Catalonia
- Contact:
Hi Chris,
At the present moment you should draw a custom legend as in the example Christopher Ireland suggested on this thread.
At the present moment you should draw a custom legend as in the example Christopher Ireland suggested on this thread.
Best Regards,
Narcís Calvet / Development & Support Steema Software Avinguda Montilivi 33, 17003 Girona, Catalonia Tel: 34 972 218 797 http://www.steema.com |
Instructions - How to post in this forum |
Thanks for the response.
I reviewed the thread as suggested, and I now see how to create a legend box with the series titles inside.
How can I add the series line color and symbol? I'm aware that there's a Legend.OnDrawSymbol Event, but I'm not sure how I would use that event to draw the series symbols in my custom legend. Could you post some example code?
Thanks,
Chris
I reviewed the thread as suggested, and I now see how to create a legend box with the series titles inside.
How can I add the series line color and symbol? I'm aware that there's a Legend.OnDrawSymbol Event, but I'm not sure how I would use that event to draw the series symbols in my custom legend. Could you post some example code?
Thanks,
Chris
-
- Site Admin
- Posts: 14730
- Joined: Mon Jun 09, 2003 4:00 am
- Location: Banyoles, Catalonia
- Contact:
Hi Chris,
This event wouldn't be available in a custom legend as shown in Cristopher Ireland's example. I can think of two options here:
1. Manually drawing desired symbols on the charts canvas using custom legend's Draw method.
2. As Christopher Ireland suggested, you can inherit from base legend class to create your own legend. This could mean having that event available.
Sorry but I don't have any code example of that.
This event wouldn't be available in a custom legend as shown in Cristopher Ireland's example. I can think of two options here:
1. Manually drawing desired symbols on the charts canvas using custom legend's Draw method.
2. As Christopher Ireland suggested, you can inherit from base legend class to create your own legend. This could mean having that event available.
Sorry but I don't have any code example of that.
Best Regards,
Narcís Calvet / Development & Support Steema Software Avinguda Montilivi 33, 17003 Girona, Catalonia Tel: 34 972 218 797 http://www.steema.com |
Instructions - How to post in this forum |