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

Message ListMessage List     Post MessagePost Message

  Y-axis Chart syncYAxis
Posted by Don on Aug-07-2018 22:05
Attachments:
I have a question related to the dual Y-axis Chart syncYAxis. Please see the example output image below.

My requirements are: there are two Y-axes. The HOLC line is plotted to the right-side Y-axis. The blue line is plotted to the left-side Y-axis.

Both Y-axes are set to Log Scale. In addition, I want the left-side Y-axis value 1  align to value 15 of right-side Y-axis. I tried to use $c->syncYAxis(1 / 15); in my testing code. It seems working for the alignment but part of the blue line is outside of the plot area as you can see the chart below. Also, the labels on the left-side Y-axis looks not very good. I tried to use Axis.setLogScale2 with lowerLimit and upperLimit but not working.

Do you have any suggestions how to solve this problem? I put the complete testing PHP code below for your convenience.

Thank you very much!


///////////////////////////

<?php

require_once("../lib/FinanceChart.php");

$highData = Array(
    25.62,
    24.22,
    15.86,
    15.86,
    14.29,
    13.51,
    14.64,
    15.70,
    17.98,
    19.40,
    20.67,
    23.34,
    24.29,
    26.59,
    29.31,
    29.57,
    30.23,
    30.72,
    29.23,
    33.69,
    38.69,
    38.05,
    39.15,
    37.73,
    37.57,
    41.76,
    45.43,
    45.52,
    46.50,
    49.78,
    51.88,
    51.43,
    50.43,
    49.94,
    49.44,
    57.63,
    56.68,
    59.06,
    60.32,
    58.03,
    58.08,
    65.21,
    77.49,
    88.23,
    90.89,
    83.71,
    83.92,
    87.76,
    96.53,
    100.30,
    95.92,
    85.22,
    83.74,
    78.43,
    68.56,
    66.23,
    63.25,
    66.26,
    64.39,
    64.76,
    72.53,
    72.31,
    75.99,
    79.44,
    81.44,
    80.15,
    78.00,
    77.86,
    84.87,
    90.77,
    94.25,
    99.02,
    102.50,
    103.30,
    108.00,
    119.00,
    115.93,
    118.90,
    133.00,
    129.36,
    132.65,
    132.54,
    130.54,
    132.07,
    119.72,
    116.41,
    120.53,
    122.57,
    119.03,
    105.35,
    98.12,
    109.56,
    112.10,
    100.41,
    99.65,
    104.34,
    109.48,
    115.57,
    118.25,
    111.80,
    117.26,
    121.95,
    137.11,
    144.12,
    144.77,
    156.10,
    155.45,
    153.46,
    164.00,
    164.05,
    169.04,
    176.24,
    176.42,
    179.26,
    178.97,
    181.72,
    178.24,
    190.04,
    193.98,
    194.82,
    207.99
);

$lowData = Array(

    23.37,
    15.04,
    12.68,
    11.50,
    12.15,
    11.17,
    12.42,
    11.87,
    15.53,
    17.07,
    19.14,
    19.34,
    22.80,
    23.60,
    25.84,
    26.96,
    26.99,
    27.44,
    27.44,
    29.84,
    33.71,
    33.69,
    34.74,
    35.08,
    34.28,
    35.76,
    39.81,
    42.93,
    45.20,
    46.67,
    48.37,
    47.14,
    46.78,
    47.46,
    45.05,
    49.04,
    50.46,
    53.44,
    52.83,
    51.94,
    54.13,
    57.86,
    65.02,
    75.75,
    80.04,
    75.73,
    80.14,
    82.13,
    86.69,
    94.37,
    85.05,
    75.09,
    72.80,
    62.84,
    63.06,
    60.01,
    55.79,
    61.26,
    56.25,
    58.46,
    64.92,
    64.30,
    68.71,
    73.21,
    77.78,
    71.40,
    71.65,
    74.96,
    73.99,
    83.65,
    89.81,
    93.09,
    94.48,
    97.87,
    96.26,
    108.60,
    106.75,
    105.99,
    118.63,
    122.24,
    124.25,
    125.01,
    124.53,
    120.07,
    103.12,
    107.72,
    109.50,
    112.34,
    105.26,
    93.42,
    93.70,
    100.53,
    93.74,
    90.34,
    92.04,
    94.99,
    104.48,
    103.13,
    112.52,
    105.71,
    109.11,
    115.82,
    128.53,
    138.68,
    140.68,
    146.53,
    142.27,
    142.73,
    150.05,
    150.55,
    153.48,
    166.89,
    169.01,
    166.97,
    155.15,
    164.94,
    162.32,
    169.10,
    182.17,
    183.92,
    201.50
);

$openData = Array(
    22.84,
    24.22,
    15.99,
    15.13,
    13.04,
    12.19,
    12.73,
    12.59,
    14.87,
    17.97,
    19.50,
    20.50,
    23.60,
    24.00,
    26.50,
    27.12,
    28.89,
    30.10,
    27.51,
    29.39,
    33.95,
    37.77,
    37.10,
    36.30,
    37.21,
    35.36,
    40.91,
    43.23,
    45.11,
    46.56,
    48.79,
    50.75,
    50.16,
    49.96,
    49.87,
    47.99,
    56.86,
    55.14,
    54.34,
    56.71,
    54.64,
    57.86,
    65.50,
    78.31,
    85.99,
    83.56,
    81.29,
    83.53,
    87.98,
    95.03,
    95.93,
    85.46,
    84.81,
    76.02,
    65.62,
    62.57,
    63.14,
    63.50,
    64.35,
    57.56,
    65.04,
    69.60,
    68.35,
    74.91,
    79.71,
    80.15,
    71.77,
    74.74,
    76.84,
    84.57,
    90.57,
    93.56,
    95.00,
    102.50,
    100.59,
    108.22,
    118.81,
    110.38,
    118.05,
    129.25,
    124.82,
    126.10,
    131.20,
    126.90,
    121.50,
    110.15,
    109.07,
    119.87,
    118.75,
    105.26,
    96.47,
    97.65,
    108.78,
    93.97,
    99.02,
    95.49,
    104.41,
    106.14,
    112.71,
    113.46,
    110.37,
    115.82,
    127.03,
    137.89,
    143.71,
    145.10,
    153.17,
    144.88,
    149.10,
    164.80,
    154.26,
    169.87,
    169.95,
    170.16,
    167.17,
    178.54,
    167.88,
    166.41,
    187.99,
    183.82,
    119.13
);

$closeData = Array(
    24.22,
    16.24,
    15.37,
    13.24,
    12.19,
    12.88,
    12.76,
    15.02,
    17.98,
    19.40,
    20.35,
    23.34,
    24.03,
    26.48,
    26.93,
    28.56,
    30.10,
    27.44,
    29.23,
    33.57,
    37.30,
    36.70,
    35.93,
    36.75,
    34.73,
    40.54,
    43.00,
    44.45,
    46.08,
    48.47,
    50.46,
    49.79,
    50.02,
    49.69,
    47.95,
    55.78,
    54.98,
    54.47,
    57.83,
    54.60,
    57.86,
    65.21,
    77.49,
    85.65,
    83.43,
    82.53,
    83.43,
    87.25,
    95.03,
    95.30,
    85.05,
    83.61,
    76.02,
    65.07,
    63.06,
    63.24,
    63.25,
    64.25,
    56.65,
    64.65,
    69.60,
    68.11,
    74.67,
    79.44,
    80.15,
    71.51,
    75.18,
    76.68,
    84.30,
    90.43,
    92.93,
    95.60,
    102.50,
    100.75,
    108.00,
    118.93,
    110.38,
    117.16,
    128.46,
    124.43,
    125.15,
    130.28,
    125.43,
    121.30,
    112.76,
    110.30,
    119.50,
    118.30,
    105.26,
    97.34,
    96.69,
    108.99,
    93.74,
    99.86,
    95.60,
    104.21,
    106.10,
    113.05,
    113.54,
    110.52,
    115.82,
    121.35,
    136.99,
    143.66,
    143.65,
    152.76,
    144.02,
    148.73,
    164.00,
    154.12,
    169.04,
    169.48,
    169.23,
    167.43,
    178.12,
    167.78,
    165.26,
    187.50,
    185.11,
    190.29,
    207.99
);

$timeStampsYM = Array(
    '2008-08',
    '2008-09',
    '2008-10',
    '2008-11',
    '2008-12',
    '2009-01',
    '2009-02',
    '2009-03',
    '2009-04',
    '2009-05',
    '2009-06',
    '2009-07',
    '2009-08',
    '2009-09',
    '2009-10',
    '2009-11',
    '2009-12',
    '2010-01',
    '2010-02',
    '2010-03',
    '2010-04',
    '2010-05',
    '2010-06',
    '2010-07',
    '2010-08',
    '2010-09',
    '2010-10',
    '2010-11',
    '2010-12',
    '2011-01',
    '2011-02',
    '2011-03',
    '2011-04',
    '2011-05',
    '2011-06',
    '2011-07',
    '2011-08',
    '2011-09',
    '2011-10',
    '2011-11',
    '2011-12',
    '2012-01',
    '2012-02',
    '2012-03',
    '2012-04',
    '2012-05',
    '2012-06',
    '2012-07',
    '2012-08',
    '2012-09',
    '2012-10',
    '2012-11',
    '2012-12',
    '2013-01',
    '2013-02',
    '2013-03',
    '2013-04',
    '2013-05',
    '2013-06',
    '2013-07',
    '2013-08',
    '2013-09',
    '2013-10',
    '2013-11',
    '2013-12',
    '2014-01',
    '2014-02',
    '2014-03',
    '2014-04',
    '2014-05',
    '2014-06',
    '2014-07',
    '2014-08',
    '2014-09',
    '2014-10',
    '2014-11',
    '2014-12',
    '2015-01',
    '2015-02',
    '2015-03',
    '2015-04',
    '2015-05',
    '2015-06',
    '2015-07',
    '2015-08',
    '2015-09',
    '2015-10',
    '2015-11',
    '2015-12',
    '2016-01',
    '2016-02',
    '2016-03',
    '2016-04',
    '2016-05',
    '2016-06',
    '2016-07',
    '2016-08',
    '2016-09',
    '2016-10',
    '2016-11',
    '2016-12',
    '2017-01',
    '2017-02',
    '2017-03',
    '2017-04',
    '2017-05',
    '2017-06',
    '2017-07',
    '2017-08',
    '2017-09',
    '2017-10',
    '2017-11',
    '2017-12',
    '2018-01',
    '2018-02',
    '2018-03',
    '2018-04',
    '2018-05',
    '2018-06',
    '2018-07',
    '2018-08'
);

$epsNriDataArrChart = Array(
    NoValue,
    0.383,
    NoValue,
    NoValue,
    0.357,
    NoValue,
    NoValue,
    0.256,
    NoValue,
    NoValue,
    0.287,
    NoValue,
    NoValue,
    0.397,
    NoValue,
    NoValue,
    0.524,
    NoValue,
    NoValue,
    0.476,
    NoValue,
    NoValue,
    0.501,
    NoValue,
    NoValue,
    0.663,
    NoValue,
    NoValue,
    0.919,
    NoValue,
    NoValue,
    0.914,
    NoValue,
    NoValue,
    1.113,
    NoValue,
    NoValue,
    1.007,
    NoValue,
    NoValue,
    1.981,
    NoValue,
    NoValue,
    1.757,
    NoValue,
    NoValue,
    1.331,
    NoValue,
    NoValue,
    1.241,
    NoValue,
    NoValue,
    1.973,
    NoValue,
    NoValue,
    1.441,
    NoValue,
    NoValue,
    1.07,
    NoValue,
    NoValue,
    1.19,
    NoValue,
    NoValue,
    2.07,
    NoValue,
    NoValue,
    1.66,
    NoValue,
    NoValue,
    1.28,
    NoValue,
    NoValue,
    1.42,
    NoValue,
    NoValue,
    3.06,
    NoValue,
    NoValue,
    2.33,
    NoValue,
    NoValue,
    1.85,
    NoValue,
    NoValue,
    1.97,
    NoValue,
    NoValue,
    3.28,
    NoValue,
    NoValue,
    1.9,
    NoValue,
    NoValue,
    1.42,
    NoValue,
    NoValue,
    1.69,
    NoValue,
    NoValue,
    3.36,
    NoValue,
    NoValue,
    2.1,
    NoValue,
    NoValue,
    1.67,
    NoValue,
    NoValue,
    2.07,
    NoValue,
    NoValue,
    3.89,
    NoValue,
    NoValue,
    2.73,
    NoValue,
    NoValue,
    2.34,
    NoValue,
    NoValue
);



# Create a XYChart object of size 600 x 350 pixels
$c = new XYChart(1200, 800);


$plotAreaObj = $c->setPlotArea(50, 25, 1100, 700);
$plotAreaObj->setGridColor(0xc0c0c0, 0xc0c0c0);

$c->syncYAxis(1 / 15);

$labelsObj = $c->xAxis->setLabels($timeStampsYM);
$c->xAxis->setLabelStep(10);

$c->yAxis->setLogScale();

$c->setYAxisOnRight(true);

$layer = $c->addHLOCLayer3($highData, $lowData, $openData, $closeData, 0x008000, 0xff0000);

$layer->setLineWidth(2);

$c->yAxis2()->setLogScale();

$lineLayer = $c->addLineLayer();

$earningDataSetOjb = $lineLayer->addDataSet($epsNriDataArrChart, 0x0000cc, "Earnings Per Share(TTM)");

$earningDataSetOjb->setDataSymbol(CircleSymbol, 6);
$lineLayer->setLineWidth(2);
$lineLayer->setUseYAxis2();
$lineLayer->setGapColor(SameAsMainColor);


# Output the chart
header("Content-type: image/png");
print($c->makeChart2(PNG));
chartSample.png

  Re: Y-axis Chart syncYAxis
Posted by Peter Kwan on Aug-08-2018 04:38
Hi Don,

If you use syncYAxis, then the two y-axes have a fixed relationship. The two axes can be treated as displaying the same quantity, but in different units. For example, we can image one axis is for displaying the length in feet, and the other axis is for displaying the same length in meters.

For this type of charts, it is best to use one of the axes to plot all the value. The other axis is just for human reading.

For example, in your case, you can plot the $epsNriDataArrChart using the right y-axis, like:

# change the data to use right y-axis unit
for ($i = 0; $i < count($epsNriDataArrChart); ++$i)
    $epsNriDataArrChart[$i] = $epsNriDataArrChart[$i] * 15;

$earningDataSetOjb = $lineLayer->addDataSet($epsNriDataArrChart, 0x0000cc, "Earnings Per Share(TTM)");

$earningDataSetOjb->setDataSymbol(CircleSymbol, 6);
$lineLayer->setLineWidth(2);
#######  $lineLayer->setUseYAxis2();   ### Do not use this line
$lineLayer->setGapColor(SameAsMainColor);

With the above method, the right y-axis will be auto-scaled so that the line will stay within the plot area, so the line would not fall outside of the plot area, and you still have the left y-axis for human reading of the TTM values.

With dependent axis, the labels on the second axis may not show "nice" values if the ratio is not "nice". For example, if you have syncAxis(0.326516), it is quite possible the labels on the second axis is not "nice". If the ratio is nice (eg. the ratio is 1.0/10 or 1.0/20), then the labels will be nice too.

Regards
Peter Kwan