javascript - NVD3时间格式,带焦点图的线

标签 javascript d3.js nvd3.js

我正在使用带有焦点图的 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/

相关文章:

javascript - react native : transparent view inside opaque view

javascript - 如何动态更改线插值

JavaScript 闭包无法访问外部变量

javascript - 如何在 NVD3 中全局更改过渡持续时间?

RCharts 散点图增强功能

javascript - Mongoose - 使用 objectid 保存对象

javascript - 如何使用 PHP mySQL 和 jQuery 在另一个页面上显示搜索结果?

javascript - 如何使用 underscore.js 找到数组中对象的索引?

javascript - 使用 d3.js 创建径向图表

javascript - 折线图未达到图表上的正确值且线条平滑