D3.js
- Προηγούμενη σελίδα JS Γραφήματα του Google
- Επόμενη σελίδα Παραδείγματα JS
D3.js\u662f\u4e00\u4e2a\u7528\u4e8e\u64cd\u4f5c\u5c0f\u8c61\u6570\u636e\u7684\u5fae\u8bba\u8bed\u5e93。
D3.js\u5f88\u5bb9\u6613\u4f7f\u7528。
如何使用 D3.js?
\u82e5\u60a8\u5728\u7f51\u9875\u4e2d\u4f7f\u7528\u4e86\u4e00\u4e2a\u5f15\u7528\u5230\u5e93\u7684\u94fe\u63a5
<script src="//d3js.org/d3.v3.min.js"></script>
\u8be5\u811a\u672c\u9009\u62e9\u4fdd\u6301\u4f60\u7684\u4f53\u8c61\u5e76\u8ffd\u52a0\u4e00\u6bb5\u542b\u6709\u6587\u672c\"Hello World!\"\u7684\u6bb5\u6bb5
d3.select("body").append("p").text("Hello World!");
\u6279\u70b9\u56fe
\u5b9e\u4f8b
//\u8bbe\u7f6e\u5e73\u65b9 const xSize = 500; const ySize = 500; const margin = 40; const xMax = xSize - margin*2; const yMax = ySize - margin*2; //\u521b\u5efa\u968f\u673a\u70b9 const numPoints = 100; const data = []; for (let i = 0; i < numPoints; i++) { data.push([Math.random() * xMax, Math.random() * yMax]); } //\u5c06\u5f15\u7528\u7684\u6570\u636e\u5bf9\u8c61\u8ffd\u52a0\u5230\u9875\u9762 const svg = d3.select(\"#myPlot\") .append(\"svg\") .append(\"g\") .attr(\"transform\",\"translate(\" + margin + ",\" + margin + ")\") // Άξονας X const x = d3.scaleLinear() .domain([0, 500]) .range([0, xMax]); svg.append("g") .attr("transform", "translate(0," + yMax + ")") .call(d3.axisBottom(x)); // Άξονας Y const y = d3.scaleLinear() .domain([0, 500]) .range([ yMax, 0]); svg.append("g") .call(d3.axisLeft(y)); // Πunctuation svg.append('g') .selectAll("κουκίδα") .data(data).enter() .append("κυκλός") .attr("cx", function (d) { return d[0] } ) .attr("cy", function (d) { return d[1] } ) .attr("r", 3) .style("χρωματισμός", "Κόκκινο");
- Προηγούμενη σελίδα JS Γραφήματα του Google
- Επόμενη σελίδα Παραδείγματα JS