Why are you formatting the windspeed as string and then (multiple times) converting it to float?
This may be unrelated to your problem. I do notice that the outTemp coloring is done with the string value and converted to the real value in the coloration function itself. Could the windspeed float variable be going out of scope? I don't usually write Javascript so, sorry I'm not much help. On Sun, May 15, 2022 at 3:24 AM Meteo Oberwallis <[email protected]> wrote: > Hi Guys > I have a problem with the wind color in Belchertown. I managed to display > the wind in color as well. Only it doesn't always do so after visiting or > refreshing the Belchertown page. I've attached my changes. What could it > be? I have 2 pictures attached. At view a is at page load and also a few > seconds later. At some point the color will change (see appendix b). But > that is always different. > > This is my Code: > > // Change the color of the Windspeed variable according to US-EPA standards > // (adjusted to match skin colors better) > function get_windSpeed_color(windSpeed, returnColor = false) { > if (windSpeed <= 0) { > var windSpeed_color = "rgba(0,255,0,1)"; > } else if (windSpeed >= 19.9) { > var windSpeed_color = "rgba(126,255,0,1)"; > } else if (windSpeed >= 39.9) { > var windSpeed_color = "rgba(0,255,0,1)"; > } else if (windSpeed >= 59.9) { > var windSpeed_color = "rgba(255,128,0,1)"; > } else if (windSpeed >= 79.9) { > var windSpeed_color = "rgba(255,0,0,1)"; > } else if (windSpeed >= 99.9) { > var windSpeed_color = "rgba(255,0,120,1)"; > } else if (windSpeed >= 118.0) { > var windSpeed_color = "rgba(255,1,113,1)"; > } > > // Return the color value if requested, otherwise just set the div > color > if (returnColor) { > return windSpeed_color; > } else { > jQuery(".curwindspeed").css("color", windSpeed_color); > } > } > > and > // Windspeed Metric > if (data.hasOwnProperty("windSpeed_kph")) { > windSpeed = > parseFloat(parseFloat(data["windSpeed_kph"])).toLocaleString("$system_locale_js", > {minimumFractionDigits: unit_rounding_array["windSpeed"], > maximumFractionDigits: unit_rounding_array["windSpeed"]}); > get_windSpeed_color(windSpeed); > jQuery(".curwindspeed").html(windSpeed); > > I have the complete text as Attachment new_belchertown_js > > Thx for you help > > -- > You received this message because you are subscribed to the Google Groups > "weewx-user" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/weewx-user/1a07d243-7268-48d9-8bdf-a9649df4ac95n%40googlegroups.com > <https://groups.google.com/d/msgid/weewx-user/1a07d243-7268-48d9-8bdf-a9649df4ac95n%40googlegroups.com?utm_medium=email&utm_source=footer> > . > -- Peter Quinn (415)794-2264 -- You received this message because you are subscribed to the Google Groups "weewx-user" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/weewx-user/CAA1SM21ZYWHPNRofxV-d%3DBPN3FmeSJysyrGj%3DOaer%3DWoAcez7A%40mail.gmail.com.
