2015-10-16 37 views
0

我正在使用酒窩模板,但找不到標題的命令。所以我只是查找了一個d3命令並將其添加到我的代碼中。不幸的是,標題沒有顯示。有人可以發現我的錯誤嗎?d3.js,酒窩,在圖上獲得標題

<html> 
<head> 
    <script src="http://d3js.org/d3.v3.min.js"></script> 
    <script src="http://dimplejs.org/dist/dimple.v2.1.6.min.js"></script> 
</head> 
<body> 
<div id="chartContainer"> 
    <script type="text/javascript"> 
    var svg = dimple.newSvg("#chartContainer", 590, 400); 
     d3.tsv("bbd3.tsv", function (data) { 
     var myChart = new dimple.chart(svg, data); 
     myChart.setBounds(75, 30, 490, 330) 
     var myAxisx = myChart.addMeasureAxis("x", "HR"); 

     myAxisx.overrideMin = 35; 
     myAxisx.overrideMax = 75; 
     myAxisx.title = "averaged Number of Home Runs"; 
     var myAxisy = myChart.addMeasureAxis("y", "avg"); 
     myAxisy.overrideMin = 0.23; 
     myAxisy.overrideMax = 0.255; 
     myAxisy.title = "Batting average in % averaged over all players";   var mySeries = myChart.addSeries(["handedness"], dimple.plot.bubble); 
     mySeries.aggregate = dimple.aggregateMethod.avg; 
     myChart.addLegend(180, 10, 360, 20, "left"); 
     myChart.draw(); 
     svg.append("text") 
     .attr("x", (width/2))    
     .attr("y", 0 - (margin.top/2)) 
     .attr("text-anchor", "middle") 
     .style("font-size", "16px") 
     .style("text-decoration", "underline") 
     .text("Value vs Date Graph"); 
     }); 
    </script> 
</div> 
</body> 
</html> 

回答

1

我不能看到的marginwidth變量使用放置標題任何聲明。由於無論如何您的圖表定義爲固定尺寸,您可以將其替換爲:

svg.append("text") 
    .attr("x", 295)    
    .attr("y", 30) 
    .attr("text-anchor", "middle") 
    .style("font-size", "16px") 
    .style("text-decoration", "underline") 
    .text("Value vs Date Graph");