为什么从Vega编辑器中删除规范的简单副本在本地不起作用?

时间:2017-05-17 21:11:06

标签: javascript jquery version vega vega-lite

我在Vega编辑器中有这个规范有效:

{
  "$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”,之后我看到它无法正常工作我试过这个脚本源码src =“https://cdnjs.cloudflare.com/ajax/libs/vega/2.6.5/vega.min.js”谁是Vega编辑器的相同版本...但它也不起作用!< / p>

请有人可以帮助我吗?

1 个答案:

答案 0 :(得分:0)

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