{
let parcoords2 = ParCoords()("#example2")
.data(
[
{name: "Asparagus", protein: 2.2, calcium: 0.024, sodium: 0.002},
{name: "Butter", protein: 0.85, calcium: 0.024, sodium: 0.714},
{name: "Coffeecake", protein: 6.8, calcium: 0.054, sodium: 0.351},
{name: "Pork", protein: 28.5, calcium: 0.016, sodium: 0.056},
{name: "Provolone", protein: 25.58, calcium: 0.756, sodium: 0.876}
]
)
.on("render axesreorder", function() {
const pc = this
const svg = pc.svg
const lines = [
{dimension: "protein", value: 15},
{dimension: "calcium", value: 0.7}
]
let overlay = this.svg.selectAll('.overlay').data([lines])
overlay = overlay.merge(overlay.enter().append('g').classed('overlay', true))
overlay.call(drawLines)
function drawLines(selection) {
const data = selection.datum()
let paths = selection.selectAll('path').data(data)
const dim = pc.dimensions()
paths = paths.merge(paths.enter().append('path'))
paths
.attr('d', d => {
let x = pc.xscale(d.dimension)
const y = dim[d.dimension].yscale(d.value)
return d3.line()([[x-30, y],[x+30, y]])
})
.style('stroke', 'red')
}
})
parcoords2
.render()
.createAxes()
.reorderable()
return parcoords2
}