【问题标题】:Dygraphs: No Label on X Axis when data have only one recordDygraphs:当数据只有一条记录时,X 轴上没有标签
【发布时间】:2015-04-13 21:36:11
【问题描述】:

我最近开始使用 Dygraphs, 我发现如果数据只有一条记录, 图表下方的 x 轴上没有标签显示。

例如,使用来自tutorial of Dygraphs site 的代码:

<html>
<head>
<script type="text/javascript"
  src="dygraph-combined-dev.js"></script>
</head>
<body>
<div id="graphdiv"></div>
<script type="text/javascript">
  g = new Dygraph(

    // containing div
    document.getElementById("graphdiv"),

    // CSV or path to a CSV file.
    "Date,Temperature\n" +
    "2008-05-07,75\n" +
    "2008-05-08,70\n" +
    "2008-05-09,80\n"

  );
</script>
</body>
</html>

我将数据改为一条记录:

// CSV or path to a CSV file.
"Date,Temperature\n" +
"2008-05-07,75\n"

x 轴上不显示任何标签。

我尝试查看 Dygraphs 的选项参考, 但是当数据只有一条记录时,似乎没有选项可以绘制标签。

知道在只输入一条记录时如何绘制标签吗?

【问题讨论】:

    标签: javascript dygraphs


    【解决方案1】:

    只有一个值,dygraphs 对您的数据规模毫无意义。 x 轴是否应该跨越一年?一个月?一个世纪?

    解决方案是明确设置比例:

    g = new Dygraph(
      // containing div
      "graphdiv",
      // CSV or path to a CSV file.
      "Date,Temperature\n" +
      "2008-05-07,75\n",
      {
        dateWindow: [new Date(2008, 0, 0), new Date(2008, 11, 30)]
      }
    );
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-07-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-05-19
      • 2020-12-28
      相关资源
      最近更新 更多