dygraph x-y 图,x 轴值带有浮点数

dygraph x-y plot with floating points for x-axis values

我正在尝试绘制一些多列 x-y 数据。如果 x 轴是一个整数,那么一切都很好。但是如果 x 轴是一个浮点数(这是我想要的),我得到:

"Couldn't parse 2.214844 as a date"
...

作为控制台中的错误。如何绘制 x 轴的浮点数?

数据示例:

2.214844,,,,,0.000000
2.224854,,,,0.000000,
2.234131,0.000000,,,,
2.264893,,,0.000000,,
2.273193,,0.000000,,,
104.372070,,,,0.000000,
104.376709,,,,,0.000000
104.398193,0.000000,,,,
104.498047,,,0.000000,,
104.577148,,0.000000,,,

到目前为止我的代码:

g = new Dygraph(
            document.getElementById("graphdiv"),
            "./a.csv", 
          {
             labels: ['time','1','2','3','4','5'],
             visibility: [true, false, false,false,false],
             axes: { x: {
                          //valueParser: function(x) {return parseFloat(x);},
                          valueParser: function(x) {return parseInt(x);}
                        }
                   }
           });

我尝试过使用和不使用轴选项。

您发现了相当大的错误! dygraphs 根据第一个(“2.214844”)决定你的 x 值是日期还是数字。在这种情况下,because of an imprecise check,它是错误的。

这将在下一个 dygraphs 版本中得到修复。但与此同时,您的选择是:

  1. 在该值中添加或删除一个数字,即使其成为“2.2148440”,末尾为零。 (说真的!)

  2. 明确告诉 dygraphs 你的 x 轴是数字。

这就是它的样子:

g = new Dygraph(
    document.getElementById("graph"),
    csv,
    {
       xValueParser: parseFloat,
       axes: {
         x: {
           valueFormatter: x => x,
           ticker: Dygraph.numericTicks,
           axisLabelFormatter: x => x,
         }
       }
    }
);

full example