1

我正在尝试为 highcharts 构建一系列数据来绘制我的图表。

我的数组需要读取为 YaxisValuesArray = [null, 78.12,null, null, null] - ; 相反,我的数组是 [,78.12,,,] 因为我的图表没有出现。

下面是我的代码

 var n = parseInt(releaseprod);
                if (!isNaN(n)) {

                    var number = parseFloat(releaseprod);
                    if (number > 0)
                        YaxisValuesArray.push(parseFloat(releaseprod).toFixed(2));
                    else
                        YaxisValuesArray.push(parseInt(releaseprod));
                }
                else {
                    releaseprod = null;
                    YaxisValuesArray.push(releaseprod);

                }
                 YaxisValuesArray.join(" , ");

虽然我明确地将空值推送到数组。我的警报仍然显示为 [,78.12,,,]。

Highchart 代码:仅适用于系列

  series: [{
            showInLegend: true,
            name: 'Values',
            data: YaxisValuesArray //[,78.1,,,] --- NOt able to plot the graph
            //data: [null, 78.1, null, null, null]  -- Able to plot the graph


        }]

有人请告诉我如何将空值添加到数组中,以便我的图表出现。

4

2 回答 2

0

The .join() function returns a string from the array.

The HighChart data parameter is supposed to take in an array of values, with null evaluating to no data at that point.

To fix your issue, simply get rid of the join function call and pass in the YaxisValuesArray array.

于 2013-10-25T18:21:00.860 回答
0

为您提供的一些修复:

  • .toFixed(x)返回字符串,所以不要使用它,或者之后.parseFloat()再次使用

  • 不要使用join(),因为它返回字符串

  • 你的代码不完整。releaseprod解析前变量看起来如何?你如何遍历后端的所有点?像这样:[,78.12,,,]看起来真的错了。另外你是如何定义YaxisValuesArray变量的?

于 2013-10-28T11:11:25.017 回答