1

nvd3 (および d3) を使い始めたばかりで、対数スケーリングに苦労しています。

線形スケールでは問題ありませんが、対数スケールではバーが描画されず、コンソール ログが記録されます。

Error: Invalid value for <rect> attribute y="NaN"

問題: http://plnkr.co/edit/Roe6tiYNDeezDEJHNCwj?p=preview

私のコード:

<!DOCTYPE html>
<html>

  <head>
    <link rel="stylesheet" href="https://rawgithub.com/novus/nvd3/master/src/nv.d3.css">
    <script src="https://rawgithub.com/novus/nvd3/master/lib/d3.v3.js"></script>
    <script src="https://rawgithub.com/novus/nvd3/master/nv.d3.js"></script>
  </head>

  <body>

  <script>
    var chart, chart2;
    var data = [{
      "key": "Test",
      "values":
      [
        {"x": "One", "y": 110},
        {"x": "Two", "y": 6},
        {"x": "Three", "y": 12052 },
        {"x": "Four", "y": 4543},
        {"x": "Five","y": 6069},
        {"x": "Six","y": 3899 }
      ]
    }];

    /*Linear scale*/
    nv.addGraph(function () {
        chart = nv.models.multiBarChart()
                    .showControls(false)
                    .showLegend(false);

        chart.multibar
          .yScale(d3.scale.linear())

        d3.select('#chart svg')
          .datum(data)
          .call(chart);

        nv.utils.windowResize(chart.update);

        return chart;
    });

    /*Log scale - not working*/
    nv.addGraph(function () {
        chart2 = nv.models.multiBarChart()
                    .showControls(false)
                    .showLegend(false);

        chart2.multibar
          .yScale(d3.scale.log());

        d3.select('#chart2 svg')
          .datum(data)
          .call(chart2);

        nv.utils.windowResize(chart2.update);

        return chart;
    });

  </script>


  <div id="chart">
    <svg></svg>
  </div>

  <div id="chart2">
    <svg></svg>
  </div>

  </body>

</html>

ドメインと範囲の値を追加しようとしましたが、役に立ちませんでした

      .yDomain([0, 12500])
      .yRange([50, 0]);

何か案は?

4

1 に答える 1

3

This doesn't work for the current version of D3 because log scales aren't defined at 0 and there are a couple of 0s hardcoded in the NVD3 source. You would have to either modify the NVD3 source or create a composite scale that returns a useful value for 0 to make this work.

于 2013-10-14T08:17:50.343 に答える