Javascript 带有d3的面积图在jsp页面上不呈现,但在html中可以正常工作

Javascript 带有d3的面积图在jsp页面上不呈现,但在html中可以正常工作,javascript,jsp,d3.js,Javascript,Jsp,D3.js,我成功地在html页面中呈现了d3js面积图。下面是在chrome或mozilla中成功呈现的代码。文件名是say 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"> &l

我成功地在html页面中呈现了d3js面积图。下面是在chrome或mozilla中成功呈现的代码。文件名是say 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>

js图形和图表库
var margin={顶部:10,右侧:20,底部:30,左侧:40},
宽度=960-margin.left-margin.right,
高度=400-margin.top-margin.bottom;
var svg=d3.select(#dbar”).append(“svg”).attr(“width”,
宽度+边距。左侧+边距。右侧)。属性(“高度”,高度+边距。顶部+边距。底部)
.附加(“g”)。
属性(“变换”、“平移”(+margin.left+)、“+margin.top+”);
var parseDate=d3.time.format(“%m-%Y”).parse;
var x=d3.time.scale().range([0,width]);
变量y=d3.scale.linear().range([height,0]);
var xAxis=d3.svg.axis().scale(x.orient(“底部”);
var yAxis=d3.svg.axis().scale(y).orient(“左”);
var area=d3.svg.area().x(函数(d){return x(d.date);})
.y0(高度)
.y1(函数(d){返回y(d.count);});
d3.json(“data/json.json”,函数(错误,数据){
data.StoreVisitGraphCount.list.forEach(函数(d){
d、 日期=解析日期(d.date);
d、 计数=+d.count;
});
//log(data.StoreVisitGraphCount.list);
x、 域(d3.extent(data.StoreVisitGraphCount.list,函数(d){
返回d.date;});
y、 域([0,d3.max(data.StoreVisitGraphCount.list,函数(d){
返回d.count;})];
log(data.StoreVisitGraphCount.list);
追加(“路径”)
.datum(data.StoreVisitGraphCount.list)
.attr(“类别”、“区域”)
.attr(“d”,区域);
svg.append(“g”)
.attr(“类”、“x轴”)
.attr(“变换”、“平移(0)”、“高度+”)
.呼叫(xAxis);
svg.append(“g”)
.attr(“类”、“y轴”)
.呼叫(yAxis)
.append(“文本”)
.attr(“变换”、“旋转(-90)”)
.attr(“y”,6)
.attr(“dy”,“.71em”)
.style(“文本锚定”、“结束”)
.text(“价格($)”);
});
但当我复制粘贴此代码以显示“temp.jsp”页面时,它不会呈现,也不会显示图表


需要建议不是因为您将其保存为jsp或html页面。您需要将charset=“UTF-8”添加到脚本声明中,因为d3.js使用UTF字符

例如


这个答案是正确的。但是,如果你需要快速破解,你可以使用d3.v3.min.js——一个最小化的版本——它似乎可以删除像“pi”这样的字符。
<script src="http://d3js.org/d3.v3.js" charset="UTF-8"></script>