我非常喜欢dygraphs中的errorBar功能,但我似乎无法让它工作。该图表显示正常,但如果我将errorBars更改为true,则不再绘制图形。
此外,注释根本没有显示。当我和#34;硬编码"我能够得到这项工作。数据,但现在似乎我把它放入一个数组,它不再工作了。
function nameAnnotation(ann) {
return "(" + ann.series + ", " + ann.x + ")";
};
var data = [];
data.push([new Date("2007/01/01"),10000,1]);
data.push([new Date("2007/01/02"),9463.777815,16]);
data.push([new Date("2007/01/03"),8748.659709,31]);
data.push([new Date("2007/01/04"),7779.545394,46]);
data.push([new Date("2007/01/05"),6846.280611,61]);
data.push([new Date("2007/01/06"),6042.265704,76]);
data.push([new Date("2007/01/07"),5052.064845,91]);
data.push([new Date("2007/01/08"),4089.830899,106]);
data.push([new Date("2007/01/09"),3195.631158,121]);
data.push([new Date("2007/01/10"),2541.901849,136]);
data.push([new Date("2007/01/11"),1805.774559,151]);
data.push([new Date("2007/01/12"),1167.31813,166]);
data.push([new Date("2007/01/13"),433.566787,181]);
data.push([new Date("2007/01/14"),-475.4670651,196]);
data.push([new Date("2007/01/15"),-1171.779711,211]);
data.push([new Date("2007/01/16"),5000,226]);
data.push([new Date("2007/01/17"),4091.462451,241]);
data.push([new Date("2007/01/18"),3386.055666,256]);
data.push([new Date("2007/01/19"),2728.37301,271]);
data.push([new Date("2007/01/20"),2167.424525,286]);
data.push([new Date("2007/01/21"),1483.230149,301]);
data.push([new Date("2007/01/22"),917.4477079,316]);
data.push([new Date("2007/01/23"),179.2235937,331]);
data.push([new Date("2007-01-24"),-625.1312787,346]);
data.push([new Date("2007/01/25"),-1209.343528,361]);
data.push([new Date("2007/01/26"),-1832.497902,376]);
data.push([new Date("2007/01/27"),-2426.93031,391]);
data.push([new Date("2007/01/28"),-2940.290957,406]);
data.push([new Date("2007/01/29"),-3745.675041,421]);
data.push([new Date("2007/01/30"),-4412.335834,436]);
data.push([new Date("2007/01/31"),-5303.819068,451]);
g = new Dygraph(
document.getElementById("graphdiv"),
data
,
{
labels: [ "Date", "Series1", "Error" ],
//errorBars: true,
axisLineColor: "red",
sigma: 2.0
}
);
g.ready(function() {
g.setAnnotations([
{
series: "Series1",
icon: 'images/Money.png',
width: 35,
height: 45,
x: "2007/01/01",
shortText: "P",
text: "Pay Day"
},
{
series: "Series1",
icon: 'images/Money.png',
width: 35,
height: 45,
x: "2007/01/16",
shortText: "P",
text: "Pay Day"
},
{
series: "Series1",
icon: 'images/dollarsign.png',
width: 18,
height: 20,
x: "2007/01/14",
shortText: "O",
text: "Possible Cash Shortage"
},
{
series: "Series1",
icon: 'images/dollarsign.png',
width: 18,
height: 20,
x: "2007/01/24",
text: "Possible Cash Shortage"
},
{
series: "Series1",
icon: 'images/bill.png',
width: 18,
height: 20,
x: "2007/01/13",
text: "Car Insurance Payment"
},
{
series: "Series1",
icon: 'images/bill.png',
width: 18,
height: 20,
x: "2007/01/23",
text: "Car Loan Payment"
}
]);
});
答案 0 :(得分:0)
我不确定这是否是您想要的效果,但是看一下文档(http://dygraphs.com/tests/steps.html中的示例),您可以看到正确的设置方法您的errorBars
而不是像这样格式化数据:[new Date("2007/01/01"),10000,1]
它应该像这样设置:
数据设置
[new Date("2007/01/01"),[10000,1]]
标签设置
labels: [ "Date", "Series1" ]
就注释而言......再次,设置错误。如果你看看它们是如何设置的,它会在你的选项中使用Dygraph绘制回调函数。注释的示例用法:
drawCallback: function(g) {
var ann = g.annotations();
var html = "";
for (var i = 0; i < ann.length; i++) {
var name = nameAnnotation(ann[i]);
html += name + " : " + (ann[i].shortText || '(icon)') + "<br/>";
}
document.getElementById("ann").innerHTML = html;
}
请参阅以下文档和示例小提琴以了解正确用法: