|
Flexible legend and unit display |
Posted by boubekki on Apr-01-2017 00:33 |
|
Héllo,
Is it possible to have a graph size that grows depending on the size of the legend? Or is it possible to specify the size of the legend?
In my current code, I can only set the size of the plot area and the size of the result image which leads me to do some calculation to make sure that the legend but also that units are
not truncated.
Thanks! |
Re: Flexible legend and unit display |
Posted by Peter Kwan on Apr-03-2017 21:52 |
|
Hi boubekki,
Yes, you can resize the chart to any size you like.
For your case, the code structure can be something like (in Java/C#):
.. create chart as usual ..
// layout the chart
c.layout();
int legendWidth = c.getLegend().getWidth();
int legendHeight = c.getLegend().getHeight();
// resize the chart based on the legend width or height (depending on
// how to layout the chart
c.setSize(.....);
As an alternative to changing the chart size, you can also change the plot area size. See the sample code "Multi-Symbol Line Chart" for an example:
http://www.advsofteng.com/doc/cdnet.htm#multisymbolline.htm
You can set the legend box size by using Box.setSize. However, the size of the content in the legend box depends on the number of entries, the font size and the layout method (eg. whether you use vertical or horizontal or grid layout). If the content is larger than the box, it will just overflow outside the box. So setting the legend box size is mainly used for controlling the width for wrapping the legend entries. It cannot limit the content height.
Hope this can help.
Regards
Peter Kwan |
|