1
我目前正試圖運行一個名爲metricsgraphics.js的簡單庫。這是我對使用超級興奮的D3圖書館,但我有一些問題讓它運行。它看起來像一個非常簡單的庫使用,但我不斷收到錯誤。我有以下內容:使用D3庫時的XMLHttpRequest問題
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Testing</title>
<link href="lib/metricsgraphics.css" rel="stylesheet">
</head>
<body>
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.6/d3.js"></script>
<script src="lib/metricsgraphics.js"></script>
<script type="text/javascript">
d3.json('data/ufo-sightings', function(data) {
})
d3.json('data/ufo-sightings', function(data) {
data = MG.convert.date(data, 'year');
})
d3.json('data/ufo-sightings', function(data) {
MG.data_graphic({
title: "UFO Sightings",
description: "Yearly UFO sightings from the year 1945 to 2010.",
data: data,
width: 650,
height: 150,
target: '#ufo-sightings',
x_accessor: 'year',
y_accessor: 'sightings',
markers: [{'year': 1964, 'label': '"The Creeping Terror" released'}]
})
})
</script>
</body>
我在他們的網站上關注他們的指示。我收到以下兩條錯誤消息:
XMLHttpRequest cannot load file:///directory/where/my/data/is. Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https, chrome-extension-resource.
Uncaught NetworkError: Failed to execute 'send' on 'XMLHttpRequest': Failed to load file:///directory/where/my/data/is.
任何人都可以幫我解釋並提供可能的解決方案嗎?