AmChart将日期值倍增

时间:2017-06-21 08:19:14

标签: javascript amcharts

我正在尝试创建一个包含倍数日期值的图表,但它不起作用。我认为逻辑是好的,amChart不喜欢这种日期格式。有什么想法吗?

工作例子:

var chart = AmCharts.makeChart( "chartdiv", {
  type: "xy",
  dataProvider: [ {
    "ax": 16.10, <--------
    "ay": 2,
    "bx": 16.11, <--------
    "by": 2
  }, {
    "ax": 16.20, <--------
    "ay": 3,
    "bx": 16.21, <--------
    "by": 3
  }],
  graphs: [ {
    "xField": "ax",
    "yField": "ay"
  }, {
    "xField": "bx",
    "yField": "by"
  } ],
} );

我想要的是:

  var chart = AmCharts.makeChart( "chartdiv", {
  type: "xy",
  dataProvider: [ {
    "ax": "2017/04/27 09:16:10", <--------
    "ay": 2,
    "bx": "2017/04/27 09:16:11", <--------
    "by": 2
  }, {
    "ax": "2017/04/27 09:16:20", <--------
    "ay": 3,
    "bx": "2017/04/27 09:16:21", <--------
    "by": 3
  }],
  graphs: [ {
    "xField": "ax",
    "yField": "ay"
  }, {
    "xField": "bx",
    "yField": "by"
  } ],
} );

http://jsfiddle.net/Lktv4s4b/1/

1 个答案:

答案 0 :(得分:1)

对于基于日期的数据,您必须为图表对象指定dataDateFormat,以便AmCharts知道如何正确解析日期。由于您使用的是XY图表,因此您还必须告诉AmCharts您有一个基于日期的值轴(XY图表只有值轴,与串行图表不同),您必须指定哪一个是基于日期的。根据您的数据,您的X轴是基于日期的,因此您至少需要告诉它底值轴&#39; type"date"

AmCharts.makeChart("chartdiv", {
  type: "xy",
  dataDateFormat: "YYYY/MM/DD JJ:NN:SS",
  valueAxes: [{
    position: "bottom",
    type: "date"
  }], //you can also specify the second value axis' properties if needed, but it will create a numeric y-axis for you by default if you don't
  // ... rest of your properties omitted ...
});

更新了小提琴:http://jsfiddle.net/Lktv4s4b/2/