|
How to change the scale and labels for X axis - Finance CHart |
Posted by Ale on Jul-22-2014 08:12 |
|
Hi Peter,
I'm working on some financial chart in PHP, I'm not an expert programmer and I need to
change the style of the X Axis. By default My chart generate the first (top) X Axis
screen capture and I want to obtain something like the second (bottom) screen capture.
Bold font for months and between the months some days (dates) are showed.
Thx in advance.
|
Re: How to change the scale and labels for X axis - Finance CHart |
Posted by Peter Kwan on Jul-23-2014 05:42 |
|
Hi Ale,
You can use Axis.setLabels to set any labels you want. Note that for the FinanceChart, you should set the labels for the first chart (the chart in the top). ChartDirector will copy them to the indicator charts added later.
For example:
#assume the main price chart is the first chart in the FinanceChart
$firstChart = $c->addMainChart(240);
#use any $labels array you want
$firstChart->xAxis->setLabels($labels);
To use the above code, you need to write some code to generate the labels you want and store them into the $labels array. Then you can pass the array to ChartDirector to be used as the axis labels.
For your particular case, the following is an example of how such an array can be generated:
$firstChart= $c->addMainChart(240);
# Create month labels
for ($i = 0; $i < count($timeStamps); ++$i)
$labels[] = floor((getChartYMD($timeStamps[$i]) % 10000) / 100);
# Remove duplicated month labels
for ($i = count($labels) - 1; $i > 0; --$i)
$labels[$i] = ($labels[$i] == $labels[$i - 1]) ? NULL : $firstChart->formatValue($timeStamps[$i], "<*font=bold*>{value|mmm}");
# 1899-1-1 is a sunday
$sunday = chartTime(1899, 1, 1);
for ($i = 1; $i < count($timeStamps); ++$i) {
# If the number of weeks elapsed since the sunday for today is same as that of yesterday, it is the same
# week as yesterday, and so no need to put another weekly label
if (floor(($timeStamps[$i] - $sunday) / 86400 / 7) == floor(($timeStamps[$i - 1] - $sunday) / 86400 / 7))
continue;
# Before putting the weekly label, make sure there is no month label within 3 days to avoid overlapping
for ($j = $i - 3; ($j <= $i + 3) && (!$labels[$j]); ++$j);
if ($j > $i + 3)
$labels[$i] = $firstChart->formatValue($timeStamps[$i], "{value|d}");
}
$firstChart->xAxis()->setLabels($labels);
Hope this can help.
Regards
Peter Kwan |
Re: How to change the scale and labels for X axis - Finance CHart |
Posted by Ale on Jul-27-2014 06:47 |
|
Thx. Peter!! I will try this! |
|