第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會有你想問的

無法在 D3 中渲染氣泡圖

無法在 D3 中渲染氣泡圖

吃雞游戲 2022-07-08 17:00:32
我是 D3 的新手,并試圖繪制下面的氣泡圖。<!DOCTYPE html><meta charset="utf-8"><!-- Load d3.js --><script src="https://d3js.org/d3.v4.js"></script><!-- Load color scale --><script src="https://d3js.org/d3-scale-chromatic.v1.min.js"></script><!-- Create a div where the graph will take place --><div id="my_dataviz"></div><script>// set the dimensions and margins of the graphvar margin = {top: 10, right: 20, bottom: 30, left: 50},    width = 500 - margin.left - margin.right,    height = 420 - margin.top - margin.bottom;// append the svg object to the body of the pagevar svg = d3.select("#my_dataviz")  .append("svg")    .attr("width", width + margin.left + margin.right)    .attr("height", height + margin.top + margin.bottom)  .append("g")    .attr("transform",          "translate(" + margin.left + "," + margin.top + ")");//Read the datad3.csv("dis.csv", function(data) {  // Add X axis  var x = d3.scaleLinear()    .domain([0, 30])    .range([ 0, width ]);  svg.append("g")    .attr("transform", "translate(0," + height + ")")    .call(d3.axisBottom(x));  // Add Y axis  var y = d3.scaleLinear()    .domain([0, 30])    .range([ height, 0]);  svg.append("g")    .call(d3.axisLeft(y));  // Add a scale for bubble size  var z = d3.scaleLinear()    .domain([0, 300])    .range([ 4, 40]);  // Add a scale for bubble color  var myColor = d3.scaleOrdinal()    .domain(["Asia", "Europe", "Americas", "Africa", "Oceania"])    .range(d3.schemeSet2);  // -1- Create a tooltip div that is hidden by default:  var tooltip = d3.select("#my_dataviz")    .append("div")      .style("opacity", 0)      .attr("class", "tooltip")      .style("background-color", "black")      .style("border-radius", "5px")      .style("padding", "10px")      .style("color", "white")我正在關(guān)注本教程https://www.d3-graph-gallery.com/graph/bubble_basic.html ,當(dāng)我渲染頁面時(shí),我看不到任何錯誤,也沒有繪制圖表。任何幫助,將不勝感激。
查看完整描述

1 回答

?
慕娘9325324

TA貢獻(xiàn)1783條經(jīng)驗(yàn) 獲得超4個(gè)贊

您的代碼有幾個(gè)問題:


通常,您在 html<head>標(biāo)記中調(diào)用 d3 庫和色標(biāo)。

<!DOCTYPE html>

<meta charset="utf-8" />

<head>

  <!-- Load d3.js -->

  <script src="https://d3js.org/d3.v4.js"></script>


  <!-- Load color scale -->

  <script src="https://d3js.org/d3-scale-chromatic.v1.min.js"></script>

</head>

你<div id="my_dataviz"></div>和它下面的代碼,即<script>包含所有可視化代碼的標(biāo)簽需要放在 HTML<body>標(biāo)簽中。

<body>

  <!-- Create a div where the graph will take place -->

  <div id="my_dataviz"></div>


  <script>

     //Your visualization script needs to go here

  </script>


</body>

導(dǎo)入的數(shù)據(jù)d3.csv都是字符串格式。因此,您需要使用 foreach 循環(huán)鍵入轉(zhuǎn)換您的數(shù)值數(shù)據(jù),例如:

      data.forEach(d => {

        d.average_distance = +d.average_distance.trim();

        d.average_price = +d.average_price.trim();

        d.average_rating = +d.average_rating.trim();

      });

您的色標(biāo)需要映射到neighbourhood數(shù)據(jù)集中的 。

      // Add a scale for bubble color

      var myColor = d3

        .scaleOrdinal()

        .domain(data.map(d => d.neighbourhood))

        .range(d3.schemeSet2);

我已經(jīng)為您進(jìn)行了這些更改,您可以在此處查看代碼框以獲取工作示例。


查看完整回答
反對 回復(fù) 2022-07-08
  • 1 回答
  • 0 關(guān)注
  • 94 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號