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

Message ListMessage List     Post MessagePost Message

  Autoscale Legend
Posted by TN on Aug-31-2022 22:50
Is there a way to autoscale a legend to fit a given area regardless the number of keys or length of key texts?

  Re: Autoscale Legend
Posted by TN on Sep-01-2022 05:26
A related question: If we want a bottom placement of the legend below the X axis title without it being potentially clipped due to not knowing ahead of time the number of keys and length of key texts, would this be the process:

1.) Place the legend near the bottom of the chart on using addLegend.
2.) Add the data series with the data name.
3.) Call layoutLegend
4.) Get legend height
5.) Reposition/Reset legend (?? not sure how to this, call addlegend again?) with height information

Is there an easy way to do this or does the legend auto scale to avoid clipping?


Thanks.

  Re: Autoscale Legend
Posted by Peter Kwan on Sep-01-2022 22:08
Hi TN,

If there is sufficient non-overlapping content, the content will eventually overflow outside its container (which means the content is clipped to its container), unless the container can extend indefinitely in size.

For your case, to avoid clipping, you can increase the height of your chart (using BaseChart.setSize) to as tall as necessary to contain the legend box. It is like laying out a web page. The web page will extend indefinitely to contain everything in the page.

If you need to reposition the LegendBox, you can use Box.setPos. In C#/Java, it is like:

// position the legend box so that bottom edge of the legend box is 5 pixels
// from the bottom of the chart
myLegendBox.setPos(5, myChart.getHeight() - myLegendBox.getHeight() - 5);

In some case, it may be possible to adjust other items on the chart. For example, in the following sample code, the plot area size is adjusted to leave sufficient space for the legend box:

https://www.advsofteng.com/doc/cdnet.htm#markbar.htm

Best Regards
Peter Kwan