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

Message ListMessage List     Post MessagePost Message

  different raising and falling colors to addBarIndicator
Posted by kuli on Dec-12-2012 21:14
Hi

I am trying to add a histogram to my financial chart (python) using

c = FinanceChart(640)
c.addBarIndicator(....)

which i was able todo. Now i want to set different colors to falling and raising bars.
Please suggest me how to do that.very thanks.

  Re: different raising and falling colors to addBarIndicator
Posted by Peter Kwan on Dec-13-2012 02:36
Hi kuli,

The FinanceChart volume bars have different colors for up, down and flat days.  May be you can use the FinanceChart.py source code (see the addVolIndicator method) as a reference on how this is achieved.

Basically, you would need to separate your data into two or more data series, with each data series representing bars of one color. The separation method depends on what you mean by "falling" and "raising" bars. After separating the data, you may the data to the chart as different data sets, using different colors.

In brief, the code would be like:

#separate the bar data into two data series for falling and raising bars
fallingBars = [NoValue] * len(myData)
raisingBars = [NoValue] * len(myData)
for i in range(0, len(myData)) :
    if is_Falling_Bar(i) :
       fallingBars[i] = myData[i]
    else :
       raisingBar[i] = myData[i]

#add the two data series using different colors
barLayer = c.addIndicator(height).addBarLayer2(Overlay)
barLayer.setBorderColor(Transparent)
barLayer.addDataSet(fallingBars, fallingBarColor)
barLayer.addDataSet(raisingBars, raisingBarColor)

#display the legend icon color based on the last bar
barLayer.getDataSet(fallingBars[-1] != NoValue).setDataName("My Indicator")


Hope this can help.

Regards
Peter Kwan