nvd3为累积折线图添加标题

时间:2013-06-23 10:35:28

标签: nvd3.js

我希望从nvd3.js获得一个标题(在图表行上方)到我的累积折线图。我的图表位于div中,称为elem。当我运行下面的代码时,它会在div下面添加标题,而不是在图表上添加(picture)。之前,我试图将文本附加到svg,但我也没有工作。我想知道问题出在哪里,

nv.addGraph(function () {
var chart = nv.models.cumulativeLineChart()
 .x(function (d) { return d[0] })
 .y(function (d) { return d[1] })
 .color(d3.scale.category10().range());
chart.xAxis
 .tickFormat(function (d) {
  return d3.time.format('%H:%M:%S')(new Date(d))});
chart.yAxis
 .tickFormat(d3.format(',.2f')); 

var svg = d3.select(elem) //elem is the div, we add data here
 .append("svg:svg")
 .datum(data)
 .transition().duration(500)
 .call(chart);

var svg2 = d3.select(elem) //I try to add title as text
 .append("text")
 .attr("x", 200)
 .attr("y", 100)
 .attr("font-family", "sans-serif")
 .attr("font-size", "20px")
 .attr("fill", "black")
 .text("Water Pump Force");

nv.utils.windowResize(chart.update);
return chart;
});

0 个答案:

没有答案
相关问题