高图绘制每周数据(JS)

时间:2018-10-05 10:18:34

标签: highcharts

我正在尝试绘制以下对象,但它为我提供了具有以下x轴的图表:周四,周四,周五,周六,周六,周日,周日,周一,周二

var myData = [
    {date: "2018-08-02 00:00:00", value : "626.12"},
    {date: "2018-08-02 00:50:00", value : "626.95"},
    {date: "2018-08-03 00:40:00", value : "646.23"},
    {date: "2018-08-04 00:60:00", value : "656.5O"},
    {date: "2018-08-04 00:50:00", value : "656.65"},
    {date: "2018-08-05 00:30:00", value : "666.32"},
    {date: "2018-08-05 00:30:00", value : "666.63"},
    {date: "2018-08-06 00:30:00", value : "686.92"},
    {date: "2018-08-07 00:30:00", value : "696.21"},
    {date: "2018-08-07 00:40:00", value : "696.54"}
];

我试图用ES6数组方法filter()过滤对象,但是我没有做出类似的事情:

var weekly = [
    {date: "2018-08-02 00:00:00", value : "626.12"},
    {date: "2018-08-03 00:40:00", value : "646.23"},
    {date: "2018-08-04 00:60:00", value : "656.50"},
    {date: "2018-08-05 00:30:00", value : "666.32"},
    {date: "2018-08-06 00:30:00", value : "686.92"},
    {date: "2018-08-07 00:30:00", value : "696.21"}
];

有人有想法吗?

感谢前进。

1 个答案:

答案 0 :(得分:0)

var myData = [
    {date: "2018-08-02 00:00:00", value : "626.12"},
    {date: "2018-08-02 00:50:00", value : "626.95"},
    {date: "2018-08-03 00:40:00", value : "646.23"},
    {date: "2018-08-04 00:60:00", value : "656.5O"},
    {date: "2018-08-04 00:50:00", value : "656.65"},
    {date: "2018-08-05 00:30:00", value : "666.32"},
    {date: "2018-08-05 00:30:00", value : "666.63"},
    {date: "2018-08-06 00:30:00", value : "686.92"},
    {date: "2018-08-07 00:30:00", value : "696.21"},
    {date: "2018-08-07 00:40:00", value : "696.54"}
];

myData = myData.reverse().filter((obj, index) => {
  if(index !== myData.length-1) {
    return obj.date.split(' ')[0] !== myData[index+1].date.split(' ')[0]
  }
  return true;
}).reverse();

console.log(myData)