Home Forums Chart Support Wind direction degrees to description

Wind direction degrees to description

Viewing 4 posts - 1 through 4 (of 4 total)
  • #31354

    Luc

    I have a chart of a wind sensor that displays values from 0 to 359 degrees. On my y-axis are the values 0, 100, 200, 300 and 400 degrees. I want the data to be displayed in degrees but replace the y-axsis with

    N for 0
    NE for 45
    E for 90
    SE for 135
    S for 180
    SW for 225
    W for 270
    NW for 315

    How can I accomplish this?

    #31365

    Luc

    Already found the solution in ‘labelFormatter’. For others who are looking for such a solution I briefly describe my solution.

    Because I made it possible to dynamically add different data (sensor from a weather station) to the chart by clicking a weather icon, I use the setter of the corresponding axis after adding data to chart. See code below.

            chart.axisY2[0].set('labelFormatter',function ( e ) {
              if ( e.value >= 11.25 && e.value < 33.75 ) return 'NNE';
              else if ( e.value >= 33.75 && e.value < 56.25 ) return 'NE';
              else if (e.value >= 56.25 && e.value < 78.75 ) return 'ENE';
              else if (e.value >= 78.75 && e.value < 101.25 ) return 'E';
              else if (e.value >= 101.25 && e.value < 123.75 ) return 'ESE';
              else if (e.value >= 123.75 && e.value < 146.25 ) return 'SE';
              else if (e.value >= 146.25 && e.value < 168.75 ) return 'SSE';
              else if (e.value >= 168.75 && e.value < 191.25 ) return 'S';
              else if (e.value >= 191.25 && e.value < 213.75 ) return 'SSW';
              else if (e.value >= 213.75 && e.value < 236.25 ) return 'SW';
              else if (e.value >= 236.25 && e.value < 258.75 ) return 'WSW';
              else if (e.value >= 258.75 && e.value < 281.25 ) return 'W';
              else if (e.value >= 281.25 && e.value < 303.75 ) return 'WNW';
              else if (e.value >= 303.75 && e.value < 326.25 ) return 'NW';
              else if (e.value >= 326.25 && e.value < 348.75 ) return 'NNW';
              else if (e.value >= 348.75 ) return 'N';
              else if (e.value < 11.25 ) return 'N';
              return  e.value;  
            });
    #31373

    @lve,

    Glad you’ve figured it out :)

    You can further simplify the solution by using interval and labelFormatter as shown in this JSFiddle.


    Shashi Ranjan
    Team CanvasJS

    #31379

    Luc

    Great! I used interval and maximum, but your code is simpler.

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.