|
Vertical X Axis Labels and width of elements |
Posted by Ed on Apr-24-2015 01:52 |
|
I have a scatter plot that I am creating and the X-Axis elements need vertical labels. I have been able do to this properly so the labels are vertical.
However, if you look at the chart with the horizontal labels, you will see that the x-axis item separation is calculated using the horizontal labels and NOT the vertical labels. In the vertical labels chart, there is way too much room between elements.
How do I reduce the space between elements so they are closer together? My bubble is at most 50 pixels so even if I could specify a spacing of 30 characters then my problem would be solved.
My code is in perl:
$c->setPlotArea(200, 10, 550, $y_plot, $perlchartdir::Transparent, $perlchartdir::Transparent, $perlchartdir::Transparent, $perlchartdir::Transparent);
# Set the labels on the x axis.
my $tb;
$c->xAxis()->setLinearScale2(0, $srccount+2, \\@labelxw);
$tb = $c->xAxis()->setLabels(\\@labelx);
$c->xAxis()->setRounding(0, 0);
$c->xAxis()->setLabelStep(1, 1);
$tb->setFontAngle(90);
$tb->setFontStyle("arial.ttf");
$tb->setFontSize(8);
# Set the labels on the y axis.
$tb = $c->yAxis()->setLabels(\\@labely);
$c->yAxis()->setRounding(0, 0);
$c->yAxis()->setLabelStep(1, 1);
$tb->setFontAngle(0);
$tb->setFontStyle("arial.ttf");
$tb->setFontSize(8);
# set the x axis to transparent, with labels in dark red (0x663300)
$c->xAxis()->setColors($perlchartdir::Transparent, 0x663300);
# set the y axis and labls to transparent
$c->yAxis()->setColors($perlchartdir::Transparent, 0x663300);
$c->addScatterLayer(\\@datax, \\@datay, "Connections", $perlchartdir::CircleShape, 9, 0x80ff3333, 0x80ff3333)->setSymbolScale(\\@bsize);
$c->addScatterLayer(\\@datax, \\@datay, "", perlchartdir::Cross2Shape(0.01), 9, 0x80555555, 0x80555555)->setSymbolScale(\\@bsizex);
Thanks in advance.
|
Re: Vertical X Axis Labels and width of elements |
Posted by Peter Kwan on Apr-25-2015 01:30 |
|
Hi Ed,
For your case, I think the x-axis label spacing is not related to the label rotation, but is
based on the plot area width and the number of labels. It should be (plotAreaWidth /
(noOfLabels - 1)).
If you would like to have 60 pixels between labels, you can set the plotAreaWidth to (60 *
noOfLabels - 1) with a minimum value of 60 (in case there is just one label).
Hope this can help.
Regards
Peter Kwan |
Re: Vertical X Axis Labels and width of elements |
Posted by Ed on Apr-25-2015 01:50 |
|
I am not sure that I understand. I am setting the plotAreaWidth to an arbitrary number and the graph is running off the edge.
How would setting it to a smaller number make it stay within the confines of the plot area?
Is there no way to manually set the spacing between labels/graph columns? |
Re: Vertical X Axis Labels and width of elements |
Posted by Peter Kwan on Apr-25-2015 02:05 |
|
Hi Ed,
I have just measured you chart image. It seems the image is 750 pixels wide. (The image
width is controlled by the "new XYChart(....)" line.
The plot area starts at x = 200, and is 550 wide. So the right edge of the plot area is at
750. This is also the position of the last x label, as ChartDirector simply spreads the x-axis
labels evenly across the bottom of the x-axis. But a label has a finite size, so half of the
label will end up outside the chart.
For your case, instead of 550, you may use 530. This will leave 20 pixels right margin (the
space between the right side of the plot area, and the right side of the image. This should
be more than enough for vertical labels.
The method I mentioned in my last message can be used to set the label spacing, that is,
to configure the plot area width. Another method is to increase the number of labels. You
can insert dummy labels (empty strings) to the labels array if you like.
Hope this can help.
Regards
Peter Kwan |
Re: Vertical X Axis Labels and width of elements |
Posted by Ed on Apr-25-2015 02:09 |
|
Ah, I see. I had thought that I had left a 100 pixel right margin but had made some adjustments over time to allow the y-axis labels to not get cut off. I will make the adjustments as well as add a dummy label at the end and remake the graph.
Thanks for the explanation. |
Re: Vertical X Axis Labels and width of elements |
Posted by Ed on Apr-25-2015 02:11 |
|
As a follow-up question, is there a way to determine the max length of the y-axis labels in the font to be used and then adjust the plot area left margin to fit this label length? |
Re: Vertical X Axis Labels and width of elements |
Posted by Ed on Apr-25-2015 02:14 |
|
And possibly the height of the vertical labels in pixels as well to adjust the plot area for both x-axis and y-axis label sizes? |
Re: Vertical X Axis Labels and width of elements |
Posted by Ed on Apr-25-2015 02:15 |
|
Definitely much better with the width at 530 and a blank label added to the end.
|
Re: Vertical X Axis Labels and width of elements |
Posted by Peter Kwan on Apr-25-2015 15:40 |
|
Hi Ed,
You may consider the "XYChart.packPlotArea" API, which can fine tune the plot area size
based on the label size. It can adjust the plot area height based on the horizontal axis
labels (x-axis for your case), and the plot area width based on the vertical axis labels. Note
that it does not adjust the plot area width based on the horizontal axis labels, so you must
still explicitly reserve a margin at the right side for the x-axis labels, but this margin is easy
to handle.
http://www.advsofteng.com/doc/cdperl.htm#XYChart.packPlotArea.htm
There are some sample code in ChartDirector that uses this API. For example, see:
http://www.advsofteng.com/doc/cdperl.htm#missingpoints.htm
Hope this can help.
Regards
Peter Kwan |
|