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

Message ListMessage List     Post MessagePost Message

  X axis label issues
Posted by Raghu Goyal on Aug-10-2006 19:13
Hi,

I am facing the flood of x axis labels on chart and x labels are overlapped. To control the flood of x axis labels I could use setLabels method with some labels as empty but I do not want to use that method with some empty string because then on tooltip also it shows x value as blank.

I am using xaxis.setLabelStep() method like this.

xaxis.setLabelStep(chartXValues.length/3);

where chartXValues is an array that is dynamic and keep on increasing, so i don't know what to set in setLabelStep... And it does not show last x label some times because chartXValues.length/3 value would be changing on runtime dynamically.

Is there any way in XY charts so that I am able to see atleast first and last x axis label ?
Or is there any better way to solve the problem ?

Please help...

Thanks,
Raghu Goyal

  Re: X axis label issues
Posted by Peter Kwan on Aug-11-2006 00:25
Hi Raghu,

You mention "i don't know what to set in setLabelStep". Currently, you are using chartXValues.length/3 as the label step, which should be quite OK. It means around 3 - 4 labels on the x-axis.

If you want to see the first and last labels, that means either you see these two labels only and no other labels, or you can accept the labels are not evenly spaced. (For example, if you have 11 labels, there is no way to evenly step the labels and also show the first and last labels. It is because 11 is a prime number.)

I suggest you use the following method:

//use normal label stepping
xaxis.setLabelStep(chartXValues.length/3);

//force display of last label
xaxis.addMark(chartXValues.length - 1, 0x000000, "" + chartXValues[chartXValues.length - 1]);

Hope this can help.

Regards
Peter Kwan

  Re: X axis label issues
Posted by Raghu Goyal on Aug-11-2006 13:41
Attachments:
Hi Peter,

It helped a lot. Thanks.
I am able to show the last xaxis label with these 2 lines of code.

xaxis.setLabelStep(chartXValues.length/3);
//force display of last label
xaxis.addMark(chartXValues.length - 1, 0x000000, "" + chartXValues[chartXValues.length - 1]);

Please see the attached image and let me know if there is any setting by which xaxis tick is hidden if that label is not being displayed. In the image last label and tick is a mark (10:56:10) and just before that there is a tick without label.. Can i hide that tick too if there is no label displayed for that.

Thanks,
Raghu Goyal
chart xaxis issue.JPG

  Re: X axis label issues
Posted by Raghu Goyal on Aug-14-2006 13:13
Hi,

Can some one please reply of my previous mail in this thread?

Thanks,
Raghu Goyal

  Re: X axis label issues
Posted by Peter Kwan on Aug-14-2006 22:11
Hi Raghu,

Since you may add one label, you can surely add all labels yourself, so you can control where are the labels (and so where are the ticks). For example:

//first and last labels only
xaxis.setLabelStep(chartXValues.length);

//labels in between
for (int i = 0; i < chartXValues.length - chartXValues.length / 3; i += chartXValues.length / 3)
       xaxis.addMark(i, 0x000000, "" + chartXValues[i]);

Regards
Peter Kwan

  Re: X axis label issues
Posted by Ewan Edwards on Aug-25-2006 02:47
I've just started tackling this same problem myself for an XYChart I need to plot, so I was pleased to find this example as part of this discussion:

//first and last labels only
xaxis.setLabelStep(chartXValues.length);

I'm using ChartDirector 4.0 for Perl for Linux (x86_64) if that makes any difference.

If find that I cannot use setLabelStep(scalar @labels); the tick at the far right of the XYChart (since the origin is on the left) never appears.

Since ChartDirector seems to count from 0, I tried setLabelStep(scalar(@labels)-1) instead. Still no go.

setLabelStep(scalar(@labels)-2) works. Except that the tick is one pixel from the right border of the XYChart. The first tick (representing $labels[0]) shares the same pixel as the left border of the XYChart.

This is a problem for 2 reasons:

1) The label displayed on the right side is not the last label; I display the range of labels in my HTML, so the text in the HTML does not match the label in the graph. The fix is an ugly kludge: $labels[-2] = $labels[-1];

2) Since the last tick is inside the border, a mark is also presented. If the mark is the same colour as the border, it makes the border look twice as thick. As it happens, I've styled the marks to appear light grey (where the border is black). This situation makes the right border look soft.

Is this a bug in ChartDirector? or is there a way to have the final tick/mark/label share the same pixel as the right border of an XYChart.

  Re: X axis label issues
Posted by Ewan Edwards on Aug-25-2006 03:17
I've found a solution: do not set labels on the X axis, and add marks explicitly.

What I ended up with that works for me is (in Perl):

my $label_count = scalar @labels;
my $step = int($label_count / 3);
$chart_obj->xAxis()->addMark(0, 0x000000, $labels[0]);
$chart_obj->xAxis()->addMark($step, 0xc0c0c0, $labels[$step])->setMarkColor(0xc0c0c0, 0x000000, 0x000000);
$chart_obj->xAxis()->addMark($step * 2, 0xc0c0c0, $labels[$step * 2])->setMarkColor(0xc0c0c0, 0x000000, 0x000000);
$chart_obj->xAxis()->addMark($label_count-1, 0x000000, $labels[-1]);

The first addMark is necessary since I'm no longer doing: $c->xAxis()->setLabels(\@labels);

The first and final addMark calls don't need the setMarkColor since everything needs to be black (otherwise, the grey marks overwrite the left and right borders, respectively, of the XYChart).

It would be nice if ChartDirector's setLabelStep() could be smarter, or any alternative that simply expressed "make these labels fit the desired graph width, divided into x as-equal-as-possible sections". But, as I've shown above, it's not absolutely necessary.