D3.js D3JS轴图错误
我的图表中有一个bug,特别是在x轴标签中 据推测,它应该显示从csv导入的数据的月份,但滴答声被窃听了。标签上显示“dec”,但数据来自1月份 这是我的功能,在用户按下切换到每月数据后加载数据:D3.js D3JS轴图错误,d3.js,charts,D3.js,Charts,我的图表中有一个bug,特别是在x轴标签中 据推测,它应该显示从csv导入的数据的月份,但滴答声被窃听了。标签上显示“dec”,但数据来自1月份 这是我的功能,在用户按下切换到每月数据后加载数据: function updateDataMonthly() { var parseDate = d3.time.format("%d-%m-%Y").parse; d3.select("#chart-rate-of-change svg > *").remove(); d3.csv("dat
function updateDataMonthly() {
var parseDate = d3.time.format("%d-%m-%Y").parse;
d3.select("#chart-rate-of-change svg > *").remove();
d3.csv("data/chart-rateofchangemonthly.csv",function(err,data){
//get each key of the data that is not date
//these will be our key in the key/value pair
//the values x and y will be month and the value
var testdata = Object.keys(data[0]).filter(function(k){return k!="month"})
.map(function(k){
return {"key":k, "values":data.map(function(d){
return {
//let's make this a real date
"x":parseDate(d.month),
"y":+d[k]
}
})}
})
console.log(testdata);
var i=0;
testdata[i].type = "line";
testdata[i++].yAxis = 1;
testdata[i].type = "line";
testdata[i++].yAxis = 1;
testdata[i].type = "line";
testdata[i++].yAxis = 1;
testdata[i].type = "line";
testdata[i++].yAxis = 1;
testdata[i].type = "line";
testdata[i++].yAxis = 1;
testdata[i].type = "line";
testdata[i++].yAxis = 1;
testdata[i].type = "line";
testdata[i++].yAxis = 1;
nv.addGraph(function() {
var chart = nv.models.multiChart()
.margin({top: 30, right: 140, bottom: 50, left: 100})
.interpolate("linear").color(d3.scale.category10().range());
chart.xAxis.tickFormat(function(d) {
console.log(d);
console.log(new Date(d));
return d3.time.format("%b")(new Date(d))
});
chart.useInteractiveGuideline(true);
chart.xAxis.rotateLabels(-20);
chart.yAxis1.tickFormat(d3.format(',f'));
chart.yAxis1.axisLabel("Rate Of Change (ppm)")
.showMaxMin(true);
//chart.yAxis.axisLabel("Temperature (ºC)");
var hdrfmt = d3.time.format("%b");
chart.interactiveLayer.tooltip.headerFormatter(hdrfmt);
d3.select('#chart-rate-of-change svg')
.datum(testdata)
.call(chart);
nv.utils.windowResize(chart.update);
return chart;
});
})
}
谢谢你的帮助 您的日期在chart-rateofchangemonthly.csv中的格式如何?您的日期在chart-rateofchangemonthly.csv中的格式如何?