Javascript parseFloat和空值 [英] Javascript parseFloat and nulls

查看:1120
本文介绍了Javascript parseFloat和空值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对JavaScript非常陌生,因为我目前正在jQuery Mobile中制作一个跨平台的网络应用程序,我已经使用XML解析的例子到HighCharts图表,但是当我在我的系列数据中遇到空值时,它无法绘制任何几乎可以把它变成散点图。

  //推入数据点
$(系列)。 find('data point')。each(function(i,point){
seriesOptions.data.push(
parseFloat($(point).text())
);
});

我不知道如何编写if语句来检查它是否找到null,if所以如何告诉它使用它...任何人都可以请帮助或指引我在正确的方向,因为我会喜欢我的图表是正确的,而不是放置一个零值,如果我有一个null。

$ b $



$ p $ //推入数据点
$(series).find('data point')。each(function( (!),
var floatVal = parseFloat($(point).text());
if(!isNaN(floatVal)){
seriesOptions.data.push(floatVal);
}
else {
seriesOptions.data.push(null);
}
console.log(floatVal)
});


I am very new to javascript as I am currently making a cross platform web app in jQuery Mobile, I have used the example of XML Parsing to a HighCharts graph yet when I encounter a null in my series data it fails to draw any of the line and makes it into a scatter plot almost.

// push data points
$(series).find('data point').each(function(i, point) {
    seriesOptions.data.push( 
        parseFloat($(point).text())
    );
});

I have no idea how to write a if statement that checks to see if it found a null and if so how to tell it to use it... Can anyone please help or point me in the right direction as I would love my charts to be correct rather than placing a zero value where I have a null.

解决方案

With a quick google on Javascript If statments I beleive I have got there - thanks Bjorn :0) Your answer led me to get there !!!

// push data points
$(series).find('data point').each(function(i, point) {
    var floatVal = parseFloat($(point).text());
            if (!isNaN(floatVal)) {
                seriesOptions.data.push(floatVal);
        }
        else {
        seriesOptions.data.push(null);
        }
        console.log(floatVal)
    });

这篇关于Javascript parseFloat和空值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆