|
question about text in marks |
Posted by aldy on Jan-18-2012 10:29 |
|
Hi Peter, why is it that some letters of the texts using the addMark method looks cut-off no
matter what font I'm using. I just want to make them look the same as the info box at the
bottom of the chart. Any idea how to achieve this? It is important to make these texts
clear coz this will be used for presentation. Thanks in advance. In the attached example, I
used helvetica included with chartdirector.
|
Re: question about text in marks |
Posted by Peter Kwan on Jan-19-2012 01:39 |
|
Hi aldy,
I believe it is because the text is drawn using a dash line color. So the text is "dashed" too.
To create a mark as a dash line, with text which is not dashed, you may use something like:
$m = $c->addMark($myDataValue, -1, $myLabel);
$m->setMarkColor($myDashLineColor, $myTextColor, $myTextColor);
Hope this can help.
Regards
Peter Kwan |
Re: question about text in marks |
Posted by aldy on Jan-19-2012 18:38 |
|
Thanks Peter for the excellent help.
I have another 2 questions,
1. How can I get the height of the labels of x-axis? I can't seem to get it using getWidth()
method, what I want to achieve is to compute the y-position of texts that will be added at
the bottom of the chart without overlapping it with the x-axis title.
2. What's the best way so that the angle of the x-axis labels will auto-adjust based on their
length to avoid overlapping? |
Re: question about text in marks |
Posted by Peter Kwan on Jan-19-2012 23:49 |
|
Hi aldy,
1. What you probably need is the "thickness" of the axis, which consists of the "thickness" of the region occupied by the axis labels, as well as the axis title. The API is Axis.getThickness. To use this, you would need to enter all the data to the chart first (otherwise ChartDirector cannot know which axis scale to use), and then call BaseChart.layoutAxes (to tell ChartDirector everything has been entered and it can determine the axis scale). The code would be like:
... enter all data ...
$c->layoutAxes();
$thickness = $c->xAxis->getThickness();
In practice, a better strategy is to always put your text box at the bottom of the chart, and adjust the plot area height so that the axis labels and title will not overlap with the text box. The method to adjust the plot area is XYChart.packPlotArea. See "Multi-Symbol Line Chart" for an example.
2. You mentioned "to avoid overlapping". Do you mean that the x-axis labels overlap among themselves (such as the first label overlaps with the second label), or do you mean the labels overlap with the text box below it (which should be addressed with (1) above).
To configure the axis labels, the first thing we need to know is why there are axis labels. They can be set up from your code (eg. using Axis.setLabels), or they can be automatically generated by ChartDirector when the axis is auto-scaled (in your chart, the y-axis labels seem auto-scaled).
If your code specifies the labels, it should know the length and density of the labels, and it should be able to rotate them if necessary.
If the labels are determined by ChartDirector (and so your code do not know what are the labels), you may use Axis.setTickDensity to set a guaranteed spacing between labels. If the spacing is big enough, the labels should not overlap. However, if you feel that the labels can be very long (like 100000000000) so that they can overlap despite a large spacing, it usually means they are not easily readable anyway (it is hard to know how many zeros are there), and you should consider to format the numbers as something likes 100B (for 100 billions) to make it shorter. (See Axis.setLabelFormat and Axis.setFormatCondition)
Hope this can help.
Regards
Peter Kwan |
Re: question about text in marks |
Posted by aldy on Jan-24-2012 06:53 |
|
Thanks Peter, the getThickness() method works! For the second item, I meant that the
labels overlap each other, will still try your suggestion. |
|