Dygraphs 不接受变量作为数组数据集的标签
Dygraphs not accepting variable as Label for array dataset
我正在整理 dygraphs,这很有趣。
出于某种原因,尽管它不接受变量作为包含数据的数组的标签。我已将字符串格式化为与 "hardcoded" 条目完全一样,但它不起作用。
这里有一些片段可以让你明白我的意思。
var select =('<?php echo implode('","', $select); ?>');
var label='"X"'+ ',"'+select+'"';
g = new Dygraph(
// containing div
document.getElementById("graphdiv"),allData,
{
labels: [label], // I tried it with and without the brackets, no difference
legend:'always',
title:'Abweichung der Messerte',
titleHeight:32,
ylabel:'<?php echo $art?>',
xlabel:'Zeit',
showRangeSelector: true,
digitsAfterDecimal: 5,
strokeWidth: 1.5,
drawPoints: true,
}
);
如果我将标签记录到控制台,它看起来像这样,具体取决于所选数字:
""X","10002","10003""
我仍然收到以下错误
"Mismatch between number of labels ("X","10002","10003") and number of columns in array (3)"
我的 allData 数组格式是 [time,Value1,Value2],如果我对标签进行硬编码,它可以正常工作。
请告诉我哪里做错了:-)
问候大卫
您需要传递一个字符串数组,而不是逗号分隔的标签字符串。
即
['X', 'Y1', 'Y2']
而不是
'X,Y1,Y2'
我正在整理 dygraphs,这很有趣。 出于某种原因,尽管它不接受变量作为包含数据的数组的标签。我已将字符串格式化为与 "hardcoded" 条目完全一样,但它不起作用。
这里有一些片段可以让你明白我的意思。
var select =('<?php echo implode('","', $select); ?>');
var label='"X"'+ ',"'+select+'"';
g = new Dygraph(
// containing div
document.getElementById("graphdiv"),allData,
{
labels: [label], // I tried it with and without the brackets, no difference
legend:'always',
title:'Abweichung der Messerte',
titleHeight:32,
ylabel:'<?php echo $art?>',
xlabel:'Zeit',
showRangeSelector: true,
digitsAfterDecimal: 5,
strokeWidth: 1.5,
drawPoints: true,
}
);
如果我将标签记录到控制台,它看起来像这样,具体取决于所选数字:
""X","10002","10003""
我仍然收到以下错误
"Mismatch between number of labels ("X","10002","10003") and number of columns in array (3)"
我的 allData 数组格式是 [time,Value1,Value2],如果我对标签进行硬编码,它可以正常工作。
请告诉我哪里做错了:-)
问候大卫
您需要传递一个字符串数组,而不是逗号分隔的标签字符串。
即
['X', 'Y1', 'Y2']
而不是
'X,Y1,Y2'