Slide 8
Slide 8 text
·ͣ7VFΛΘͣʹॻ͍ͯΈΔ
const dataset = [ 10, 20, 5, 3, 8, 40, 20, 35];
const w = 200, h = 100, margin = 5;
const svg = d3.select(‘.graph').append('svg')
.attr('width', w + margin).attr('height', h + margin);
const xScale = d3.scaleLinear().domain([0, dataset.length]).range([margin, w - margin]);
const yScale = d3.scaleLinear().domain([d3.min(dataset), d3.max(dataset)]).range([h -
margin, margin]);
const xAxis = d3.axisBottom(xScale);
svg.append('g')
.attr('transform', `translate(0, ${h})`)
.call(xAxis);
const yAxis = d3.axisLeft(yScale);
svg.append('g')
.attr('transform', `translate(${margin}, 0)`)
.call(yAxis);
const d3line = d3.line()
.x((d, i) => xScale(i))
.y(d => yScale(d))
.curve(d3.curveLinear);
svg.append('path')
.attr(‘d', d3line(dataset))
.style('stroke-width', 2)
.style('stroke', 'steelblue')
.style('fill', 'none');