我正在尝试查询MySQL数据库并使用d3plus创建可视化。我的后端是Express.JS,模板是EJS
这是我的错误:
ReferenceError: C:\cit\views\results.ejs:10
8|
9| <script>
>> 10| <% var data = [
11| {"year": 2011, "name":"jobs", "value": "2011"}
12| ]
13| var visualization = d3plus.viz()
d3plus is not defined
at eval (eval at compile (C:\cit\node_modules\ejs\lib\ejs.js:618:12), <anonymous>:31:24)
at returnedFn (C:\cit\node_modules\ejs\lib\ejs.js:653:17)
at tryHandleCache (C:\cit\node_modules\ejs\lib\ejs.js:251:36)
at View.exports.renderFile [as engine] (C:\cit\node_modules\ejs\lib\ejs.js:482:10)
at View.render (C:\cit\node_modules\express\lib\view.js:135:8)
at tryRender (C:\cit\node_modules\express\lib\application.js:640:10)
at Function.render (C:\cit\node_modules\express\lib\application.js:592:3)
at ServerResponse.render (C:\cit\node_modules\express\lib\response.js:1008:7)
at Query.con.query (C:\cit\app.js:24:13)
at Query.<anonymous> (C:\cit\node_modules\mysql\lib\Connection.js:502:10)
我的results.ejs代码:
<% include partials/header.ejs %>
<h1>= <%= naics %></h1>
<h1>= <%= industry %></h1>
<div id="viz"></div>
<script>
<% var data = [
{"year": 2011, "name":"jobs", "value": "2011"}
]
var visualization = d3plus.viz()
.container("#viz")
.data(data)
.type("bar")
.id("name")
.x("year")
.y("value")
.draw() %>
</script>
<% include partials/footer.ejs %>
还有我的具有d3plus脚本源的header.ejs代码:
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<script src="http://d3plus.org/js/d3.js"></script>
<script src="http://d3plus.org/js/d3plus.js"></script>
<title>The HTML5 Herald</title>
<meta name="description" content="The HTML5 Herald">
<meta name="author" content="SitePoint">
</head>
<body>
现在,我正在制作可视化的硬拷贝,但仍然遇到问题。可能是什么问题?
PS:我的脚注中也添加了脚本源。万一这是问题。不是。
最佳答案
我认为您正在使用d3plus v1。相反,您必须使用d3plus v2。 new d3plus.BarChart() .select("#viz") .data(data) .x("year") .y("value") .groupBy("name") .render();