有浮点的dygraph x-y图,用于x轴值

时间:2018-07-27 15:58:42

标签: dygraphs

我正在尝试绘制一些多列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);}
                        }
                   }
           });

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

1 个答案:

答案 0 :(得分:0)

您已经发现了很多错误! dygraphs根据第一个数字(“ 2.214844”)确定x值是日期还是数字。在这种情况下,because of an imprecise check会出错。

此问题将在下一个音标版本中得到修复。但是与此同时,您可以选择:

  1. 从该值中添加或删除一位数字,即将其设为“ 2.2148440”,并在末尾添加零。 (严重!)

  2. 明确告诉字形图您的x轴是数字。

这将是这样的:

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

请参见full example