简体   繁体   中英

Dygraphs not accepting variable as Label for array dataset

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

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

ie

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

and not

'X,Y1,Y2'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM