Below is how I creat a bar chart using rect
s in D3. However, how would I modify that to get the bar chart with path property in d3js?
I have a json file which has the data to be read and am trying to create a bar chart with paths rather than rectangles in d3js.
Json :
[
{
"name": "sam",
"age": 24
},
{
"name": "baby",
"age": 23
},
{
"name": "adu",
"age": 21
},
{
"name": "ja",
"age": 23
},
{
"name": "mack",
"age": 34
}
]
Code:
<script>
d3.json("mydata.json", function (data) {
var canvas = d3.select('body').append('svg')
.attr('width', 500)
.attr('height', 500);
canvas.selectAll('rect')
.data(data)
.enter()
.append('rect')
.attr('width',function (d) { return d.age * 10; })
.attr('height', 48)
.attr('y', function (d, i) { return i * 50; })
.attr('fill', 'blue');
canvas.selectAll('text')
.data(data)
.enter()
.append('text')
.attr('fill','white')
.attr('y', function (d, i) {
return i* 50 + 24;
})
.text(function (d) {
return d.name;
})
});
</script>
I have searched through many sites. I am unable to get though