Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Candle chart - make the shadow same color as an increasing/decreasing candle color #122

Closed
dorsoft opened this issue Jun 1, 2015 · 4 comments
Labels

Comments

@dorsoft
Copy link

dorsoft commented Jun 1, 2015

I'm developing a financial app, it is customary to color the candle shadow the same color as the candle itself. e.g. green/red for increasing/decreasing.

I've managed to accomplish that by adding the following code:
A. CandleChartDataSet line 31
/// use candle color for the shadow
public var makeShadowSameColorAsCandle = false

B. CandleStickChartRenderer - drawDataSet (line 104) changed from:

CGContextSetStrokeColorWithColor(context, (dataSet.shadowColor ?? dataSet.colorAt(j)).CGColor);

to

       var shadowColor = dataSet.shadowColor ?? dataSet.colorAt(j);
        if (dataSet.makeShadowSameColorAsCandle)
        {
            if (e.open >= e.close)
            {
                shadowColor = dataSet.decreasingColor ?? dataSet.colorAt(j);
            }
            else
            {
                shadowColor = dataSet.increasingColor ?? dataSet.colorAt(j);
            }
        }

        CGContextSetStrokeColorWithColor(context, shadowColor.CGColor);    

Could you please add it to the master ?

@AlBirdie
Copy link
Contributor

AlBirdie commented Jun 2, 2015

I've had the same requirement and altered the CandleStickChartRenderer almost identically to your solution. However, what is missing is the case for e.open == e.close, so a neutral shadow color.

@dorsoft
Copy link
Author

dorsoft commented Jun 2, 2015

Nice catch @AlBirdie, I guess we could use something like:

var shadowColor = dataSet.shadowColor ?? dataSet.colorAt(j);
if (dataSet.makeShadowSameColorAsCandle)
{
if (e.open > e.close)
{
shadowColor = dataSet.decreasingColor ?? dataSet.colorAt(j);
}
else if (e.open < e.close)
{
shadowColor = dataSet.increasingColor ?? dataSet.colorAt(j);
}
}
CGContextSetStrokeColorWithColor(context, shadowColor.CGColor);

@AlBirdie
Copy link
Contributor

AlBirdie commented Jun 2, 2015

Yes, that's it. :)

@dorsoft
Copy link
Author

dorsoft commented Jun 14, 2015

On top of that it is customary to draw a horizontal line when the candle height is zero, I've added this feature as well

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants