我正在使用带有焦点图的 nvd3 线的相当简单的示例。 myData
从我的 php 文件返回一个 JSON 对象,其中 x 坐标是 0-23 之间的数字。我想知道如何将 x 轴格式化为小时格式。
d3.json('get_data.php', function (error, myData) {
// Renders a line chart
(function () {
nv.addGraph(function () {
var chart = nv.models.lineWithFocusChart();
chart.xAxis
.tickFormat(d3.format(''));
chart.yAxis
.tickFormat(d3.format(''));
chart.y2Axis
.tickFormat(d3.format(''));
d3.select("#chart svg")
.datum(myData)
.transition().duration(500)
.call(chart); //Define transition and pass the d3.selection to our lineChart.
nv.utils.windowResize(chart.update);
return chart; //Must return the enclosed chart variable so the global rendering queue can store it.
//});
});
})(); });
以下是 myData
中的示例 json 数据。我是否需要以任何方式操纵它?
[{
“键”:“数据”,
“值(value)观”:[
{
“x”:0,
“y”:408175
},
{
“x”:1,
“y”:428739
},
{
“x”:2,
“y”:422141
},
{
“x”:3,
“y”:439864
},
{
“x”:4,
“y”:441409
}
]
}]
如有任何帮助,我们将不胜感激。
最佳答案
以下对我不起作用。 Chart.lines.xScale(d3.time.scale()); Chart.lines2.xScale(d3.time.scale());
在最新的 nvd3 中,您必须使用以下命令来更新 xScale。 Chart.xScale(d3.time.scale()); Chart.focus.xScale(d3.time.scale());
希望它对某人有帮助。
关于javascript - NVD3时间格式,带焦点图的线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35744202/