Node.js,express,jade,highcharts和2D数组

免责声明,我很新的javascript / node.js / express / jade / highcharts等…

对我的问题
我有一个模板,收到我预处理我的路由器代码几个参数。 参数被分成1个对象,并代表高数据graphics元数据和系列数据。

当我试图将二维数组传递给表示我的数据系列的玉石模板时,我遇到了一个问题,但在chrome开发工具中,它看起来像一个正常的数组。 我的Highcharts代码基于: Highcharts列图

这是我的代码:

delivered.js

var callback = function process_results(result){ var res = new Object() res.title = "Delivery Count" res.yAxisTitle = 'Delivered' res.seriesName = "Delivered per month" res.seriesData = [] for (var i = 0; i < result.rows.length; i++) { //process the query results row = result.rows[i] date = "\'" + row.month_delivered + '/' + row.year_delivered + "\'" count = row.count res.seriesData.push([date,count]) }; console.log(res) response.render('column-graph', res) } 

列graph.jade

 html head link(rel='stylesheet', href='/stylesheets/style.css') script(type='text/javascript', src="http://code.jquery.com/jquery-1.9.1.min.js") script(type='text/javascript', src="http://code.highcharts.com/highcharts.js") script(type='text/javascript', src="http://code.highcharts.com/modules/exporting.js") title Delivered Leads body div#container(style="min-width: 500px; height: 500px; margin: 0 auto") script. $(function () { $('#container').highcharts({ chart: { type: 'column' }, title: { text: "#{title}" }, subtitle: { text: 'Source: Internal DB' }, xAxis: { type: 'category', labels: { rotation: -45, style: { fontSize: '13px', fontFamily: 'Verdana, sans-serif' } } }, yAxis: { min: 0, title: { text: "#{yAxisTitle}" } }, legend: { enabled: false }, series: [{ name: '#{seriesName}', data: [#{seriesData}], dataGrouping: { enabled: true }, dataLabels: { enabled: true, rotation: -90, color: '#FFFFFF', align: 'right', x: 4, y: 10, style: { fontSize: '13px', fontFamily: 'Verdana, sans-serif', textShadow: '0 0 3px black' } } }] }); }); 

#{seriesData}参数是应该是二维数组的res.seriesData。 在deliver.js中,我有一个console.log(res)显示这个:

 { title: 'Delivery Count', yAxisTitle: 'Delivered', seriesName: 'Delivered per month', seriesData: [ [ '\'7/2014\'', '3000' ], [ '\'6/2014\'', '5163' ], [ '\'5/2014\'', '23882' ], [ '\'4/2014\'', '26471' ], [ '\'3/2014\'', '82172' ], [ '\'2/2014\'', '31283' ], [ '\'1/2014\'', '637400' ], [ '\'12/2013\'', '86420' ], [ '\'11/2013\'', '119150' ], [ '\'10/2013\'', '49093' ] ] } 

但是当我在浏览器中看到它时,我得到这个:

  series: [{ name: 'Delivered per month', data: ['7/2014',3000,'6/2014',5163,'5/2014',23882,'4/2014',26471,'3/2014',82172,'2/2014',31283,'1/2014',637400,'12/2013',86420,'11/2013',119150,'10/2013',49093], dataGrouping: { enabled: true }, dataLabels: { enabled: true, rotation: -90, color: '#FFFFFF', align: 'right', x: 4, y: 10, style: { fontSize: '13px', fontFamily: 'Verdana, sans-serif', textShadow: '0 0 3px black' } } }] }); 

对不起,很长的问题,并提前致谢!

最后,我做了其他的事情。 而不是在deliver.js中预处理数组,
我将数组传递给玉模板,并执行以下操作:

 html head link(rel='stylesheet', href='/stylesheets/style.css') script(type='text/javascript', src="http://code.jquery.com/jquery-1.9.1.min.js") script(type='text/javascript', src="http://code.highcharts.com/highcharts.js") script(type='text/javascript', src="http://code.highcharts.com/modules/exporting.js") title Delivered Leads body div#container(style="min-width: 500px; height: 500px; margin: 0 auto") script. var arrToMultiArr = function(arr){ var result = new Array() for (var i=0; i < arr.length; i+=2){ var date = arr[i] var count = arr[i + 1] result.push([date, count]) } return result }; var mySeries = arrToMultiArr([#{seriesData}]) $(function () { $('#container').highcharts({ chart: { type: 'column' }, title: { text: "#{title}" }, subtitle: { text: 'Source: Internal DB' }, xAxis: { type: 'category', labels: { rotation: -45, style: { fontSize: '13px', fontFamily: 'Verdana, sans-serif' } } }, yAxis: { min: 0, title: { text: "#{yAxisTitle}" } }, legend: { enabled: false }, series: [{ name: '#{seriesName}', data: mySeries, dataGrouping: { enabled: true }, dataLabels: { enabled: true, rotation: -90, color: '#FFFFFF', align: 'right', x: 4, y: 10, style: { fontSize: '11px', fontFamily: 'Verdana, sans-serif', textShadow: '0 0 3px black' } } }] }); }); 

尝试改变:

 data: [#{seriesData}], 

至:

 data: #{seriesData},