如何根据月份的变化从控制台中获取销售价值,我希望数据应该影响我的数据 这是我的选择框:
<select id="months">
<option value="">Select</option>
<option value="nov">NOV</option>
<option value="dec">DEC</option>
<option value="jan">JAN</option>
</select>
这是JavaScript
function sales(booked, total) {
this.booked = booked;
this.total = total;
};
sale = new sales(8, 12) ;
$("#months").on('change', function(){
mons = $(this).val();
console.log(mons);
if(mons == "nov"){
sale = new sales(1,12) ;
}
if(mons == "dec"){
sale = new sales(2,12) ;
}
if(mons == "jan"){
sale = new sales(15,12) ;
}
console.log(sale.booked +' ' +sale.total);
});
console.log(sale.booked +' ' +sale.total);
var w = 400;
var h = 400;
var r = h/2;
var color = d3.scale.category20c();
data = [{"label":"booked " + sale.booked, "value": sale.booked},
{"label": "total " + sale.total, "value": sale.total}];
var vis = d3.select('#chart').append("svg:svg").data([data]).attr("width", w).attr("height", h).append("svg:g").attr("transform", "translate(" + r + "," + r + ")");
var pie = d3.layout.pie().value(function(d){return d.value;});
// declare an arc generator function
var arc = d3.svg.arc().outerRadius(r);
// select paths, use arc generator to draw
var arcs = vis.selectAll("g.slice").data(pie).enter().append("svg:g").attr("class", "slice");
arcs.append("svg:path")
.attr("fill", function(d, i){
return color(i);
})
.attr("d", function (d) {
// log the result of the arc generator to show how cool it is :)
//console.log(arc(d));
return arc(d);
});
我想根据此月份选择框的更改来更改var数据的值, 我试图通过这个,但在月更改功能的范围内,它工作正常,价值观正在改变,但外面我不能得到这种变化。 我怎么能得到它。