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

Message ListMessage List     Post MessagePost Message

  Finance Chart not working
Posted by techsoft on Apr-27-2015 19:41
Attachments:
hi,
I have downloaded the chartdir trial version in php. I'm trying to pull my datas into
financedemochart.php but its not showing the chart image. Below is what i have done so
far.
financedemochart.php
financedemochart.php

25.00 Kb

  Re: Finance Chart not working
Posted by techsoft on Apr-27-2015 19:43
I'm trying in the below function.

function generateRandomData($ticker, $startDate, $endDate, $resolution) {

    global $timeStamps, $volData, $highData, $lowData, $openData, $closeData;

    /*$db = new FinanceSimulator($ticker, $startDate, $endDate, $resolution);
    $timeStamps = $db->getTimeStamps();
    $highData = $db->getHighData();
    $lowData = $db->getLowData();
    $openData = $db->getOpenData();
    $closeData = $db->getCloseData();
    $volData = $db->getVolData();*/

//newly added
$sql = "SELECT TIME_FORMAT( CURTIME( ) , '%H' ) AS HOUR , TIME_FORMAT( CURTIME(
) ,  '%i' ) AS
MINUTE,UNIX_Timestamp(date_added) As cash_date,Open_Price, High_Price, Low_Price,
Close_Price, NET_TRDQTY  FROM chart WHERE SYMBOL='$ticker' ORDER BY date_added
DESC";
$result = mysql_query($sql) or die(mysql_error());

     while ($row = mysql_fetch_array($result)) {
// $dbtime = explode('-',$row['Date_acc']);
// $y = $dbtime[0];
// $m =$dbtime[1];
// $d=$dbtime[2];

  $theDate[] = str_replace("-","",$row['cash_date']);
      $timeStamps[] = chartTime2(str_replace("-","",$row['cash_date']));

      //  $timeStamps[] = chartTime($y, $m, $d,  09, 30, 0);
  $openData[] = $row['Open_Price'];
          $highData[] = $row['High_Price'];
          $lowData[] = $row['Low_Price'];
          $closeData[] = $row['Close_Price'];
          $volData[] = $row['NET_TRDQTY'];
     }


}

  Re: Finance Chart not working
Posted by Peter Kwan on Apr-28-2015 03:42
Hi techsoft,

In your code, I think the "DESC" in the SQL is not necessary.  Also, I think:

$timeStamps[] = chartTime2(str_replace("-","",$row['cash_date']));

should be simply:

$timeStamps[] = chartTime2($row['cash_date']);

If it is not showing the chart image, would you mind to clarify what it is showing? Is the browser just showing a complete blank page without nothing, or a broken image symbol, or a valid image but with no chart?

If what you see is a broken image, please go into the broken image to see what is the error message inside the broken image. See:

http://www.chartdir.com/forum/download_thread.php?site=chartdir&bn=chartdir_faq&thread=1117817200

If what you see then is a completely blank page, please ensure your PHP is configued to return error messages to the browser. To do this, please modify your "php.ini" and set error_reporting to E_ERROR, and display_error to 1, then restart your PHP (or Apache if you are using SAPI PHP). Instead of modifying "php.ini", sometimes including the following code in the first line of the financedemochart script may also work:

ini_set('display_errors',1);
error_reporting(E_ALL);

Note that the sample code will only plot a chart if there are sufficient data within the specified time range. If your database call returns no data, or the data are not in between $startDate and $endDate, or if the number of days is less than the $extraPoints parameter, then there is insufficient data and no financial chart can be drawn. Instead, the chart will contain the text "No data available for the specified time period".

Please kindly let me know what is the result.

Regards
Peter Kwan

  Re: Finance Chart not working
Posted by techsoft on Apr-28-2015 13:11
Attachments:
hi Peter Kwan,

Thanks for your reply. I had made some changes in the code as like you mentioned. Its
working and the chart is drawn. But it is not in a correct format and i don't know why it is
so?. Is there anything else to change in the financedemochart.php to get my data.?
I have data for one month that is from 2015-04-01 to 2015-04-28. How to pass
startdate and enddate for selecting?
Given below is my function code.

function generateRandomData($ticker, $startDate, $endDate, $resolution) {

    global $timeStamps, $volData, $highData, $lowData, $openData, $closeData;

    /*$db = new FinanceSimulator($ticker, $startDate, $endDate, $resolution);
    $timeStamps = $db->getTimeStamps();
    $highData = $db->getHighData();
    $lowData = $db->getLowData();
    $openData = $db->getOpenData();
    $closeData = $db->getCloseData();
    $volData = $db->getVolData();*/

//newly added
$sql = "SELECT TIME_FORMAT( CURTIME( ) , '%H' ) AS HOUR , TIME_FORMAT( CURTIME(
) ,  '%i' ) AS
MINUTE,UNIX_Timestamp(date_added) As cash_date,Open_Price, High_Price, Low_Price,
Close_Price, NET_TRDQTY  FROM cash_data WHERE SYMBOL='$ticker' ";
$result = mysql_query($sql) or die(mysql_error());

     while ($row = mysql_fetch_array($result)) {
// $dbtime = explode('-',$row['Date_acc']);
// $y = $dbtime[0];
// $m =$dbtime[1];
// $d=$dbtime[2];

  $theDate[] = str_replace("-","",$row['cash_date']);
      $timeStamps[] = chartTime2($row['cash_date']);

      //  $timeStamps[] = chartTime($y, $m, $d,  09, 30, 0);
  $openData[] = $row['Open_Price'];
          $highData[] = $row['High_Price'];
          $lowData[] = $row['Low_Price'];
          $closeData[] = $row['Close_Price'];
          $volData[] = $row['NET_TRDQTY'];
     }


}


Please see the image i have uploaded.
financedemochart.png

  Re: Finance Chart not working
Posted by Peter Kwan on Apr-28-2015 18:53
HI techsoft,

I think in your SQL, you need to "ORDER BY date_added" (not "ORDER BY date_added DESC"
or leaving the "ORDER BY date_added" out). The data needs to be arrange in chronological
order, not in random order or in reverse chronological order.

Regards
Peter Kwan

  Re: Finance Chart not working
Posted by techsoft on Apr-28-2015 20:41
hi Peter Kwan,

I will try it. Also please tell me how to pass or add value for  $startDate and $endDate in
the function generateRandomData($ticker, $startDate, $endDate, $resolution).
Please post any examples.

Thanks.

  Re: Finance Chart not working
Posted by Peter Kwan on Apr-29-2015 01:27
Hi techsoft,

In the sample code, $startDate and $endDate are in "chartTime" format. The sample code
also includes some examples on how to obtain the year, month, and day from that format.
You can then construct the date format as supported by your database.

For example, if your database can use ISO 8601 date format, then you can use:

$yyyymmdd = getChartYMD($startDate);
$isoStartDate = substr($yyyymmdd, 0, 4) . "-" . substr($yyyymmdd, 4, 2) . "-" .
substr($yyyymmdd, 6, 2);

.... same for $endDate to create $isoEndDate ....


$sql = "SELECT ........ FROM myTable WHERE dateCol >= '$isoStartDate' and dateCol <
'$isoEndDate' ..........";

Hope this can help.

Regards
Peter Kwan

  Re: Finance Chart not working
Posted by techsoft on May-04-2015 17:28
hi Peter,

Thanks for your ideas. Now its drawing chart, but i have another doubt that is to create
interactive finance chart which function should be actually modified getData() or
generateRandomData(). ?

Also my doubt regarding  $startdate and $enddate is not cleared. Because when we
select time period only number of days is passing. From this how could i get $startdate.

  Re: Finance Chart not working
Posted by Peter Kwan on May-05-2015 04:32
Hi techsoft,

The sample code is just an example. You can modify them in anyway you like. So you can
modify getData or generateRandomData depending on which one best fit you needs. It does
not matter so long as you can get the data.

In the sample code, the $startDate for a daily chart is computed by assuming that the
trading days are from Mon to Fri. If your market has a different rule (eg. in some countries
the trading holidays are different, and some financial systems may trade 7 days a week),
you would need to compute it based on the rules of your market.

If you are using a database for data and it supports the LIMIT clause in SQL, you would not
need the $startDate or $endDate at all, as you can simply ask the database to return data
for the number of records you need.

Regards
Peter Kwan

  Re: Finance Chart not working
Posted by techsoft on May-05-2015 20:20
hi Peter,

Thanks a lot for your help. Its working fine now and we have a plan to purchase the
license of software for php. Before  that i would like to know something more about the
chartdirector.

* Which one is more suitable for a website in linux platform?

1. If we purchase the license, what are the new features available with the software.?
2.What we have to do if we need a combo chart ? is there any need purchasing
another license?
3.How to set range(ex:weekly,monthly..etc) with time period to draw the chart?
4.Is there any editing options in the chart like text,arrow,marker etc..
5.Currently there is only two moving averages in the demo. How many will be there
after purchasing license.?

I would be very grateful for any advise you could give me on my doubts.

thanks
Techsoft

  Re: Finance Chart not working
Posted by Peter Kwan on May-06-2015 08:32
Hi techsoft,

For licensing questions, I will forward them to sales@advsofteng.net. Please expect an
email response shortly.

3) How to set range(ex:weekly,monthly..etc) with time period to draw the chart?

For "setting the range (ex:weekly,monthly,..)", are you referring that in the sample code
there are getWeeklyData and getMonthlyData? In the sample code, it starts to call
getWeeklyData when the time range is over 1.5 years, and getMonthlyData if it is over
4.5 years. You can certainly modify the criteria of when the use weekly or monthly data.

If your code have determined to use weekly data, your code should query your database
for weekly data. The exact method depends on how your database is structured. In one
common case, the database would have a table for daily data and one for weekly data,
and your code can query the weekly data table for weekly data. If you do not want to
set up a weekly data table, you can compute the weekly data from the daily data. The
code is provided as an example in the sample code. (See convertDailyToWeeklyData in
the sample code.) The same applies to monthly data.

4) Is there any editing options in the chart like text,arrow,marker etc..

Are you referring to interactive editing (similar to photoshop that you can draw things
interactively onto the chart), or are you referring to adding extra things to the chart
programmatically (such as computing "buy" and "sell" or other symbols and include them in
the chart)? For the latter, ChartDirector allows you to include custom data series into the
chart, and the data can be represented as symbols (such as arrows) and can have text
labels. Many of our customers have "top secret" formulas to compute buy or sell or other
special signals. After the data are computed, they just pass them to ChartDirector to
include them in the chart.

If you are referring to interactive editing, you would need to develop a graphics editor
with your own code, which can put text or symbols to an image. You can then use it to
add text or symbols to the chart image, which is just an ordinary image.

5) Currently there is only two moving averages in the demo. How many will be there
after purchasing license.?

ChartDirector does not have hard coded a limit to the number of moving averages. You
can modify the code to add any reasonable number of moving averages (even 1000
moving averages is fine).

Hope this can help.

Regards
Peter Kwan

  Re: Finance Chart not working
Posted by techsoft on May-06-2015 15:05
Attachments:
Hi Peter,

Thanks for your help, all going good now. :)

Regarding interactive chart editing options. Please view the image below. I would like
to create editing options like that.

thanks
Techsoft
New Picture 2.jpg

  Re: Finance Chart not working
Posted by Peter Kwan on May-07-2015 00:25
Hi techsoft,

I would not be surprise if the chart you attached is created by ChartDirector. (Many of the
details, like how the axes are labelled, the top margin on the y-axis, the way the text boxes
have rounded corners, ... seems to be consistent with ChartDirector.) The developer of that
web site probably did what I have suggested - that is - develop a simple graphics editor
with his own code, and use it to put things on the chart image created by ChartDirector.

If you would like to do similar things, you may need to develop the graphics editor code like
the developer of that web site.

Regards
Peter Kwan

  Re: Finance Chart not working
Posted by techsoft on May-07-2015 13:23
Hi Peter,

Thanks for your reply.

If you have any example or reference link regarding graphics editor creation, please
share it.

Thanks
Techsoft

  Re: Finance Chart not working
Posted by techsoft on May-07-2015 18:20
hi, Peter

I forgot to ask you one thing, that is how can we integrate trackfinance.php with financedemochart.php.

If you have any example code please share it.

Thanks
Techsoft

  Re: Finance Chart not working
Posted by Peter Kwan on May-08-2015 00:47
Hi techsoft,

I do not really have any example for how to create an interactive graphics editor.

For combining the Interactive Financial Chart with trackfinance.php, you would need to first make financedemochart.php into a HTML web page. Currently, financedemochart.php is an image, but trackfinance.php is a web page (the image is loaded by "getchart.php" in that web page). There is an example to make "financedemochart.php" at:

http://www.chartdir.com/forum/download_thread.php?bn=chartdir_support&thread=1411652864#N1411719094

The original intention of the above is to add image map for tooltips to the Interactive Financial Chart, but once it becomes HTML, you can add other things such as track cursors.

Hope this can help.

Regards
Peter Kwan