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

Message ListMessage List     Post MessagePost Message

  Resizing x-axis labels
Posted by Lee Baxter on Jul-14-2009 17:58
Hi,

I just wondered if there is any way of resizing axis labels depending upon the size of the chart and the string length.  I've produced a resizable swing control that redraws the graph when it's resized, but I need to reduce the font size for smaller charts so that the x-axis labels don't bunch up together.  Is there a function in ChartDirector to determine the font size or would I need to set it emperically?

Thanks, Lee.

  Re: Resizing x-axis labels
Posted by Peter Kwan on Jul-15-2009 01:06
Hi Lee,

In most resizable charts I see, the font size is never changed. For example, you may try to view the charts in the Windows Performance Manager (enter "perfmon" in the command line). The charts are resizable. When the chart is resized, the font size is the same. However, the number of labels on the x-axis changed. If the chart is larger, there are more labels and vice versa.

It is because even if you resize the fonts a little bit (say from 8 points to 6 points), the font will be unreadable because they are too small. So all labels are unreadable and useless if your resize them even if it is change a little bit.

So the common method to resize a chart is similar to resizing a geographic map (eg. google map). When the map is resized, the label fonts are not resized, but the amount of labels changed.

The method to change the number of labels depend on the nature of your labels and who put the labels on the axis. If the axis labes are determined by ChartDirector automatically (eg. auto-scaling), ChartDirector will reduce the number of labels when the chart is smaller. If your code put the labels on the chart, you code would need to reduce the number of labels. For example, if you are using a label based x-axis (configured using Axis.setLabels), you may use Axis.setLabelStep to step the labels if the chart is too small. It is like:

//maintain approximately 50 pixels per label - step the labels if necessary
c.xAxis().setLabelStep(1 + (int)(labels.length * 50 / c.getPlotArea().getWidth()));

If you really want to change the font size, you may use:

//First, compute fontSize based on your chart size. Then use:
c.xAxis().setLabelStyle("Arial", myFontSize);

Hope this can help.

Regards
Peter Kwan