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

Message ListMessage List     Post MessagePost Message

  Y-Axis financial data to 8 decimal places
Posted by Neil on Mar-24-2019 07:35
Attachments:
Hi,

I'm using php, current evaulation version of ChartDirector downloaded a couple of days ago.

I've meddled around with one of the finance examples, replacing the randomized values with a snapshot of some real data and added a couple of test 'symbols'.

I intend to insert 'Demark Sequential' counts above and below the candles, this is the aim of my project. To implement the TD Sequential and show it on a chart when I detect it within the program.

I have two issues which I cant figure out

1 : The numbers on the right side of this large chart only display to 7 decimal places and I can't find how to change this to 8 decilam places. I've tried many different things related to formating over the last few hours and I simply don't udnerstand this huge library enough to figure it out so far.

I'm sure it's something very simple that I'm doing wrong.

The full code including sample data and attached generated image is in this message.

The second issue is that I added a scatter layer and it appeared that I can't add numbers as symbols but only pre defined shape symbols, I can add text characters as datafields which I have done, then I placed them over the pre defined symbol - see bar 5 on the candle chart - it actually shows a '9' but it's over the top of another tiny symbol - this achieves what I want but I'm sure there's a better way of doing it. Maybe I should use my own images as symbols or perhaps there's a way of adding text without needing a symbol?

So - 8 decimal places - this is for crypto charts and they do need 8 decimal places, if chartdirector can't do this then I guess I could convert all the data to integer values by multiplying by 10,000,000 but I would rather not do this.


Source Code (modified example) with real data - apologies for data length as I wanted to test with 100 bars so there's a lot of hard coded numbers in here :

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

// Setup test data
$timeStamps = array( 1553264100000,1553265000000,1553265900000,1553266800000,1553267700000,1553268600000,1553269500000,1553270400000,1553271300000,1553272200000,1553273100000,1553274000000,1553274900000,1553275800000,1553276700000,1553277600000,1553278500000,1553279400000,1553280300000,1553281200000,1553282100000,1553283000000,1553283900000,1553284800000,1553285700000,1553286600000,1553287500000,1553288400000,1553289300000,1553290200000,1553291100000,1553292000000,1553292900000,1553293800000,1553294700000,1553295600000,1553296500000,1553297400000,1553298300000,1553299200000,1553300100000,1553301000000,1553301900000,1553302800000,1553303700000,1553304600000,1553305500000,1553306400000,1553307300000,1553308200000,1553309100000,1553310000000,1553310900000,1553311800000,1553312700000,1553313600000,1553314500000,1553315400000,1553316300000,1553317200000,1553318100000,1553319000000,1553319900000,1553320800000,1553321700000,1553322600000,1553323500000,1553324400000,1553325300000,1553326200000,1553327100000,1553328000000,1553328900000,1553329800000,1553330700000,1553331600000,1553332500000,1553333400000,1553334300000,1553335200000,1553336100000,1553337000000,1553337900000,1553338800000,1553339700000,1553340600000,1553341500000,1553342400000,1553343300000,1553344200000,1553345100000,1553346000000,1553346900000,1553347800000,1553348700000,1553349600000,1553350500000,1553351400000,1553352300000,1553353200000);
$openData = array(0.00001129,0.0000116,0.00001146,0.00001141,0.00001149,0.00001161,0.00001158,0.00001145,0.00001132,0.00001126,0.00001133,0.00001122,0.00001122,0.00001137,0.00001124,0.00001125,0.00001127,0.00001128,0.00001125,0.0000112,0.00001115,0.00001106,0.00001108,0.00001107,0.00001097,0.00001077,0.00001087,0.000011,0.00001087,0.00001086,0.00001082,0.00001083,0.00001084,0.00001085,0.00001103,0.0000109,0.00001086,0.00001091,0.00001095,0.00001096,0.00001089,0.00001085,0.00001084,0.00001085,0.00001081,0.00001085,0.00001083,0.00001086,0.00001093,0.00001085,0.00001111,0.0000112,0.0000111,0.00001111,0.00001118,0.00001124,0.0000113,0.00001144,0.00001125,0.00001135,0.00001128,0.00001115,0.00001115,0.00001109,0.00001116,0.00001116,0.00001114,0.00001102,0.00001102,0.00001115,0.00001113,0.0000111,0.00001112,0.0000111,0.00001113,0.00001114,0.00001108,0.00001113,0.00001107,0.00001112,0.00001117,0.0000112,0.00001119,0.00001114,0.00001155,0.0000118,0.0000116,0.00001149,0.00001143,0.00001166,0.00001163,0.00001192,0.00001182,0.00001187,0.00001181,0.00001176,0.00001172,0.00001174,0.00001176,0.00001203);
$highData = array(0.0000117,0.00001165,0.0000115,0.00001159,0.00001172,0.00001167,0.00001161,0.00001157,0.0000114,0.00001133,0.00001133,0.00001126,0.00001148,0.00001143,0.0000113,0.00001134,0.0000114,0.00001128,0.00001125,0.00001121,0.00001118,0.00001114,0.00001111,0.00001108,0.00001097,0.00001091,0.00001109,0.00001102,0.00001091,0.00001088,0.00001087,0.00001093,0.00001087,0.00001105,0.00001103,0.0000109,0.00001095,0.00001099,0.00001099,0.00001096,0.00001089,0.00001088,0.00001087,0.00001087,0.00001085,0.00001088,0.00001087,0.00001095,0.00001093,0.00001115,0.00001126,0.00001122,0.00001114,0.00001117,0.00001124,0.00001135,0.00001145,0.00001147,0.0000114,0.00001137,0.00001132,0.0000112,0.00001115,0.0000112,0.00001117,0.00001117,0.00001117,0.00001106,0.00001117,0.00001119,0.0000112,0.00001115,0.00001113,0.00001113,0.00001121,0.00001114,0.00001115,0.00001117,0.00001113,0.00001117,0.00001125,0.00001126,0.00001122,0.00001166,0.00001182,0.0000118,0.00001163,0.00001154,0.00001167,0.00001166,0.00001198,0.00001194,0.00001189,0.00001189,0.00001186,0.0000119,0.00001181,0.00001178,0.00001212,0.00001209);
$lowData = array(0.00001125,0.0000114,0.0000113,0.00001133,0.00001148,0.00001153,0.00001137,0.0000113,0.00001115,0.00001125,0.0000111,0.00001114,0.00001122,0.0000112,0.0000112,0.0000112,0.00001125,0.00001121,0.00001116,0.00001109,0.00001105,0.00001104,0.00001104,0.00001091,0.00001073,0.00001077,0.00001086,0.00001083,0.00001074,0.00001079,0.00001075,0.00001081,0.00001079,0.00001085,0.00001088,0.00001081,0.00001086,0.00001088,0.00001089,0.00001086,0.00001081,0.00001082,0.00001081,0.00001078,0.00001075,0.00001082,0.0000108,0.00001085,0.00001082,0.00001082,0.00001105,0.00001104,0.00001104,0.00001106,0.00001115,0.00001122,0.00001128,0.00001125,0.00001122,0.00001127,0.00001113,0.00001112,0.00001105,0.00001107,0.00001109,0.00001105,0.00001092,0.00001095,0.00001098,0.00001109,0.00001106,0.00001108,0.00001108,0.00001107,0.0000111,0.00001103,0.00001104,0.00001105,0.00001105,0.00001111,0.00001116,0.00001116,0.00001114,0.00001112,0.0000115,0.00001155,0.00001143,0.0000114,0.00001141,0.00001154,0.00001161,0.00001173,0.00001169,0.00001175,0.00001167,0.0000117,0.0000117,0.00001166,0.00001176,0.00001188);
$closeData = array(0.0000116,0.00001148,0.00001141,0.00001148,0.00001161,0.00001158,0.00001143,0.00001132,0.00001126,0.00001133,0.00001122,0.00001122,0.00001136,0.00001124,0.00001124,0.00001127,0.00001129,0.00001125,0.00001119,0.00001115,0.00001106,0.00001108,0.00001108,0.00001098,0.00001078,0.00001086,0.000011,0.00001086,0.00001086,0.00001081,0.00001082,0.00001084,0.00001084,0.00001103,0.0000109,0.00001085,0.00001091,0.00001098,0.00001095,0.00001089,0.00001085,0.00001084,0.00001085,0.0000108,0.00001085,0.00001083,0.00001086,0.00001093,0.00001085,0.00001111,0.0000112,0.00001112,0.00001111,0.00001117,0.00001124,0.00001129,0.00001145,0.00001125,0.00001135,0.00001129,0.00001115,0.00001116,0.00001109,0.00001117,0.00001115,0.00001115,0.00001101,0.00001103,0.00001115,0.00001113,0.00001109,0.00001111,0.00001112,0.00001112,0.00001114,0.00001108,0.00001112,0.00001107,0.00001111,0.00001117,0.0000112,0.00001117,0.00001114,0.00001153,0.00001179,0.00001161,0.00001149,0.00001143,0.00001165,0.00001163,0.00001192,0.00001182,0.00001187,0.00001181,0.00001175,0.00001171,0.00001175,0.00001176,0.00001203,0.0000119);
$volData = array(17938323,7831283,3805286,3764273,6632897,3101203,3804050,4040749,5218694,2513775,3285667,1865259,4502938,2875207,1945579,2764222,2164549,1100290,1635795,2713179,1313175,1044308,1427226,6103499,5701804,3192639,4879551,1978197,2493919,929416,1894995,2561036,1425812,3142428,1235589,1685204,877528,1792087,1203171,1005020,1250021,515526,946330,1467921,2091277,1064182,1317987,1591155,816409,5300881,4821489,2291852,2179377,1153817,1298110,3137531,3392251,6340510,2829984,1227720,1922119,1146767,2434700,1601988,1942468,1585730,3889168,1427072,1686112,1572767,1752524,549136,877869,559068,1904320,900913,1147104,1477505,328954,1035791,3153258,1487627,1204849,9970424,16039581,7198660,7442143,3372443,4918984,1680509,12747952,3650554,6863257,2943535,2651989,2951360,2410282,1892488,7411004,7171395);
$buySignal = array(NoValue,NoValue,NoValue,NoValue,0.00001148, NoValue,NoValue,NoValue,NoValue,NoValue,NoValue, NoValue, NoValue, NoValue, NoValue, NoValue, NoValue, NoValue, NoValue, NoValue,NoValue, NoValue, NoValue, NoValue, NoValue, NoValue, NoValue, NoValue, NoValue, NoValue,NoValue, NoValue, NoValue, NoValue, NoValue, NoValue, NoValue, NoValue, NoValue, NoValue,NoValue, NoValue, NoValue, NoValue, NoValue, NoValue, NoValue, NoValue, NoValue, NoValue,NoValue, NoValue, NoValue, NoValue, NoValue, NoValue, NoValue, NoValue, NoValue, NoValue,NoValue, NoValue, NoValue, NoValue, NoValue, NoValue, NoValue, NoValue, NoValue, NoValue,NoValue, NoValue, NoValue, NoValue, NoValue, NoValue, NoValue, NoValue, NoValue, NoValue,NoValue, NoValue, NoValue, NoValue, NoValue, NoValue, NoValue, NoValue, NoValue, NoValue,NoValue, NoValue, NoValue, NoValue, NoValue, NoValue, NoValue, NoValue, NoValue, NoValue, NoValue, NoValue, NoValue, NoValue, NoValue);
$sellSignal = array(NoValue,NoValue,NoValue,NoValue,NoValue,0.00001167,NoValue,NoValue,NoValue,NoValue,NoValue, NoValue, NoValue, NoValue, NoValue, NoValue, NoValue, NoValue, NoValue, NoValue,NoValue, NoValue, NoValue, NoValue, NoValue, NoValue, NoValue, NoValue, NoValue, NoValue,NoValue, NoValue, NoValue, NoValue, NoValue, NoValue, NoValue, NoValue, NoValue, NoValue,NoValue, NoValue, NoValue, NoValue, NoValue, NoValue, NoValue, NoValue, NoValue, NoValue,NoValue, NoValue, NoValue, NoValue, NoValue, NoValue, NoValue, NoValue, NoValue, NoValue,NoValue, NoValue, NoValue, NoValue, NoValue, NoValue, NoValue, NoValue, NoValue, NoValue,NoValue, NoValue, NoValue, NoValue, NoValue, NoValue, NoValue, NoValue, NoValue, NoValue,NoValue, NoValue, NoValue, NoValue, NoValue, NoValue, NoValue, NoValue, NoValue, NoValue,NoValue, NoValue, NoValue, NoValue, NoValue, NoValue, NoValue, NoValue, NoValue, NoValue);

// Wide chart for 100 bars
$c = new FinanceChart(1600);

# Add a title to the chart
$c->addTitle("Finance Chart with Custom Symbols");

$c->setYAxisStyle("arialbd.ttf", 8, 0x000000, 10);
// 100 pixel margin is lots of space to show the 8 decimal place price but it only shows the price to 7 decimal places
$c->setMargins(50,50,100,50);

# Set the data into the finance chart object
$c->setData($timeStamps, $highData, $lowData, $openData, $closeData, $volData, $extraDays);

# Add the main chart with 600 pixels in height
$mainChart = $c->addMainChart(600);


# Add candlestick symbols to the main chart, using green/red for up/down days
$c->addCandleStick(0x66ff66, 0xff6666);


# Add buy signal symbols to the main chart, using cyan (0x00ffff) upward pointing arrows as symbols

// This works but doesn't do anything - I wonder if this 'value' is not the correct name
// for some reason it defaults to 7 decimal places - I need 8
$c->setNumberLabelFormat("{value|8.,}");

//GlassSphereShape
// Use a 1 pixel symbol - Can't seem to add the text label to the scatter chart without also adding a symbol
// All I need is a number/letter
$buyLayer = $mainChart->addScatterLayer(null, $buySignal, "Buy", GlassSphereShape, 5, 0x00ffff);

// Add labels to the buy symbols

// I could not find a way to get rid of the symbol and add data at the same time
// but I managed to overwrite the symbol with the data which is effectively the same - it looks the same anyway

//$labels = array(NoValue, "B",NoValue,NoValue,NoValue,NoValue,NoValue,NoValue,NoValue,NoValue);
$labels = array("A", "B","C","D","9","F","G","H","I","J");
//$buyLayer->addExtraField($labels);
$buyLayer->addExtraField($labels);

$buyLayer->setDataLabelFormat("{field0}");


$textbox = $buyLayer->setDataLabelStyle("arialbd.ttf", 8);
$textbox->setBackground(0xcc99ff, Transparent, 1);
$textbox->setAlignment(Right);
$textbox->setPos(8, 0);

# Shift the symbol lower by 20 pixels
$dataSetObj = $buyLayer->getDataSet(0);
// Original offset was 20 but that seemed a little far away - changed to 10
$dataSetObj->setSymbolOffset(0, 10);

// Use red 'down' arrow 0xff0000
$sellLayer = $mainChart->addScatterLayer(null, $sellSignal, "Sell", ArrowShape(180, 1, 0.4, 0.4), 11, 0xff0000);

# Shift the symbol higher by 20 pixels
$dataSetObj = $sellLayer->getDataSet(0);
$dataSetObj->setSymbolOffset(0, -10);


# Add a volume indicator chart (75 pixels high) after the main chart, using green/red/grey for
# up/down/flat days
$c->addVolIndicator(75, 0x99ff99, 0xff9999, 0x808080);


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

Image of chart generated by the above code is attached.


Thanks for any help. I will be buying once I get over the learning curve here.
finchart.jpg

  Re: Y-Axis financial data to 8 decimal places
Posted by Peter Kwan on Mar-25-2019 23:04
Hi Neil,

By default, for axis labels, ChartDirector will format it as short as possible. For example, if the label values are 1.3, 1.4, 1.5, ChartDirector will use "1.3", "1.4", "1.5" as the labels, but not "1.30", "1.40", "1.50". To override, you can use Axis.setLabelFormat to set the number of decimal places. For example:

# 8 decimal place
$mainChart->yAxis->setLabelFormat("{value|8}");

For the label, using a scatter layer is a common method to add text only symbols. Just set the scatter symbol to a 1 pixel transparent square, like:

#invisible symbols just to specify the position of the text labels
$buyLayer = $mainChart->addScatterLayer(null, $buySignal, "Buy", SquareShape, 1, Transparent, Transparent);

Hope this can help.

Regards
Peter Kwan

  Re: Y-Axis financial data to 8 decimal places
Posted by Neil on Mar-26-2019 04:06
Thanks - that fixed the two issues for me.

I did notice something else, it's present in the above original chart - there are no 'gaps' between the candles.

Is there any way to control this ?

I made a separate candle chart using similar data without the /lib/FinanceChart.php but instead using the XYChart class and it looks like the XYChart version has the 'correct' spaces between all the bars by default where on the above chart using the FinanceChart class most of them have no space at all between the candles and they touch but some of them do have a small amount of space.

Thanks

Neil