首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >JQuery Flot时间戳

JQuery Flot时间戳
EN

Stack Overflow用户
提问于 2016-06-22 04:26:37
回答 1查看 73关注 0票数 0

我正在尝试使用flot获取m/d/y格式的时间戳,以便在x轴上显示。我已经通读了API docs,但是时间戳仍然不能转换。我哪里错了?

代码语言:javascript
复制
<!-- Flot demo info -->
    <script>
          $(document).ready(function() {
            //random data
            var d1 = [
                [(new Date(2016, 6, 23)).getTime(), 55],
                [(new Date(2016, 6, 24)).getTime(), 45],
                [(new Date(2016, 6, 25)).getTime(), 55],
                [(new Date(2016, 6, 26)).getTime(), 65],
                [(new Date(2016, 6, 27)).getTime(), 25],
                [(new Date(2016, 6, 28)).getTime(), 85],
                [(new Date(2016, 6, 29)).getTime(), 15],
            ];

            //flot options
            var options = {
              series: {
                curvedLines: {
                  apply: true,
                  active: true,
                  monotonicFit: true
                }
              },
              colors: ["#26B99A"],
              grid: {
                borderWidth: {
                  top: 0,
                  right: 0,
                  bottom: 1,
                  left: 1
                },
                borderColor: {
                  bottom: "#7F8790",
                  left: "#7F8790"
                }
              }
            };
            var plot = $.plot($("#security_activity"), [{
              label: "Security",
              data: d1,
              yaxis: {},
              xaxis: {
                mode: "time",
                timeformat: "%m/%d/%y"
              },
              lines: {
                fillColor: "rgba(150, 202, 89, 0.12)"
              }, //#96CA59 rgba(150, 202, 89, 0.42)
              points: {
                fillColor: "#fff"
              }
            }], options);
          });
        </script>
EN

回答 1

Stack Overflow用户

发布于 2016-06-22 04:36:36

呃,愚蠢的我..。将x轴/y轴选项放在错误的位置。

更新的代码:

代码语言:javascript
复制
<!-- Flot demo info -->
    <script>
          $(document).ready(function() {
            //random data
            var d1 = [
                [(new Date(2016, 6, 23)).getTime(), 55],
                [(new Date(2016, 6, 24)).getTime(), 45],
                [(new Date(2016, 6, 25)).getTime(), 55],
                [(new Date(2016, 6, 26)).getTime(), 65],
                [(new Date(2016, 6, 27)).getTime(), 25],
                [(new Date(2016, 6, 28)).getTime(), 85],
                [(new Date(2016, 6, 29)).getTime(), 15]
            ];

            //flot options
            var options = {
              series: {
                curvedLines: {
                  apply: true,
                  active: true,
                  monotonicFit: true
                }
              },
              colors: ["#26B99A"],
              grid: {
                borderWidth: {
                  top: 0,
                  right: 0,
                  bottom: 1,
                  left: 1
                },
                borderColor: {
                  bottom: "#7F8790",
                  left: "#7F8790"
                }
              },
              yaxis: {},
              xaxis: {
                mode: "time",
                timeformat: "%m/%d/%y",
                minTickSize: [1, "day"]
              }
            };
            var plot = $.plot($("#security_activity"), [{
              label: "Security",
              data: d1,
              lines: {
                fillColor: "rgba(150, 202, 89, 0.12)"
              }, //#96CA59 rgba(150, 202, 89, 0.42)
              points: {
                fillColor: "#fff"
              }
            }], options);
          });
        </script>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37953960

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档