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

Message ListMessage List     Post MessagePost Message

  Add shading to a certain part of the chart in finance chart?
Posted by London on Oct-22-2024 08:05
Is it possible to shade a certain part of the chart such as between 4am and 10am? as say gray and then the rest of the chart is just default?

php btw.

  Re: Add shading to a certain part of the chart in finance chart?
Posted by Peter Kwan on Oct-22-2024 17:13
Hi London,

You can use the Axis.addZone API. The following describe what is this API and an example of what it can do:

https://www.advsofteng.com/doc/cdnet.htm#Axis.addZone.htm
https://www.advsofteng.com/doc/cdnet.htm#markzone2.htm

The following is an example posted in this forum:

https://www.chartdir.com/forum/download_thread.php?bn=chartdir_support&thread=1668975980#N1669045247

(a) In brief, a FinanceChart includes a main price chart and optional some indicator charts. We need to get the XYChart object that you want to add the shading. For example:

#Save the main price chart into a variable so we can use it later to add the zones
$myChart = $myFinanceChart->addMainChart(........);

(b) Then you can use $myChart.xAxis().addZone(startIndex, endIndex, color); to add the zone. The startIndex and endIndex is the array index of the data point you want the zone to start and end, minus the extra leading points that the FinanceChart will not plot. For example:

$myChart->xAxis->addZone($startIndex - $extraPoints, $endIndex - $extraPoints, 0xff9999);

Best Regards
Peter Kwan

  Re: Add shading to a certain part of the chart in finance chart?
Posted by London on Oct-23-2024 03:46
the data i have to make the candlesticks is all fine and index's from zero, the problem I'm having is the chart starts at the index of 30 (because i guess you can only have so many candles on the chart depending on the size)

so in this example the start time I want the zone to start say at the time which has a index of 96 the chart is then rendering the zone 96 candles after 30 (where the chart starts within the index of the data)

is there a way to get the value at where the chart will start before the chart will render so I can reset the index at that?

  Re: Add shading to a certain part of the chart in finance chart?
Posted by Peter Kwan on Oct-23-2024 11:08
Hi London,

The most common reason the chart starts at index 30 is because your code configures it to start at 30. In some of our sample code, the code configures the chart to start at 30. See the extraPoints parameter at the following sample code:

https://www.advsofteng.com/doc/cdphp.htm#finance2.htm

Although the candlesticks are defined from index 0, most technical indicators are not defined at index 0. For example, the 25 period moving average is only defined on or after index 24. (Your need at least 25 points to compute a 25 period moving average.) Other technical indicators (RSI, MACD, ...) also require some prior data points. Our sample code uses 30 as it covers most of the common indicators.

If the extraPoints parameter explains the problem, then your code should already know where the chart starts, as it is set by your code. If you do not need the technical indicators or do not require them to start from the beginning of the visible chart, you can set the extraPoints to 0.

Best Regards
Peter Kwan

  Re: Add shading to a certain part of the chart in finance chart?
Posted by London on Oct-25-2024 02:23
Yeah my bad i fixed it, finally figured it was the $extrapoints screwing with the code. Thanks Peter!