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

Message ListMessage List     Post MessagePost Message

  Two X-axis with time.
Posted by mephy on Dec-17-2014 04:29
Hello.

I'm using this code to set first X-axis:
$layer->setXData($date);

$date is an array with chartTime2($time) values.
Everything is fine with fisrt axis.

But I need second X-axis with time.
How I can add it?
$c->xAxis2->setLabels() dont show time.

  Re: Two X-axis with time.
Posted by Peter Kwan on Dec-18-2014 02:13
Hi mephy,

You may refer to the "Dual X-Axes" sample code for an example of how to use two x-axes.

http://www.advsofteng.com/doc/cdphp.htm#dualxaxis.htm

In brief, you can set the labels on the second x-axis to any labels you want by providing
the labels:

$c->xAxis2->setLabels($myArrayOfLabels);

You can also set it to any scale you like. For example:

$c->xAxis2->setDateScale($startDate, $endDate);

Or, you can set the second x-axis to have a linear relationship with the first x-axis by using
Axis.syncAxis. For example:

$c->xAxis2->syncAxis($c->xAxis, 1, 0);

Hope this can help.

Regards
Peter Kwan

  Re: Two X-axis with time.
Posted by mephy on Dec-23-2014 03:21
Sorry, cant make it work.

$date is an array:
Array ( [0] => 63554631519 [1] => 63554634393 [2] => 63554637585 [3] => 63554640411
[4] => 63554643663 [5] => 63554649753 [6] => 63554655849 [7] => 63554661951 [8] =>
63554665101 [9] => 63554668071 [10] => 63554671329 [11] => 63554674221 [12] =>
63554677455 [13] => 63554680383 [14] => 63554683521 [15] => 63554686491 [16] =>
63554689527 [17] => 63554692527 [18] => 63554695503 [19] => 63554698539 [20] =>
63554701479 [21] => 63554704557 [22] => 63554707473 [23] => 63554710587 [24] =>
63554713491 [25] => 63554716635 )

$date2 - similar array (every value +-15 mins)

Code:

$c->xAxis->setDateScale2($date[0],$date[count($date)],$date);
$c->xAxis->setMultiFormat(StartOfDayFilter(), "<*font=arialbd.ttf*>{value|mmm dd}",
StartOfHourFilter(), "{value|hh:nn}");

$c->xAxis2->setDateScale2($date2[0],$date2[count($date['mm2'])],$date2);
$c->xAxis2->setMultiFormat(StartOfDayFilter(), "<*font=arialbd.ttf*>{value|mmm dd}",
StartOfHourFilter(), "{value|hh:nn}");

Both axes shows up, but I get values like 63554716635 in the chart.

+ a question - how can I set values $data1 to xAxis and $datas2 to xAxis2?

  Re: Two X-axis with time.
Posted by Peter Kwan on Dec-23-2014 22:08
Hi mephy,

It should be $date[$count($date) - 1], not $date[$count($date)]. Also, it is not
$date2[count($date['mm2'])], but $date2[count($date2) - 1].

There is no need to supply the $date array to setDateScale2. The third argument to
setDate2 are expected to be the labels themselves, not the positions or values of the
labels. So anything in the third argument will be displayed as is.

For your case, I suggest the following code:

$c->xAxis->setDateScale($date[0], $date[count($date) - 1]);
$c->xAxis->setMultiFormat(StartOfDayFilter(), "<*font=arialbd.ttf*>{value|mmm dd}",
StartOfHourFilter(), "{value|hh:nn}");

$c->xAxis2->setDateScale($date2[0], $date2[count($date2) - 1]);
$c->xAxis2->setMultiFormat(StartOfDayFilter(), "<*font=arialbd.ttf*>{value|mmm dd}",
StartOfHourFilter(), "{value|hh:nn}");

With the above code, ChartDirector will automatically generate the labels for the x-axis
(just like ChartDirector will automatically generate the labels for the y-axis).

If you really want the $date array to represent the values and positions of the labels
(note that for your $date array, the positions are not be evenly spaced), you may trying
something like:

$c->xAxis->setDateScale2($date[0], $date[count($date) - 1], array());
for ($i = 0; $i < count($date); ++$i)
    $c->xAxis->addLabel($date[$i], $c->formatValue($date[$i], "{value|hh:nn}"));

Hope this can help.

Regards
Peter Kwan

  Re: Two X-axis with time.
Posted by mephy on Dec-24-2014 03:44
Attachments:
I'll better show what I want :)

Coordinates: (see picture below)
red line:
00:00 - 25
12:00 - 50
24:00 - 25

green line:
06:00 - 50
12:00 - 0
18:00 - 100

Is it possible with chartdir?
Maybe some constant like NoValue to assign to red line at 6:00?

I can calculate average value, but I dont want a point with value (I'm also using track line
js). - there isnt real value at that period.
quest.png

  Re: Two X-axis with time.
Posted by Peter Kwan on Dec-24-2014 23:30
Hi Mephy,

For your case, you only need one x-axis, which is the x-axis at the bottom of your chart.
There are line layers for the two lines. The x-coordinates of the two lines can be set using
Layer.setXData and can be different. There is no need to use NoValue points. You may refer
to the sample code "Uneven Data Points" for an example:

http://www.advsofteng.com/doc/cdphp.htm#unevenpoints.htm

Hope this can help.

Regards
Peter Kwan