这应该让你开始。你可以在

http://bl.ocks.org/2595950看到它。

// data that you want to plot, I've used separate arrays for x and y values

var xdata = [5, 10, 15, 20],

ydata = [3, 17, 4, 6];

// size and margins for the chart

var margin = {top: 20, right: 15, bottom: 60, left: 60}

, width = 960 - margin.left - margin.right

, height = 500 - margin.top - margin.bottom;

// x and y scales, I've used linear here but there are other options

// the scales translate data values to pixel values for you

var x = d3.scale.linear()

.domain([0, d3.max(xdata)]) // the range of the values to plot

.range([ 0, width ]); // the pixel range of the x-axis

var y = d3.scale.linear()

.domain([0, d3.max(ydata)])

.range([ height, 0 ]);

// the chart object, includes all margins

var chart = d3.select('body')

.append('svg:svg')

.attr('width', width + margin.right + margin.left)

.attr('height', height + margin.top + margin.bottom)

.attr('class', 'chart')

// the main object where the chart and axis will be drawn

var main = chart.append('g')

.attr('transform', 'translate(' + margin.left + ',' + margin.top + ')')

.attr('width', width)

.attr('height', height)

.attr('class', 'main')

// draw the x axis

var xAxis = d3.svg.axis()

.scale(x)

.orient('bottom');

main.append('g')

.attr('transform', 'translate(0,' + height + ')')

.attr('class', 'main axis date')

.call(xAxis);

// draw the y axis

var yAxis = d3.svg.axis()

.scale(y)

.orient('left');

main.append('g')

.attr('transform', 'translate(0,0)')

.attr('class', 'main axis date')

.call(yAxis);

// draw the graph object

var g = main.append("svg:g");

g.selectAll("scatter-dots")

.data(ydata) // using the values in the ydata array

.enter().append("svg:circle") // create a new circle for each value

.attr("cy", function (d) { return y(d); } ) // translate y value to a pixel

.attr("cx", function (d,i) { return x(xdata[i]); } ) // translate x value

.attr("r", 10) // radius of circle

.style("opacity", 0.6); // opacity of circle

这样使用:

The d3 test

html点击散点图的点显示一个文本,javascript – D3.js中的简单散点图示例?相关推荐

  1. html div中显示pdf,使用Javascript从div中的HTML生成pdf

    汪汪一只猫 jsPDF能够使用插件.为了使它能够打印HTML,您必须包含某些插件,因此必须执行以下操作:去https://github.com/MrRio/jsPDF下载最新版本.在项目中包括以下脚本 ...

  2. 在linux桌面上创建一个文本,如何在Ubuntu中创建文档

    有几种方法可以在Ubuntu中使用GUI和命令行创建文档.所有这些方法都非常简单易用.您可能早些时候已在Ubuntu中将这些方法用于其他目的.但是,在本文中,我们将向您展示在Ubuntu中创建文档的8 ...

  3. 一个讨论引发关于js中函数声明,函数表达式,形参与变量声明赋值引发的一些事(http://www.cnblogs.com/zhouyongtao/archive/2012/11/22/2783089)

    //Firefox 17下运行结果 function a(){} undefined [function a(){}, 2, 3] ee 444 6 ========================= ...

  4. Java黑皮书课后题第6章:*6.17(显示0和1构成的矩阵)编写一个方法,使用下面的方法头显示m*n矩阵。每个元素都是随机产生的0或1。编写一个测试程序,提示用户输入n,显示一个n*n矩阵

    6.17(显示0和1构成的矩阵)编写一个方法,使用下面的方法头显示m*n矩阵.每个元素都是随机产生的0或1.编写一个测试程序,提示用户输入n,显示一个n*n矩阵 题目 题目描述与运行示例 破题 代码 ...

  5. Java黑皮书课后题第5章:**5.17(显示金字塔)编写程序,提示用户输入一个在1到15之间的整数,然后显示一个金字塔形状的图案

    **5.17(显示金字塔)编写程序,提示用户输入一个在1到15之间的整数,然后显示一个金字塔形状的图案 题目 题目描述 运行示例 破题 代码 题目 题目描述 **5.17(显示金字塔)编写程序,提示用 ...

  6. Android Q : 安卓源码、水滴屏适配状态栏图标(图标过多时显示一个点)

    源码路径:com.android.systemui.statusbar.phone/StatusIconContainer.java 布局文件路径:SystemUI/res/layout/status ...

  7. vue js中解决二进制转图片显示问题

    一:问题 工作中碰到的问题,在处理接口返回的验证码图片时,由于返回的是encode编码代码,在js端获取到数据之后,通过函数encodeURI()来进行解码,之后可以通过在src中设置来实现图片显示: ...

  8. 用 Lunchbox 在 vue3 中创建一个旋转的 3D 地球竟是如此简单

    ⭐️ 本文首发自 前端修罗场(点击加入),是一个由 资深开发者 独立运行 的专业技术社区,我专注 Web 技术.Web3.区块链.答疑解惑.面试辅导以及职业发展.现在加入,私聊我即可获取一次免费的模拟 ...

  9. D3.js用动画渲染数据集的显示

    介绍 数据统计和数据分析离不开数据集.之前几篇博客(用D3.js进行医疗数据可视化 (一)折线图 (Line Chart) 等)基于的是国家卫生和计划生育委员会统计信息中心的数据,可以说是已经经过了加 ...

最新文章

  1. 如何选择分布式系统(区块链)协议?
  2. java读取服务器图片大小,SpringMVC中MultipartFile上传获取图片的宽度和高度详解
  3. android问题记录
  4. 使用vue控制元素显示隐藏
  5. hexo的yelee主题修改左上角的博客名字颜色、修改代码模块中的引号内部的字体颜色
  6. Linux mount: Structure needs cleaning 错误解决方法
  7. python requests 10041报错_pythonrequests返回unicode异常消息(或如何设置请求区域设置)...
  8. sysbench mysql 测试_sysbench MySQL测试例子
  9. 061 实例15-霍兰德人格分析雷达图
  10. 一键安装thrift-0.9.0的脚本
  11. JVM优化之压缩普通对象指针(CompressedOops)与压缩类指针(CompressedClassPointers)
  12. SPSS 随机区组秩和检验
  13. 计算机病毒分为哪三类
  14. DeFi新玩法丨一文教你玩转NFT碎片化协议Fractional
  15. JavaScript监听键盘事件,组合键事件
  16. SAP基底数据仓库实战项目(序章)
  17. 判断TTS语音朗读是否结束
  18. c/c++: window下安装mingw-w64
  19. 1.7 使用不同设备类型的iOS模拟器 [原创iOS开发-Xcode教程]
  20. C语言-输出一个菱形图。

热门文章

  1. JXJJOI2018_T2_tank
  2. 【IntelliJ IDEA】tomcat启动,打印日志乱码问题
  3. 为什么说一知半解的人生最可怕?
  4. 工业物联网为“两化融合”带来巨大推力
  5. nginx 的动静分离配置(tomcat)
  6. 理解Java中的弱引用(Weak Reference)
  7. 从vmware技术团队跳槽到微软技术团队(comlan)
  8. chHANDLE_DLGMSG(windows核心编程)讲解
  9. 学生课程表管理系统——stage 1
  10. python 使用set对list去重,并保持list原来顺序