d3 实现24小时时序图

d3 画圆点 实现24小时时序图并增加异常节点的提示功能

效果图

<!DOCTYPE html>
<html>

<head lang="en">
  <meta charset="UTF-8">
  <title></title>
  <style>
    body {
      text-align: center;
    }
    #svg_tooltip {
      position: absolute;
      border-radius: 4px;
      padding: 10px;
      z-index: 2000;
      font-size: 12px;
      line-height: 1.2;
      min-width: 10px;
      background: #000;
      color: #fff;
    }
    #svg_tooltip:before {
      content: "";
      position: absolute;
      display: block;
      width: 0px;
      border: 6px solid transparent;
      border-top: 6px solid #000;
      left: 45px;
      top: 34px;
    }
  </style>
</head>

<body>
  <h1>24小时状态时序图 d3</h1>
  <svg id="svg" width="310" height=&
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
使用d3实现可视化峰峦图相比使用Matplotlib库,需要更多的代码和工作量,但是可以实现更加灵活的可视化效果。以下是一个使用d3绘制峰峦图的示例代码: ```html <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Mountain Range</title> <script src="https://d3js.org/d3.v5.min.js"></script> <style> path { fill: none; stroke: #000; stroke-width: 1.5px; } </style> </head> <body> <svg width="960" height="500"></svg> <script> // 生成随机高程数据 var data = d3.range(100).map(function(d) { return [Math.random() * 10 - 5, Math.random() * 10 - 5, Math.random() * 3]; }); // 创建投影 var projection = d3.geoIdentity() .reflectY(true) .fitSize([960, 500], { type: "Sphere" }); // 创建路径生成器 var path = d3.geoPath() .projection(projection); // 创建颜色插值器 var color = d3.scaleLinear() .domain([0, 2]) .range(["#fff", "#69b3a2"]); // 创建SVG元素 var svg = d3.select("svg"); // 绘制山峦图 svg.selectAll("path") .data(data) .enter().append("path") .attr("d", function(d) { var x = d[0]; var y = d[1]; var h = d[2]; return path({ type: "LineString", coordinates: [[x, y], [x, y - h]] }); }) .attr("stroke", function(d) { return color(d[2]); }); </script> </body> </html> ``` 以上代码通过d3生成随机高程数据,然后使用投影和路径生成器绘制山峦图,并使用颜色插值器给不同高度的山峰着色。可以在浏览器中查看结果。如果需要更复杂的定制,可以在以上示例代码的基础上进行修改。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值