Page 1 of 1

[Q] Graphs - changing Wind Dir yAxis

Posted: Tue 29 Sep 2015 6:24 pm
by TgT
Hi

This is how my graphs for wind direction looks like...
Image
Mostly my wind direction is between W and NE, and I would like to have that part in the middle of the graph. Is it doable? Anyone with highchart skills here? ;)

Re: [Q] Graphs - changing Wind Dir yAxis

Posted: Tue 29 Sep 2015 6:40 pm
by steve
In the code which sets the series data, you could process the array of points and modify it appropriately (add 180 modulo 360 or whatever) and then call setData() with the new array of points. You would also have to modify the array which sets the labels.

This is the existing code:

Code: Select all

$.ajax({
        url: 'api/graphdata/wdirdata.json',
        dataType: 'json',
        success: function (resp) {
            chart.hideLoading();
            chart.series[0].setData(resp.bearing);
            chart.series[1].setData(resp.avgbearing);
        }
});
Something like this might work:

Code: Select all

$.ajax({
        url: 'api/graphdata/wdirdata.json',
        dataType: 'json',
        success: function (resp) {
            chart.hideLoading();
            for (index = 0, len = resp.bearing.length; index < len; ++index) {
               resp.bearing[index][1] = (resp.bearing[index][1] + 180)%360;
            }
            chart.series[0].setData(resp.bearing);
            for (index = 0, len = resp.avgbearing.length; index < len; ++index) {
               resp.avgbearing[index][1] = (resp.avgbearing[index][1] + 180)%360;
            }
            chart.series[1].setData(resp.avgbearing);
        }
});
Completely untested and the syntax may not even be correct!

There may be a more clever way using Highcharts itself to do the processing. It would be simpler if Cumulus had it as an option, as in Cumulus 1 - I'll look into it at some point.

Re: [Q] Graphs - changing Wind Dir yAxis

Posted: Wed 30 Sep 2015 12:21 pm
by laulau
steve wrote: You would also have to modify the array which sets the labels.
Like this

Code: Select all

var compassP = function (deg) {
	var a = ['S', 'SW', 'W', 'NW', 'N', 'NE', 'E', 'SE'];
	return a[Math.floor((deg + 22.5) / 45) % 8];
};
And it works :clap:
CaptureCharts.JPG

Re: [Q] Graphs - changing Wind Dir yAxis

Posted: Wed 30 Sep 2015 10:50 pm
by TgT
havent tried it yet, but as it seems it works, gj! :clap:
A really nice line, You got there laulau