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

Graph with candles #14

Closed
svieujot opened this issue Aug 20, 2012 · 11 comments
Closed

Graph with candles #14

svieujot opened this issue Aug 20, 2012 · 11 comments

Comments

@svieujot
Copy link

Hello,

I am trying to do a graph similar to the Finance one, but with candles for the price.
I added the Flotr2 candle adapter, and it is almost working.
I think the remaining problem is the calculation of the min and max.
subsampleMinMax uses y[j], to compute the min & max, but in the case of candles, y is an array : [open,high,low,close].
Is there an easy way to fix this ?

Thank you.

@svieujot
Copy link
Author

I found a way to get around this for the moment :
instead of passing values in the form [ [dates], [prices] ], my data is in the form [ [dates], [closing price], [ {o,h,l,c} ] ].
The I re-wrote the candle adapter to get the o,h,l,c from data[2].

I works for the moment, but the min/max are computed by envision only on the closing prices, so as long as the candles do not overflow the closing price too much, it is fine, but if the candles have "long tails", some part might not be displayed.
So it would be nice to have a way to overload the min & max calculation.

Thank you.

@cesutherland
Copy link
Member

Ah, you want to skipPreprocess. There's an example of it here:

http://humblesoftware.com/envision/demos/ajax

Most any of the esoteric graph types like that, the user does not want to
downsample.

-c

On Tue, Aug 21, 2012 at 11:55 AM, Sylvain Vieujot
notifications@github.comwrote:

I found a way to get around this for the moment :
instead of passing values in the form [ [dates], [prices] ], my data is in
the form [ [dates], [closing price], [ {o,h,l,c} ] ].
The I re-wrote the candle adapter to get the o,h,l,c from data[2].

I works for the moment, but the min/max are computed by envision only on
the closing prices, so as long as the candles do not overflow the closing
price too much, it is fine, but if the candles have "long tails", some part
might not be displayed.
So it would be nice to have a way to overload the min & max calculation.

Thank you.


Reply to this email directly or view it on GitHubhttps://github.com//issues/14#issuecomment-7905844.

@svieujot
Copy link
Author

Great. I will try this.
Thank you !

@cesutherland
Copy link
Member

All set with this?

@svieujot
Copy link
Author

I did not try it yet.
Still tuning my multichart stuff.

@svieujot
Copy link
Author

I did not manage to use the skipPreprocess to solve this.
I understand how the skipPreprocess can be used to load data, but I don't see how this helps adjusting the axes ranges.
Anyway I can live without this for the moment, so I am closing the issue and will re-open it later if ever I need it.

@cesutherland
Copy link
Member

I'll get together an example.

Maybe open a thread on the google group?

On Fri, Aug 24, 2012 at 8:48 AM, Sylvain Vieujot
notifications@github.comwrote:

I did not manage to use the skipPreprocess to solve this.
I understand how the skipPreprocess can be used to load data, but I don't
see how this helps adjusting the axes ranges.
Anyway I can live without this for the moment, so I am closing the issue
and will re-open it later if ever I need it.


Reply to this email directly or view it on GitHubhttps://github.com//issues/14#issuecomment-8000289.

@svieujot
Copy link
Author

For the moment I solved it by adding this to my candle adapter :

extendYRange: function (axis, data, options) {
    var maxHigh = null, minLow = null;

    for (i = 0; i < data.length; i++) {
        var candleIndex = data[i][0];
        var qb = options.quotes[candleIndex];

        if( maxHigh === null || maxHigh < qb.h )
            maxHigh = qb.h;
        if( minLow === null || minLow < qb.l )
            minLow = qb.l;
    }

    if( maxHigh != null && minLow != null ){
        axis.max = Math.max( maxHigh, axis.max );
        axis.min = Math.min( minLow, axis.min );
    }
}

It will do it for some time.
The really nice thing would be to integrate the candle adapter within envision.

@cesutherland
Copy link
Member

Ahh I understand! That's the correct solution, and an issue inside Flotr2.
Feel free to create a topic-branch and submit a pull request over there.
I'll incorporate it.

On Fri, Aug 24, 2012 at 1:45 PM, Sylvain Vieujot
notifications@github.comwrote:

For the moment I solved it by adding this to my candle adapter :

extendYRange: function (axis, data, options) {
var maxHigh = null, minLow = null;

for (i = 0; i < data.length; i++) {
    var candleIndex = data[i][0];
    var qb = options.quotes[candleIndex];

    if( maxHigh === null || maxHigh < qb.h )
        maxHigh = qb.h;
    if( minLow === null || minLow < qb.l )
        minLow = qb.l;
}

if( maxHigh != null && minLow != null ){
    axis.max = Math.max( maxHigh, axis.max );
    axis.min = Math.min( minLow, axis.min );
}

}

It will do it for some time.
The really nice thing would be to integrate the candle adapter within
envision.


Reply to this email directly or view it on GitHubhttps://github.com//issues/14#issuecomment-8009622.

@svieujot
Copy link
Author

Ok, I will do that.
One issue is that to work properly with envision, I customized my dataset :
data[0] = x
data[1] = y
data[2] = {o:..., h:..., l:..., c: ...., v:....., d:....} // JSON for the full candle info : open, high, low, close, volume, date

That way it works with minimal changes in Envision.
I will submit the pull request as it works for me now, but you might have different views on the input parameters.

@svieujot
Copy link
Author

Pull request done.

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

No branches or pull requests

2 participants