带有 D3 的面积图无法在 JSP 页面上呈现,但与 HTML 配合使用正常
area chart with d3 is not rendering on jsp page but working fine with html
>我在HTML页面中成功渲染了D3JS面积图,这是在Chrome或Mozilla中成功呈现的代码。文件名是 temp.html.这是代码
<!DOCTYPE html>
<html lang="en" class="no-js">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>js graphs and charts libraries</title>
<script
src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script src="http://d3js.org/d3.v3.js"></script>
<body>
<div id="dbar">
</div>
<script type="text/javascript">
var margin = {top:10, right: 20, bottom: 30,left: 40},
width = 960 - margin.left - margin.right,
height = 400 - margin.top - margin.bottom;
var svg = d3.select ("#dbar").append("svg").attr("width",
width+margin.left+margin.right).attr("height",height+margin.top+margin.bottom)
.append("g").
attr("transform","translate("+margin.left+","+margin.top+")");
var parseDate = d3.time.format("%m-%Y").parse;
var x = d3.time.scale().range([0, width]);
var y = d3.scale.linear().range([height, 0]);
var xAxis = d3.svg.axis().scale(x).orient("bottom");
var yAxis = d3.svg.axis().scale(y).orient("left");
var area = d3.svg.area().x(function(d) { return x(d.date); })
.y0(height)
.y1(function(d) { return y(d.count); });
d3.json("data/json.json", function(error, data) {
data.StoreVisitGraphCount.list.forEach(function(d) {
d.date = parseDate(d.date);
d.count = +d.count;
});
//console.log(data.StoreVisitGraphCount.list);
x.domain(d3.extent(data.StoreVisitGraphCount.list, function(d) {
return d.date; }));
y.domain([0, d3.max(data.StoreVisitGraphCount.list, function(d) {
return d.count; })]);
console.log(data.StoreVisitGraphCount.list);
svg.append("path")
.datum(data.StoreVisitGraphCount.list)
.attr("class", "area")
.attr("d", area);
svg.append("g")
.attr("class", "x axis")
.attr("transform", "translate(0," + height + ")")
.call(xAxis);
svg.append("g")
.attr("class", "y axis")
.call(yAxis)
.append("text")
.attr("transform", "rotate(-90)")
.attr("y", 6)
.attr("dy", ".71em")
.style("text-anchor", "end")
.text("Price ($)");
});
</script>
</body>
</html>
但是当我复制粘贴此代码以说"temp.jsp"页面时,它不会呈现并且图表不会来。我在tomcat服务器上运行此页面。
需要建议
这不是因为你把它保存为 jsp 或 html 页面。您需要将 charset="UTF-8" 添加到脚本声明中,因为 d3.js 使用 UTF 字符。
例如。
<script src="http://d3js.org/d3.v3.js" charset="UTF-8"></script>
相关文章:
- html报价与php混淆
- 将html ID与angularJS一起使用
- 将 HTML 报告与 Mocha 测试框架结合使用
- HTML 标记与 ng-init 中
- 将自定义 HTML 元素与本机元素区分开来
- 为什么jQuery html在与表单一起使用时像replaceWith一样工作
- 可排序的 Js 在带有选择/选项标签的 chrome 中不起作用,但与 ul/li 标签一起工作
- 在iFrame中加载外部跨域HTML内容与从异步JavaScript加载
- 如何将 HTML 代码与字符串拆分
- Threejs - 方向平行但与线偏移 3 的光线投射器对于 intersectObject 报告 true
- 原始HTML样式与jQuery生成的具有相同结构的HTML不同
- HTML - 属性与属性
- Pregmatch html 属性与 json 内容
- ng-show工作,但与预期相反
- 将 html 数据与内联脚本 html 数据追加并打印
- ajax不适用于IE,但与所有其他浏览器配合良好
- 用户错误消息 |HTML 数据与 JavaScript
- 如何将HTML源代码与jQuery Autocomplete一起使用
- 带有 D3 的面积图无法在 JSP 页面上呈现,但与 HTML 配合使用正常
- dojo contentPane,我张贴html代码与href在我的contentPane.html代码有一个脚本,但不