|
Getting no values on Open/High low labels on finance charts |
Posted by icasper on Feb-16-2012 00:13 |
|
Hi, Please see attached chart, I am not seeing any values on Open, high low etc., it
shows "P3", here is the code for the same.
$chartDataResult = mysql_query ("SELECT
UNIX_Timestamp(PX_DATE),PX_OPEN,PX_HIGH,PX_LOW,PX_CLOSE,VOLUME FROM
history_px WHERE ID_SYMBOL = '4' ORDER BY PX_DATE limit 600") or die(mysql_error());
$chartNumberOfDays = mysql_num_rows($chartDataResult);
while ($chartDataRow = mysql_fetch_row($chartDataResult))
{
// $theDate[] = str_replace("-","",$chartDataRow[0]);
// $theChartDate[] = chartTime(str_replace("-","",$chartDataRow[0]));
$theChartDate[] = chartTime2($chartDataRow[0]);
$theOpen[] = $chartDataRow[1];
$theHigh[] = $chartDataRow[2];
$theLow[] = $chartDataRow[3];
$theClose[] = $chartDataRow[4];
$theVolume[] = $chartDataRow[5];
}
//print_r($theDate);
//print_r($theChartDate);
$chartWidth = 600;
$chartHight = 400;
$rightMargin = 40;
$extraDays = 30;
# Create a FinanceChart object of width 640 pixels
$c = new FinanceChart($chartWidth);
# Set the data into the finance chart object
$c->setData($theChartDate, $theHigh, $theLow, $theOpen, $theClose, $theVolume,
$extraDays);
# add line layer
$o = $c->addMainChart($chartHight);
# Add an HLOC symbols to the main chart, using green/red for up/down days
$mainType = $_REQUEST["ChartType"];
if ($mainType == "Close") {
$c->addCloseLine(0x000040);
} else if ($mainType == "TP") {
$c->addTypicalPrice(0x000040);
} else if ($mainType == "WC") {
$c->addWeightedClose(0x000040);
} else if ($mainType == "Median") {
$c->addMedianPrice(0x000040);
}
if ($mainType == "CandleStick") {
$c->addCandleStick(0x33ff33, 0xff3333);
} else if ($mainType == "OHLC") {
$c->addHLOC(0x008800, 0xcc0000);
}
//$c->addCandleStick(0x00ff00, 0xff0000);
# Freeze chart and auto-scale axis
//$c->addVolBars(100, 0x99ff99, 0xff9999, 0x808080);
$c->addVolIndicator(120, $theVolume, 0x99ff99, "Volume");
//$c->addVolIndicator();
$c->addSimpleMovingAvg(50, 0x663300);
# Add a 20 period simple moving average to the main chart, using purple color
$c->addSimpleMovingAvg(200, 0x9900ff);
$c->layout();
# DRAW LINE
$lineDate = "20090421";
#convert date
function convertDateToChartTime($date)
{
$y = date('Y', strtotime("$date"));
$d = date('d', strtotime("$date"));
$m = date('m', strtotime("$date"));
return chartTime($y, $m, $d);
}
$chartLineDate = convertDateToChartTime($lineDate);
//calculate X coordinates in pixels
function getPositionX($theChartDate,$chartLineDate,$chartWidth,$chartNumberOfDays)
{
while ($pos = current($theChartDate))
{
if ($pos == $theChartDate)
{
return key($theChartDate) * $chartWidth / $chartNumberOfDays;
}
next($theChartDate);
}
}
$xCoor = getPositionX($theChartDate,$chartLineDate,$chartWidth,$chartNumberOfDays);
//get Y coordinates based on price
//$yCoor = $o->getYCoor(17.25);
#add horizontal line
//$o->addLine($xCoor, $yCoor, $chartWidth, $yCoor, 0xff8888, 2);
# Output the chart
header("Content-type: image/png");
print($c->makeChart2(PNG));
2) In addition, can u tell me how to put a text label at y-axis which will show the last
price of the stocks.
Many Thanks
|
Re: Getting no values on Open/High low labels on finance charts |
Posted by Peter Kwan on Feb-16-2012 01:48 |
|
Hi icasper,
The FinanceChart library you are using seems to come from ChartDirector Ver 5. The "P3" formatting it is using will only work with ChartDirector Ver 5. Is your ChartDirector library being Ver 5?
You may add the following line in your code. This will display the version in the chart title:
$c->addTitle(dechex(getVersion()));
The leftmost digit is the major version number of ChartDirector, which needs to be Ver 5 to use the Ver 5 FinanceChart library. If you are using an earlier version of ChartDirector, you may consider to upgrade to ChartDirector Ver 5, or use the FinanceChart library that comes with the ChartDirector version you are using.
Hope this can help.
Regards
Peter Kwan |
Re: Getting no values on Open/High low labels on finance charts |
Posted by Peter Kwan on Feb-16-2012 01:52 |
|
Hi icasper,
To put the last closing price on the y-axis of the main price chart, you may use:
$lastPrice = $theClose[count($theClose) - 1];
$mark = $o->yAxis->addMark($lastPrice, -1, $lastPrice);
$mark->setMarkColors(Transparent, 0x000000, 0x9999ff);
$mark->setBackground(0x9999ff);
Hope this can help.
Regards
Peter Kwan |
Re: Getting no values on Open/High low labels on finance charts |
Posted by icasper on Feb-16-2012 21:33 |
|
Hi, I put the code as you suggest, but I m not getting chart, error loading chart with an
image comes. can u check;
$chartDataResult = mysql_query ("SELECT
UNIX_Timestamp(PX_DATE),PX_OPEN,PX_HIGH,PX_LOW,PX_CLOSE,VOLUME FROM
history_px WHERE ID_SYMBOL = '4' ORDER BY PX_DATE limit 100") or die(mysql_error());
$chartNumberOfDays = mysql_num_rows($chartDataResult);
while ($chartDataRow = mysql_fetch_row($chartDataResult))
{
// $theDate[] = str_replace("-","",$chartDataRow[0]);
// $theChartDate[] = chartTime(str_replace("-","",$chartDataRow[0]));
$theChartDate[] = chartTime2($chartDataRow[0]);
$theOpen[] = $chartDataRow[1];
$theHigh[] = $chartDataRow[2];
$theLow[] = $chartDataRow[3];
$theClose[] = $chartDataRow[4];
$theVolume[] = $chartDataRow[5];
}
//print_r($theDate);
//print_r($theChartDate);
$chartWidth = 600;
$chartHight = 400;
$rightMargin = 40;
$extraDays = 30;
# Create a FinanceChart object of width 640 pixels
$c = new FinanceChart($chartWidth);
# Set the data into the finance chart object
$c->setData($theChartDate, $theHigh, $theLow, $theOpen, $theClose, $theVolume,
$extraDays);
# add line layer
$o = $c->addMainChart($chartHight);
# Add an HLOC symbols to the main chart, using green/red for up/down days
$lastPrice = $theClose[count($theClose) - 1];
$mark = $o->yAxis->addMark($lastPrice, -1, $lastPrice);
$mark->setMarkColors(Transparent, 0x000000, 0x9999ff);
$mark->setBackground(0x9999ff);
$mainType = $_REQUEST["ChartType"];
if (!isset($mainType))
{
$mainType="Close";
}
if ($mainType == "Close") {
$c->addCloseLine(0x000040);
} else if ($mainType == "TP") {
$c->addTypicalPrice(0x000040);
} else if ($mainType == "WC") {
$c->addWeightedClose(0x000040);
} else if ($mainType == "Median") {
$c->addMedianPrice(0x000040);
}
if ($mainType == "CandleStick") {
$c->addCandleStick(0x33ff33, 0xff3333);
} else if ($mainType == "OHLC") {
$c->addHLOC(0x008800, 0xcc0000);
}
//$c->addCandleStick(0x00ff00, 0xff0000);
# Freeze chart and auto-scale axis
//$c->addVolBars(100, 0x99ff99, 0xff9999, 0x808080);
$c->addVolIndicator(100, 0x99ff99, 0xff9999, 0x808080);
//$c->addVolIndicator(120, $theVolume, 0x99ff99, "Volume");
//$c->addVolIndicator();
$c->addSimpleMovingAvg(50, 0x663300);
# Add a 20 period simple moving average to the main chart, using purple color
$c->addSimpleMovingAvg(200, 0x9900ff);
$c->layout();
# DRAW LINE
//$lineDate = "20090421";
#convert date
function convertDateToChartTime($date)
{
$y = date('Y', strtotime("$date"));
$d = date('d', strtotime("$date"));
$m = date('m', strtotime("$date"));
return chartTime($y, $m, $d);
}
$chartLineDate = convertDateToChartTime($lineDate);
//calculate X coordinates in pixels
function getPositionX($theChartDate,$chartLineDate,$chartWidth,$chartNumberOfDays)
{
while ($pos = current($theChartDate))
{
if ($pos == $theChartDate)
{
return key($theChartDate) * $chartWidth / $chartNumberOfDays;
}
next($theChartDate);
}
}
/*$xCoor =
getPositionX($theChartDate,$chartLineDate,$chartWidth,$chartNumberOfDays);
//get Y coordinates based on price
$yCoor = $o->getYCoor(17.25);
#add horizontal line
$o->addLine($xCoor, $yCoor, $chartWidth, $yCoor, 0xff8888, 2);
*/
# Output the chart
header("Content-type: image/png");
print($c->makeChart2(PNG)); |
Re: Getting no values on Open/High low labels on finance charts |
Posted by Peter Kwan on Feb-17-2012 00:50 |
|
Hi icasper,
Sorry. The setMarkColors should be setMarkColor instead.
In case you encounter any error, you may obtain the error message. It should provide information on what is the problem. If what you see is a broken image symbol (a small red X), please go into symbol to read the error message. See:
http://www.chartdir.com/forum/download_thread.php?site=chartdir&bn=chartdir_faq&thread=1117817200
For PHP, please make sure you have configured your server to report errors to the browser. Production servers may be configured not to report errors to the browsers to avoid end users seeing the error messages (in which case you would need to read the server error log to see the error messages). It is suggsted development servers should be configured to report errors to the browsers so that the developers can see them easily. For PHP, many pre-compiled distributions are configured as production servers and would not report errors to the browsers. You may want to re-configure them to report errors to the browsers.
Hope this can help.
Regards
Peter Kwan |
|