【问题标题】:nvd3.js how to properly redraw chartnvd3.js 如何正确重绘图表
【发布时间】:2013-11-20 17:26:05
【问题描述】:

我有图表类型切换器(pieChart/lineChart)、日期选择器和一个 svg 元素。

更改图表类型或日期会触发 ajax 请求(不同的 url 具有不同的响应数据结构的饼图/线),然后重绘我的图表。像这样:

   buildReport: function (data) {
          var that = this;
          // Format incoming data to chart's format
          this.structure = this.formatters[this.type].call(this, data);
          this.svgElem.empty(); // jQuery empty 

          nv.addGraph(function () {
              var chart = nv.models[that.type](); // that.type - pieChart or lineChart

              chart.options(that.options[that.type] || {});

              d3.select(that.svgElem)
                  .datum(that.structure)
                  .transition()
                  .duration(500)
                  .call(chart);

              return chart;
          });
      }

此函数在图表类型或日期更改时调用(ajax 请求可能会在某些情况下缓存)。使用 svgElem.empty() 是否正确?或者还有另一种方法来破坏图表并绘制另一个?

还有一些其他问题:

1) 如何在图表底部中心绘制图例?有什么选择吗?

2) 默认情况下如何绘制“展开”状态的堆积面积图?我需要隐藏控件(showContols: false 选项)并绘制展开的stackedArea 图表

谢谢

【问题讨论】:

  • 我猜.empty() 会做得和其他任何事情一样好。

标签: d3.js nvd3.js


【解决方案1】:

要使用非堆叠样式绘制图表,您可以使用

chart.style("展开"); // 用于展开 图表样式(“流”); // 用于流

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-07-15
    • 1970-01-01
    • 1970-01-01
    • 2012-11-09
    • 1970-01-01
    • 2013-09-30
    • 2017-03-22
    • 1970-01-01
    相关资源
    最近更新 更多