|
setLabelGap |
Posted by JC on Oct-28-2008 01:46 |
|
I am wondering is there a way to stagger both axis labels. Like each odd are set to default and evens are shifted. All data are stored in a .Net Datatable and is converted to a CD datatable before passing them to CD objects.
Axis will display vertically, and data values are 10,20,30,40,50,60,70,80,90,etc...
----|----|----|----|----|----|----|----|----|----|
1 3 5 7 9
0 2 0 4 0 6 0 8 0 1
0 0 0 0 0
0 |
Re: setLabelGap |
Posted by Peter Kwan on Oct-28-2008 20:27 |
|
Hi JC,
To configure the x-axis labels, we need to know why there are x-axis labels in the first place. Are the labels specified by your code (eg. using Axis.setLabels), or are they generated by ChartDirector when auto-scaling the axis?
I assume the labels are specified by your code (as ChartDirector auto-scaling usually will not use labels that "dense"). In this case, the easy method to "shift" the labels downwards is to insert a newline character. For example:
'assume myLabels are an array of text strings
For i = 1 To Ubound(myLabels) Step 2
myLabels(i) = vbLF & myLabels(i)
Next
c.xAxis().setLabels(myLabels)
To display the labels vertically, we usually suggest to rotate the labels by 90 degrees, like:
c.xAxis().setLabelStyle("Arial", 8, &H000000, 90)
However, you may also display using the method you are currently using (the characters are not rotated, but the text flow is vertical - this uses more space compare to rotating the labels by 90 degrees). The code is:
c.xAxis().setLabelStyle("Arial", 8, &H000000).setMaxWidth(10)
Hope this can help.
Regards
Peter Kwan |
Re: setLabelGap |
Posted by JC on Oct-28-2008 23:12 |
|
Your assumption is both, pending on what type the chart is (bar vs. Column as example)
In your example for some strange reason if I use
myLabels(i) = vbLF & myLabels(i)
it seems like your code strips it out. I had to use
myLabels(i) = " " & myLabels(i)
Is there a work around for "dense" labels? Your assumption works for Column chart, but if the chart is swap for Bar charts then the xAxis that is displayed is the auto-scale |
Re: setLabelGap |
Posted by Peter Kwan on Oct-29-2008 00:46 |
|
Hi JC,
If the chart is swapped, the horizontal axis (it is called the y-axis in ChartDirector for swapped chart) is the auto-scaled axis.
If auto-scaling is used, ChartDirector will *not* put so many labels on the axis. For example, if the labels 0, 10, 20, 30, 40, 50, .... are too crowded, ChartDirector will simply use 0, 20, 40, 60 ..., or even 0, 50, 100, 150, etc... On the other hand, if the labels 0, 10, 20, 30 ... are too sparse (may be the axis is very long and has plenty of space), ChartDirector may choose 0, 5, 10, 15, 20, ... In other words, ChartDirector will automatically determine an optimal label spacing (configurable with Axis.setTickDensity).
Therefore, there should not be any need to have two layers of labels.
In additional, ChartDirector also supports "minor ticks". It means you may have the labels as 0, 20, 40, ..., and you may put minor ticks at 10, 30, ...
In general, for numeric or date/time axis, if you find the labels over-crowded, you may consider to remove some labels, or to replace them with minor ticks. The chart may look "cleaner" this way.
The two layers or labels are usually only useful for non-numeric axis, such as the x-axis showing the names of countries. In these case, all labels may be mandatory and cannot be removed, so we may use two layers of labels to make it easier to read.
Anyway, if you need to use two layers or labels for an auto-scaled axis, you may try:
.... create chart as usual ......
'freeze chart and auto-scale axis, so we can get the labels on the axis
c.layout()
'get the label positions
Dim ticks() As Double = c.yAxis().getTicks()
'for each even label, insert empty space in front
Dim i As Integer
For i = 1 To Ubound(ticks) Step 2
c.yAxis().addLabel(ticks(i), " " & c.yAxis().getLabel(ticks(i)))
Next
Hope this can help.
Regards
Peter Kwan |
|