0

我有这个规范。

{
  "$schema": "https://vega.github.io/schema/vega-lite/v2.json",
  "description": "Some garbage test data",
  "data": {
    "values": [
      {"date": "01 Jan 2012 23:00:00", "price": 150},
      {"date": "02 Jan 2012 00:00:00", "price": 100},
      {"date": "03 Jan 2012 01:00:00", "price": 170},
      {"date": "04 Jan 2012 02:00:00", "price": 165},
      {"date": "05 Jan 2012 03:00:00", "price": 20},
      {"date": "06 Jan 2012 03:00:00", "price": 300},
      {"date": "07 Jan 2012 03:00:00", "price": 200},
      {"date": "08 Jan 2012 03:00:00", "price": 300},
      {"date": "09 Jan 2012 03:00:00", "price": 500}
    ]
  },
  "mark": "bar",
  "encoding": {
    "x": {
      "field": "date",
      "type": "ordinal",
      "timeUnit": "day"
    },
    "y": {"field": "price", "type": "quantitative", "aggregate": "average"}
  },
  "config": {"axisY": {"minExtent": 30}}
}

这会在漂亮的图表中显示每日平均值,但是在一周从星期一开始的国家/地区,以“星期日”开头是非常奇怪的。

如何更改订单以使其从星期一开始?

4

1 回答 1

0

使用该sort属性设置轴顺序:

{
  "$schema": "https://vega.github.io/schema/vega-lite/v2.json",
  "description": "Some garbage test data",
  "data": {
    "values": [
      {"date": "01 Jan 2012 23:00:00", "price": 150},
      {"date": "02 Jan 2012 00:00:00", "price": 100},
      {"date": "03 Jan 2012 01:00:00", "price": 170},
      {"date": "04 Jan 2012 02:00:00", "price": 165},
      {"date": "05 Jan 2012 03:00:00", "price": 20},
      {"date": "06 Jan 2012 03:00:00", "price": 300},
      {"date": "07 Jan 2012 03:00:00", "price": 200},
      {"date": "08 Jan 2012 03:00:00", "price": 300},
      {"date": "09 Jan 2012 03:00:00", "price": 500}
    ]
  },
  "mark": "bar",
  "encoding": {
    "x": {
      "field": "date",
      "type": "ordinal",
      "timeUnit": "day",
      "sort": ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]
    },
    "y": {"field": "price", "type": "quantitative", "aggregate": "average"}
  },
  "config": {"axisY": {"minExtent": 30}}
}

在此处输入图像描述

于 2018-07-31T14:44:36.773 回答