javascript - Use arrays as data sources in timeseries chart C3.js -


i want use arrays sources in c3.js chart this:

var xdata = ['2017-07-28', '2017-07-29']; var ydata = [30, 200];  var chart = c3.generate({     bindto: '#chart',     data: {         x: 'x',         xformat: '%y-%m-%d',         columns: [             ['x', xdata],             ['data1', ydata]         ]     },     axis: {         x: {             type: 'timeseries',             tick: {                 format: '%y-%m-%d'             }         }     } }); 

but gives me errors like:

failed parse x '2017-07-28,2017-07-29' date object

error: attribute transform: expected number, "translate(nan, 0)".

if use direct values works perfectly:

var chart = c3.generate({     bindto: '#chart',     data: {         x: 'x',         xformat: '%y-%m-%d',         columns: [             ['x', '2017-07-28', '2017-07-29'],             ['data1', 30, 200]         ]     },     axis: {         x: {             type: 'timeseries',             tick: {                 format: '%y-%m-%d'             }         }     } }); 

in case,

['x', xdata]  

is equal

['x', ['2017-07-28', '2017-07-29']] 

not

['x', '2017-07-28', '2017-07-29'] 

what can create array before :

var xdata = ['2017-07-28', '2017-07-29']; var ydata = [30, 200];  xdata.unshift('x'); ydata.unshift('data1');  var chart = c3.generate({      bindto: '#chart',      data: {          x: 'x',          xformat: '%y-%m-%d',          columns: [              xdata,              ydata         ]     },     axis: {         x: {              type: 'timeseries',              tick: {                  format: '%y-%m-%d'              }         }     } }); 

Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -