Dygraphs not accepting variable as Label for array dataset

832 Views Asked by At

I'm tying out dygraphs an it´s pretty fun. For some reason though it does not accept a variable as labels for the array containing the data. I have formatted the string to exactly look like the "hardcoded" entry but it just won´t work.

Here are some snippets to let you know what i mean.

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,
    } 
  ); 

If i log label to the console it looks like this, depending on the selected numbers:

""X","10002","10003""

Still i get the folling error

"Mismatch between number of labels ("X","10002","10003") and number of columns in array (3)"

My array format for allData is [time,Value1,Value2] and works fine if i hardcode the labels.

Please tell me what i´m doing wrong :-)

greetings David

1

There are 1 best solutions below

0
On BEST ANSWER

You need to pass an array of strings, not a comma-separated string of labels.

i.e.

['X', 'Y1', 'Y2']

and not

'X,Y1,Y2'