Reputation: 3051
I appreciate the attention provided. I have several lines that represent a line chart. currently the domain is between 0 and 100.
var y = d3.scale.linear()
.domain([0, 100])
but in some specific times I would like this domain to change according to the new data entered.
// Add new values
var count_for=0;
for (var name in groups) {
count_for++;
var group = groups[name]
if(count<=15 || count>=35){
group.data.push(20 + Math.random() * 100)
}
if(count>15 && count<20){
group.data.push(124+count_for)
}
if(count>=20 && count<25){
group.data.push(200+count_for)
}
if(count>=25 && count<35){
group.data.push(-8-count_for)
}
group.path.attr('d', line)
}
count++;
and the data that has been drawn would like them to be adjusted according to the new domain. how can I do it?
http://plnkr.co/edit/pOvnRRN3ecbnvLNWOt1h?p=preview
Upvotes: 0
Views: 117
Reputation: 746
Every time a new data is pushed, the domains need to be recalculated. To update the domain of y, you can use y.domain(d3.extent(group.data))
.
Upvotes: 1