|
How can I ensure that all SideLayout labels are within the drawn area of a PieChart? |
Posted by Bill on Jun-16-2011 03:38 |
|
Hi,
I'm creating pie charts with PieChart.setLabelLayout(Chart.SideLayout). When there is a large data set, the right side labels often fall outside (above/below) the drawn area. I've written a method that calculates the total height of all of the right side labels so I can increase the height in the PieChart constructor accordingly. It works pretty well, but it's not infallible. (The method also inserts \\n into the label strings if they are too long, so there is no problem in the horizontal dimension.)
What's the best way to ensure that all of the labels will fall within the vertical dimension of the drawn area?
Thanks,
Bill |
Re: How can I ensure that all SideLayout labels are within the drawn area of a PieChart? |
Posted by Peter Kwan on Jun-16-2011 18:57 |
|
Hi Bill,
A web page can contain arbitrary amount of text, because it can grow arbitrarily long.
However, a chart usually has a pre-determined size, and so it can only support a finite number of labels. This is like what you do when you are creating an image using Windows Paint. The size is pre-determined.
Of course, one method simply "enlarge" the size when it found that the size is not enough. However, in ChartDirector, there is no API to determine the total height of all the labels on a pie chart, so it is not easy to determine how much to enlarge the chart. The only method I can think of is to "guess", and add some margin as a buffer.
Personally, I would consider another method, which is not to allow so many sectors at all. A pie chart is not suitable for displaying a large number of sectors. If you have many sectors, a common method is to only display the top 10 sectors (or top N sectors), and try group all the other sectors as one sector called "Others" (or "Misc", etc...). You can display the information on all the sectors on a separate table (so people can know what "Others" mean).
Hope this can help.
Regards
Peter Kwan |
Re: How can I ensure that all SideLayout labels are within the drawn area of a PieChart? |
Posted by Bill on Jun-17-2011 03:24 |
|
Hi Peter,
Thanks for your prompt reply.
Point taken about limiting the number of sectors; however, the sizing problem occurs even with as few as 15 sectors, especially if most of them are on the right side of the pie chart. Also, imposing an arbitrary limit on the number of sectors has its own problems. For example, if I limit it to 10 sectors, and there are 10 rows of data, then the tenth sector would say "Other" or "Misc" even though there is only 1 row corresponding to that sector. Finally, my users want to see all of the data, if for no other reason so they can view the details of each sector with a mouseover. (These charts are not intended for printing, even though they can be.)
Since I want to minimize the vertical size of the drawn area (350 pixels by default, to minimize wasted real estate) and also support an unlimited number of sectors, I need to calculate the horizontal size on the fly before I create the chart. So, after I received your reply, I went back and tweaked my code that calculates the height of the chart and it now works pretty well, even when there are dozens of sectors.
If anyone on the forum is interested in my solution, then post a message and I'll be happy to post the code.
Having said all that, I think ASE should consider adding a new feature in a future version that will ensure that all of the labels fall within the drawn area, at least in the vertical dimension.
Thanks again,
Bill |
Re: How can I ensure that all SideLayout labels are within the drawn area of a PieChart? |
Posted by Bill on Jun-17-2011 03:33 |
|
Bill wrote:
Since I want to minimize the vertical size of the drawn area (350 pixels by default, to minimize wasted real estate) and also support an unlimited number of sectors, I need to calculate the horizontal size on the fly before I create the chart.
I meant to say "I need to calculate the vertical size on the fly.... |
Re: How can I ensure that all SideLayout labels are within the drawn area of a PieChart? |
Posted by LAXMAN on Jul-20-2012 11:48 |
|
Hi Bill,
I have same problem that labels go out of the drawing area when I use Chart.SideLayout. It would be great if you share your code.
Thanks,
Laxman |
|