简体   繁体   English

从Angular指令将数据传递到D3

[英]Passing Data to D3 from Angular directive

I am trying to create a chart using D3 and Angular, using data retrieved from a database. 我正在尝试使用D3和Angular创建图表,并使用从数据库中检索的数据。
The code below shows that chart_scan_times is the array that I want, but the graph is not displaying the data. 下面的代码显示chart_scan_times是我想要的数组,但是图形未显示数据。 Most like a problem with the '{{ }}' syntax on my EJS page, but I have tried including <%= %>, etc around the passing of chart_scan_times to data without it working 最像是EJS页面上的'{{}}'语法问题,但是我试图在将chart_scan_times传递给数据的过程中包括<%=%>等,但无法正常工作

    {{chart_scan_times}}
  <bars data='{{chart_scan_times}}'></bars>    

Displays this 显示此

The code below correctly displays the graph 下面的代码正确显示图形

      <bars data='40,4,14,22,99'></bars>

Displays This 显示此

Any help would be greatly appreciated 任何帮助将不胜感激

It seems the data attribute takes a string and you are passing an array. 似乎data属性采用字符串,并且您正在传递数组。 Try chart_scan_times = dataArr.join() from your controller or wherever you initialize this expression 在您的控制器或初始化此表达式的任何地方尝试chart_scan_times = dataArr.join()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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