0

我在 Vega Editor 中有这个规范,它可以工作:

{
  "$schema": "https://vega.github.io/schema/vega/v3.0.json",
  "width": 1,
  "height": 1,
  "padding": "auto",
  "data": [
    {
      "name": "source",
      "values": [
        {"name": "Moyenne","vote": "white","nbr": 20},
        {"name": "Moyenne","vote": "yes","nbr": 40},
        {"name": "Moyenne","vote": "no","nbr": 40}
      ]
    },
    {
      "name": "summary",
      "source": "source",
      "transform": [
        {
          "type": "aggregate",
          "groupby": ["name","vote"],
          "summarize": {"nbr": ["sum"]}
        }
      ]
    },
    {
      "name": "stacked_scale",
      "source": "summary",
      "transform": [
        {
          "type": "aggregate",
          "summarize": [{"ops": ["sum"],"field": "sum_nbr"}],
          "groupby": ["name"]
        }
      ]
    },
    {
      "name": "layout",
      "source": "summary",
      "transform": [
        {
          "type": "aggregate",
          "summarize": [{"field": "name","ops": ["distinct"]}]
        }
      ]
    }
  ],
  "marks": [
    {
      "name": "root",
      "type": "group",
      "from": {"data": "layout"},
      "properties": {
        "update": {
          "width": {"field": "width"},
          "height": {"field": "height"}
        }
      },
      "marks": [
        {
          "name": "marks",
          "type": "rect",
          "from": {
            "data": "summary",
            "transform": [
              {
                "type": "stack",
                "groupby": ["name"],
                "field": "sum_nbr",
                "sortby": ["-vote"],
                "output": {
                  "start": "sum_nbr_start",
                  "end": "sum_nbr_end"
                },
                "offset": "normalize"
              }
            ]
          },
          "properties": {
            "update": {
              "x": {"scale": "x","field": "sum_nbr_start"},
              "x2": {"scale": "x","field": "sum_nbr_end"},
              "yc": {"scale": "y","field": "name"},
              "height": {"value": 50},
              "fill": {"scale": "color","field": "vote"},
              "stroke": {"scale": "colorStroke","field": "vote"},
              "strokeWidth": {"value": 2}
            }
          }
        }
      ],
      "scales": [
        {
          "name": "x",
          "type": "linear",
          "domain": [0,1],
          "rangeMin": 0,
          "rangeMax": 500,
          "round": true,
          "nice": true,
          "zero": true
        },
        {
          "name": "y",
          "type": "ordinal",
          "domain": {"data": "summary","field": "name","sort": true},
          "padding": 1
        },
        {
          "name": "color",
          "type": "ordinal",
          "domain": {"data": "summary","field": "vote","sort": true},
          "range": ["#FF0000","#FFFFFF","#008000"]
        },
        {
          "name": "colorStroke",
          "type": "ordinal",
          "domain": {"data": "source","field": "vote"},
          "range": ["#000000"]
        }
      ],
      "axes": [{"type": "y","scale": "y"}],
      "legends": [
        {
          "fill": "color",
          "title": "vote",
          "orient": "left",
          "properties": {
            "symbols": {
              "shape": {"value": "circle"},
              "strokeWidth": {"value": 1}
            }
          }
        }
      ]
    }
  ]
}

但是,当我将过去复制到本地开发中时,它不起作用。

首先,我将版本 3.0.0-beta.31 放入 src="https://vega.github.io/vega/vega.js",在我看到它不起作用后,我尝试了这个脚本 source src=" https://cdnjs.cloudflare.com/ajax/libs/vega/2.6.5/vega.min.js”谁是相同版本的Vega编辑器...但是它也不起作用!

请问有人可以帮助我吗?

4

1 回答 1

0

根据 Github 上的这个问题,似乎“file:///通过抛出与跨源请求相关的 XMLHttpRequest 错误,从文件系统直接提供的文件(例如,使用)[失败](因为它应该)启动。”

于 2017-06-01T21:37:36.587 回答