无法将x解析为Date对象

问题描述 投票:0回答:1

原始C3.js示例:

https://c3js.org/samples/chart_stanford.html

我在C3.js斯坦福图表中收到以下控制台日志错误:

c3.js:2349无法将x'2019-09-10 08:15:51'解析为Date对象

使用我所有的JSON值。

我知道这与xFormat有关,我已将其添加到Data:的keys:区域中,但是我仍然收到相同的错误。

var data = [
  {
    "Time": "2019-09-10 08:15:51",
    "Range Gate": 26,
    "Velocity": 44
  },
  {
    "Time": "2019-09-10 08:16:51",
    "Range Gate": 46,
    "Velocity": 47
  },
  {
    "Time": "2019-09-10 08:17:51",
    "Range Gate": 55,
    "Velocity": 50
  },
  {
    "Time": "2019-09-10 08:18:51",
    "Range Gate": 1,
    "Velocity": 54
  },
  {
    "Time": "2019-09-10 08:19:51",
    "Range Gate": 11,
    "Velocity": 54
  }
];

与此数据集相同:

var data = [
  {
    "Time": "08:15:51",
    "Range Gate": 26,
    "Velocity": 44
  },
  {
    "Time": "08:16:51",
    "Range Gate": 46,
    "Velocity": 47
  },
  {
    "Time": "08:17:51",
    "Range Gate": 55,
    "Velocity": 50
  },
  {
    "Time": "08:18:51",
    "Range Gate": 1,
    "Velocity": 54
  },
  {
    "Time": "08:19:51",
    "Range Gate": 11,
    "Velocity": 54
  }
];

  var chart = c3.generate({
    size: {
      height: 600,
      width: 800 * 1.12
    },
    data: {
      json: data,
      mimeType: 'json',
      epochs: 'Velocity',
      keys: {
        x: 'Time',
        xFormat: '%H:%M:%S',
        value: ['Range Gate', 'Velocity']
      },
      type: 'stanford'
    },
    legend: {
      hide: true
    },
    point: {
      focus: {
        expand: {
          r: 5
        }
      },
      r: 2.5
    },
    axis: {
      x: {
        type: 'timeseries',
        tick: {
          format: '%H:%M:%S'
        },
        show: true,
        label: {
          text: 'Time',
          position: 'outer-center'
        },
        min: 0,
        max: 61,
        padding: {
          top: 0,
          bottom: 0,
          left: 0,
          right: 0
        },
      },
      y: {
        show: true,
        label: {
          text: 'Range Gate',
          position: 'outer-middle'
        },
        min: 0,
        max: 60,
        tick: {
          values: d3.range(0, 65, 10)
        },
        padding: {
          top: 5,
          bottom: 0,
          left: 0,
          right: 0
        },
      }
    },
    stanford: {
      scaleMin: 1,
      scaleMax: 10000,
      scaleFormat: 'pow10',
      padding: {
        top: 15,
        right: 0,
        bottom: 0,
        left: 0
      }
    }
  });

c3.js:2349无法将x'2019-09-10 08:15:51'解析为Date对象

c3.js:2349无法将x'2019-09-10 08:16:51'解析为Date对象

javascript d3.js c3.js
1个回答
0
投票

我在使用简单数据(例如示例)时遇到与使用xFormat的'26-12-2018'相同的问题:'%Y-%m-%d'

[仅当我还要添加小时数并使用斜杠时才能工作,例如'26/12/2018 00:00:00',并使用对应的xFormat:'%Y /%m /%d%H: %M:%S'

© www.soinside.com 2019 - 2024. All rights reserved.