当我开始使用范围选择器时,Dygraphs中的范围选择器将x轴的起始值与10相乘(默认情况下,加载页面x轴后正确)。例如我的第一个x轴值是1 - >范围选择器从10开始(5 - >从50开始)。 数据采用JSON格式,无需范围选择器即可正确显示。 我该如何解决这个问题或解决这个问题?
以下是dygraph.com/fiddle jsfiddle中的代码 我无法显示JSON解析,所以我输入了我在浏览器的源代码中看到的JSON。 (它从10开始,但在我的数据库中以1开头。图表在x轴上显示10,但在我移动范围选择器之前显示1的y值)
//THIS IS THE JSON THAT I SEE IN SOURCE CODE:
var datenausdb = '[["10","100.0000","101.0000","100.0000"],["11","105.0000","99.0000","100.0000"],["12","104.0000","101.0000","102.0000"],["13","105.0000","102.0000","102.0000"]]';
var datenausdbA = JSON.parse(datenausdb);
$(window).load(function () {
g = new Dygraph(
document.getElementById("div1"),
datenausdb, {
title: '%Performance',
showRangeSelector: true,
rangeSelectorHeight: 50,
});
});
但是当我手动操作JSON到
时也会发生这种情况var datenausdb = '[["1","100.0000","101.0000","100.0000"],["2","105.0000","99.0000","100.0000"],["3","104.0000","101.0000","102.0000"],["4","105.0000","102.0000","102.0000"]]';
1显示在x轴上。当我移动选择器时,它变为10并且图表中不再显示任何内容
答案 0 :(得分:1)
我想将完整的解决方案发布到我的问题中,这是由Dan提到的字符串引起的。
我还必须改变日期。这个有效:
var datenausdb = [
["2013-08-05","100.0000","100.0000","99.9700"],
["2013-08-06","100.0000","101.0000","100.5000"],
["2013-08-07","101.1200","101.1200","101.1000"],
["2013-08-08","100.0100","100.0100","100.0100"],
["2013-08-09","99.9700","99.9700","99.9700"],
["2013-08-12","100.0000","100.0000","100.0000"],
["2013-08-13","101.0000","101.0000","102.0000"],
["2013-08-14","101.1200","101.1200","102.5000"],
["2013-08-15","100.0100","100.0100","100.0100"],
["2013-08-16","99.9700","99.9700","99.9700"],
["2013-08-19","100.5000","100.5000","100.5000"],
["2013-08-20","101.1000","101.1000","101.1000"],
["2013-08-21","102.0000","102.0000","99.9700"]
];
for (var k = 0; k < datenausdb.length; k++){
datenausdb[k][0] = new Date(datenausdb[k][0]);
}
for (var i = 0; i < datenausdb.length; i++){
for (var j = 1; j < datenausdb[i].length; j++) {
datenausdb[i][j] = parseFloat(datenausdb[i][j]);
}
}
$(document).ready(function () {
g1 = new Dygraph(
document.getElementById("div1"),
datenausdb,
{
showRangeSelector: true,
rangeSelectorHeight: 50,
}
);
}
);