zoukankan      html  css  js  c++  java
  • D3——散点图Scatterplot

    散点图

    //Width and height
    var w = 500;
    var h = 100;
    var barPadding = 3;
                
    var dataset = [
          [5, 20], [480, 90], [250, 50], [100, 33], [330, 95],
          [410, 12], [475, 44], [25, 67], [85, 21], [220, 88]
    ];
                
    //Create SVG element
    var svg = d3.select("body")
        .append("svg")
        .attr("width", w)
        .attr("height", h);
    
    svg.selectAll("circle")  
       .data(dataset)
       .enter()
       .append("circle")
       .attr("cx", function(d) {
            return d[0];
       })
       .attr("cy", function(d) {
            return d[1];
       })
       .attr("r", 5)
       .attr("fill", "rgb(0,0,255)");

    .attr("r", function(d) {
        return Math.sqrt(h - d[1]);
    });

    添加labels

    svg.selectAll("text")
       .data(dataset)
       .enter()
       .append("text")
       .text(function(d) {
            return d[0] + "," + d[1];
       })
       .attr("x", function(d) {
            return d[0];
       })
       .attr("y", function(d) {
            return d[1];
       })
       .attr("font-family", "sans-serif")
       .attr("font-size", "11px")
       .attr("fill", "red");

  • 相关阅读:
    食谱
    食谱
    食谱
    无题
    重要通知
    幼儿食谱
    安卓应用开发常用代码
    安卓开发环境搭建
    《浪潮之巅》读书笔记——第11章 摩托罗拉
    预制redis数据
  • 原文地址:https://www.cnblogs.com/xuepei/p/7527536.html
Copyright © 2011-2022 走看看