# Grid Lines

Original D3 demo at https://bl.ocks.org/d3noob/c506ac45617cf9ed39337f99f8511218

Tue 27Thu 29Sat 31AprilTue 03Thu 05Sat 07Mon 09Wed 11Fri 13Apr 15Tue 17Thu 19Sat 21Mon 23Wed 25Fri 27Apr 29May 050100150200250300350400450500550600
<template>
  <d3-cartesian class="demo" :width="860" :height="450" :x="x" :y="y">
    <template #default="props">
      <d3-grid-lines orientation="Horizontal" :options="gridLineOptions" v-bind="props"/>
      <d3-grid-lines orientation="Vertical" :options="gridLineOptions" v-bind="props"/>
      <d3-line :data="data" x="date" y="close" v-bind="props"/>
    </template>
    <template #south="props">
      <d3-axis orientation="Bottom" v-bind="props"/>
    </template>
    <template #west="props">
      <d3-axis orientation="Left" v-bind="props"/>
    </template>
  </d3-cartesian>
</template>

<script>
import * as d3 from 'd3'
const parseTime = d3.timeParse("%d-%b-%y")

export default {
  data () {
    return {
      x: { type: 'Time', domain: [] },
      y: { type: 'Linear', domain: [] },
      data: null,
      gridLineOptions: { count: 5 }
    }
  },
  created () {
    d3.csv('/data/stock.csv',
      d => {
        d.date = parseTime(d.date)
        d.close = +d.close
        return d
      }).then(data => {
        this.x.domain = d3.extent(data, d => d.date)
        this.y.domain = [0, d3.max(data, d => d.close)]
        this.data = data
      })
  }
}
</script>

<style lang="scss" scoped>
.demo /deep/ {
  .line {
    stroke-width: 2px;
  }
}
</style>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51