zoukankan      html  css  js  c++  java
  • [D3] SVG Graphics Containers and Text Elements in D3 v4

    SVG is a great output format for data visualizations because of its scalability, but it comes with some idiosyncrasies and unique challenges. In this lesson we’ll learn how to use graphics containers, the SVG equivalent of a div, as well as text elements for displaying, you guessed it, text.

    var scores = [
      { name: 'Alice', score: 96 },
      { name: 'Billy', score: 83 },
      { name: 'Cindy', score: 91 },
      { name: 'David', score: 96 },
      { name: 'Emily', score: 88 }
    ];
    
    const bars = d3.select('.chart')
        .append('svg')
            .attr('width', 300)
            .attr('height', 300)
            .style('background', 'white')
        .selectAll('g') // 'g' works as canvas on svg
        .data(scores)
        .enter()
            .append('g')
            .attr('transform', (d, i) => 'translate(0, ' + i * 33 + ')');
    
    
    bars.append('rect')
        .attr('width', d => d.score)
        .attr('class', 'bar');
    
    bars.append('text')
        .text(d => d.name)  
        .attr('y', 20);

  • 相关阅读:
    2018-04-13Java编程夯实学习心得(3)
    2018-03-28JavaScript学习心得
    2018-03-27mysql学习心得
    JavaScript-作用域
    样式切换图
    购物车结算
    Visual Studio Code快捷键操作
    复选框
    win10锁屏界面无法设置隐藏
    轮播图
  • 原文地址:https://www.cnblogs.com/Answer1215/p/7286928.html
Copyright © 2011-2022 走看看