|
Own Label Formatting Function |
Posted by Dan on Jul-08-2006 18:39 |
|
hi,
I tried to manually format all shown axis labels using something like this:
$this->chart->layout();
$ticks = $this->chart->xAxis->getTicks();
foreach ($ticks as $tick)
{
$labels[]=custom_format($this->chart->xAxis->getLabel($tick));
}
$this->chart->xAxis->setLabels(labels);
$this->chart->layout();
But this only produces wired results. Any ideas how to pass all label values to a custom formatting function and pass them back to chartdirector to finally draw them?
dan |
Re: Own Label Formatting Function |
Posted by Peter Kwan on Jul-09-2006 01:06 |
|
Hi Dan,
The Axis.setLabels may not be what you want, as it not only modifies the labels, but redefine the axis scale (to become a label based axis rather than a linear axis or date/time axis).
I suggest you try:
$this->chart->layout();
$ticks = $this->chart->xAxis->getTicks();
foreach ($ticks as $tick)
$this->chart->xAxis->addLabel($tick, custom_format($this->chart->xAxis->getLabel($tick)));
Hope this can help.
Regards
Peter Kwan |
Re: Own Label Formatting Function |
Posted by Dan on Jul-13-2006 15:38 |
|
Alright, I got it to work this way - thank you! Is there also a way to receive the "basic" label data (values) and not the preformattet data? the getlabel returns me the already formatted labels which is especially bad when I have dates as I need a timestamp and not a formatted date like mm/dd/yyyy.
Nevertheless, are there any plans for the next release to include a better country/language support, e.g. by simply passing the language ID (e.g. EN, DE,..) and chartdirector would use the standard number and date formattings for this country?
Thanks!
dan |
Re: Own Label Formatting Function |
Posted by Peter Kwan on Jul-13-2006 18:41 |
|
Hi Dan,
I believe in the following code, the $tick is already the "basic" label datum, while getLabel($tick) is the formatted label.
foreach ($ticks as $tick)
$this->chart->xAxis->addLabel($tick, custom_format($this->chart->xAxis->getLabel($tick)));
In programming language that supports date and time (such as .NET, Java, ASP/COM/VB), the ticks will be the native data format for that language. However, for PHP, there is no such thing as "date" data type, so the $tick will be in ChartDirector's chartTime format (see ChartDirector Documentation/ChartDirector Reference/Data Types/Date Time Specification). You may convert this format to a format you may use by using the getChartYMD function.
(Another common format in PHP is "UNIX timestamp", but this is not suitable for charts. First UNIX timestamp cannot represent time before year 1970. Also, there is no reasonable method to convert a "historical" UNIX timestamp to human readable format, because it is difficult to know the historical daylight time savings rules. For example, in UK alone, the daylight time savings rules have changed 10 times in the last 25 years. In some countries, the daylight time saving rules are changed on a year by year basis.)
Personally, I would think the best method is to format the x-axis in ISO format "yyyymmdd" commonly used in database. Then your code just parse the formatted labels (which would be in ISO format). For example:
$c->xAxis->setLabelFormat("{value|yyyymmdd}")
Hope this can help.
Regards
Peter Kwan |
|