GoogleスプレッドシートとD3jsのD3-request/D3-request > headerをxhrリクエストで一緒に処理するのは難しいです。Googleスプレッドシートcsv/jsonファイルのD3-request検索が失敗します
XMLHttpRequest cannot load https://docs.google.com/spreadsheets/d/e/2PACX-1vSZyV9olwK_hx0BRFgLtTz5hs_Z…mROYhax3VD9AFXTvmcataf8LuSIpxGT2/pub?gid=1023695213&single=true&output=csv. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'https://fiddle.jshell.net' is therefore not allowed access.
それを回避するために、任意のアイデア:私は次のエラーを取得する
d3.request(url)
.header("X-Requested-With", "XMLHttpRequest")
.mimeType("text/csv")
.get(function(error, data) {
if (error) throw error;
console.log('request: '+ data);
});
:
は、私は次のJSを使うのか? tabletopを使用してjQueryの
$.get(url, function (result) {
var data = [];
$(result.feed.entry).each(function() {
data.push({"animal": this.gsx$animal.$t, "population": this.gsx$population.$t});
});
pie_chart(data, "#chart2");
});
使用D3のみ
d3.json(url, function (error, result) {
var data = [];
for (i = 0; i < result.feed.entry.length; i += 1) {
data.push({
"animal": result.feed.entry[i].gsx$animal.$t,
"population": result.feed.entry[i].gsx$population.$t
});
}
pie_chart(data, "#chart1");
});
を使用
あなたのサンプルデータのための彼らの同意なしにユーザーからのメールを使用しないでください。 –
Oups。これをすばやく中和できます! – Hugolpz
@MaximilianPeters:大きな感謝。私はこのコードでとても忙しく、私は自分のシートに電子メールを載せていたことを忘れていました。 – Hugolpz