zoukankan      html  css  js  c++  java
  • Basic scatterplot in d3.js

    https://www.d3-graph-gallery.com/graph/scatter_basic.html

    <!-- Code from d3-graph-gallery.com -->
    <!DOCTYPE html>
    <meta charset="utf-8">

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

    <!-- Create a div where the graph will take place -->
    <div id="my_dataviz"></div>


    <script>

    // set the dimensions and margins of the graph
    var margin = {top: 10, right: 30, bottom: 30, left: 60},
    width = 460 - margin.left - margin.right,
    height = 400 - margin.top - margin.bottom;

    // append the svg object to the body of the page
    var 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 data
    d3.csv("https://raw.githubusercontent.com/holtzy/data_to_viz/master/Example_dataset/2_TwoNum.csv", function(data) {

    // Add X axis
    var x = d3.scaleLinear()
    .domain([0, 4000])
    .range([ 0, width ]);
    svg.append("g")
    .attr("transform", "translate(0," + height + ")")
    .call(d3.axisBottom(x));

    // Add Y axis
    var y = d3.scaleLinear()
    .domain([0, 500000])
    .range([ height, 0]);
    svg.append("g")
    .call(d3.axisLeft(y));

    // Add dots
    svg.append('g')
    .selectAll("dot")
    .data(data)
    .enter()
    .append("circle")
    .attr("cx", function (d) { return x(d.GrLivArea); } )
    .attr("cy", function (d) { return y(d.SalePrice); } )
    .attr("r", 1.5)
    .style("fill", "#69b3a2")

    })

    </script>

  • 相关阅读:
    Windows服务BAT命令-安装、卸载、启动、停止
    身份认证
    密钥管理概述
    快速上手几个Linux命令
    递归
    数字签名的实现方案
    数字签名
    密码学基础
    你可以把Linux内核当成一家软件外包公司的老板
    数学归纳法
  • 原文地址:https://www.cnblogs.com/kungfupanda/p/13334363.html
Copyright © 2011-2022 走看看