D3 Tutorial Shapes Edit by Jiayi Xu and Han-Wei Shen, The Ohio - - PowerPoint PPT Presentation

d3 tutorial
SMART_READER_LITE
LIVE PREVIEW

D3 Tutorial Shapes Edit by Jiayi Xu and Han-Wei Shen, The Ohio - - PowerPoint PPT Presentation

D3 Tutorial Shapes Edit by Jiayi Xu and Han-Wei Shen, The Ohio State University Lines Line Generator lineGenerator is a function that accepts an array of co-ordinates and outputs a path data string Constructs a new line generator


slide-1
SLIDE 1

D3 Tutorial

Shapes

Edit by Jiayi Xu and Han-Wei Shen, The Ohio State University

slide-2
SLIDE 2
  • lineGenerator is a function that accepts an array of co-ordinates and
  • utputs a path data string

Lines – Line Generator

  • Constructs a new line

generator

slide-3
SLIDE 3

Lines – Line Generator

  • Define an array of

coordinates

slide-4
SLIDE 4

Lines – Line Generator

  • Now call lineGenerator,

passing in our data points

  • pathData is

"M0,80L100,100L200,30L30 0,50L400,40L500,80”

  • A path string for SVG to draw a line
slide-5
SLIDE 5

Lines – Line Generator

  • Draw the line
slide-6
SLIDE 6

Lines – Curve

  • Draw a curve
  • line.curve(curveType)
  • Explore more curve types
  • http://bl.ocks.org/d3indepth/raw/b6d4845973089bc1012dec1674d3aff8/
slide-7
SLIDE 7
  • Let’s create a line chart together!
  • Data
  • Apple stock (AAPL) price from April 23rd, 2012 to May 1st, 2012

Lines – Create a line chart

slide-8
SLIDE 8
  • Scale
  • xScale: Date to width
  • yScale: Price to height

Lines – Create a line chart

  • Final Result
slide-9
SLIDE 9
  • Line generator
  • Tell the generator how to map data

[date, price] to coordinates [x, y]

Lines – Create a line chart

  • Final Result
slide-10
SLIDE 10
  • Draw axes
  • Draw lines

Lines – Create a line chart

  • Final Result
slide-11
SLIDE 11
  • The radial line generator is similar to the line generator but the points are

formed by angle in radians (clockwise) and radius, rather than x and y

  • Data can be encoded into angle and radius
  • Application: Radar graphs

Lines – Radial Line d3.radialLine()

slide-12
SLIDE 12
  • The area generator outputs path that defines an area between two lines.
  • Data can be encoded into coordinates on the two lines
  • Application: Stream graphs, filled line charts

Area – d3.area()

slide-13
SLIDE 13
  • The radial area generator is similar to the area generator but the points

are formed by angle in radians (clockwise) and radius, rather than x and y

  • Data can be encoded into angle and radius
  • Application: Filled radar graphs

Area – Radial Area d3.radialArea()

slide-14
SLIDE 14

Arc - d3.arc()

  • Arc generators produce path data from angle and radius values
  • Data can be encoded into angle and radius
  • Application: Pie Chart
slide-15
SLIDE 15

Arc – Multiple arcs

  • Multiple arcs
  • A template of pie chart
slide-16
SLIDE 16

Symbols - d3.symbol()

  • The symbol generator produces path data for symbols
  • position
  • We can use transform to set coordinates
  • types